Jump to content
Anna Blanca

Why i can't hide Form1 in DLL?

Recommended Posts

Hello. I'm trying add Form in my DLL, and i hide it with next constraction:

procedure Start;

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.ShowMainForm := False;
Application.Run;
end;

exports
Start;

 Earlier, in previous versions Delphi, my DLL worked normal, but exactly in 12-th Delphi version, all broked. When i launch my library through app, it's working normal, but when i launch through rundll32.exe - no one component on Form1 not working. What Embarcadero broked in this time and how fix it? 

P.S. I attach my project to this topic, you can open it and look all youselfe. 

Fucking DLL.zip

Share this post


Link to post

Your Start() function is not compatible with rundll32. It's a wonder your code ever worked at all. You are invoking undefined behavior.

 

Read: INFO: Windows Rundll and Rundll32 Interface

 

Your Start() function MUST have the following signature in order for rundll32 to call it correctly:

procedure Start(hwnd: HWND; hinst: HINSTANCE; lpszCmdLine: PAnsiChar; nCmdShow: Integer); stdcall;
Edited by Remy Lebeau

Share this post


Link to post
19 hours ago, Remy Lebeau said:

Your Start() function is not compatible with rundll32. It's a wonder your code ever worked at all. You are invoking undefined behavior.

Hm-m-m, earlier, in Delphi 11, all worked normal and my library launched by rundll32.exe normal.

So, and what is HINSTANCE? When i use it in my code, IDE underlining it by red.... No one module in uses not help.

Edited by Anna Blanca

Share this post


Link to post
6 hours ago, Anna Blanca said:

So, and what is HINSTANCE? When i use it in my code, IDE underlining it by red.... No one module in uses not help.

HInstance is the instance (var) of the module, derived from System.pas (type HINST). Should be always defined and available  'cause it is used at loading time (look SysInit.pas)

 

FYI, MainInstance in the HInstance of the MAIN APPLICATION (not the module like dll, library, ...).

Share this post


Link to post
6 hours ago, DelphiUdIT said:

FYI, MainInstance in the HInstance of the MAIN APPLICATION (not the module like dll, library, ...).

In this case, my DLL is main application. So, what library i must add in uses? 

 

And i want message you, if my DLL launch normal, when i  not hide Form1, when i not use  Application.ShowMainForm := False; 

Share this post


Link to post
12 minutes ago, Anna Blanca said:

my DLL is main application

A DLL is a library and it can run only in the processes of a main application (rundll32 or other app).

Share this post


Link to post
17 hours ago, Anna Blanca said:

Hm-m-m, earlier, in Delphi 11, all worked normal and my library launched by rundll32.exe normal.

"Seeming to work fine" is a possible result of Undefined Behavior. That doesn't mean the code was right, though.  rundll32 requires a very specific signature for the entry point function that it calls, and your code was not satisfying that requirement.  Fix that first, and if your UI problem still occurs then we can focus on that next.

17 hours ago, Anna Blanca said:

So, and what is HINSTANCE? When i use it in my code, IDE underlining it by red.... No one module in uses not help.

Sorry, I keep forgetting that Delphi doesn't define HINSTANCE as a type. Use System.HINST or Winapi.Windows.HINST or THandle instead.

Edited by Remy Lebeau

Share this post


Link to post
26 minutes ago, Remy Lebeau said:

Sorry, I keep forgetting that Delphi doesn't define HINSTANCE. Use System.HINST or Winapi.Windows.HINST or THandle instead.

I wrote that, HINSTANCE is a global var. HINST is the type.

Edited by DelphiUdIT

Share this post


Link to post
16 hours ago, Anna Blanca said:

So, and what is HINSTANCE? When i use it in my code, IDE underlining it by red.... No one module in uses not help.

Edited 15 hours ago by Anna Blanca

image.thumb.png.36381ac08bdabf04badcb27b8c1be187.png

image.thumb.png.ad1b7399bf9e49539f302a62ec9bb50b.png

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×