Solved

Help..Mapping Application.Handle!!

Posted on 1998-12-10
7
192 Views
Last Modified: 2010-04-04
My question this....

 In delphi 3 I am trying to assign the Main Executables Application.Handle(Mainform.Handle) to a Dll. How do you do this. I know how to access a procedure in a Dll and use it but how do you assign and EXE's Application.Handle to a Dll. This is pretty important for what I require to do. Any ideas??

The Delphi help says "When writing a DLL that uses VCL forms, assign the window handle of the host EXE’s main window to the DLL’s Application.Handle property. This makes the DLL’s form part of the host application. Never assign to Application.Handle in an EXE."

Easier said then done I say....
Any help would be much appreciated.

Thanks WESTY :|
0
Comment
Question by:westy100697
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350511
Do this in the DLL

Procedure SetApplication(TheApplication : TApplication); Stdcall;

begin
  Application := TheApplication;
end;

Then call it from your application like this (after declaring it in the DLL interface as the usual manner...):

SetApplication(Application); // And there you have it.

Cheers,

Raymond.

0
 

Author Comment

by:westy100697
ID: 1350512
rwilson,
        This seems to work well with a little fiddling. The only problem now is that it doesn't want to release/free the application when i exit. Get a runtime error?? It is very strange
but I think it stems from the Dll. Not unloading properly. I thank you very much and am awarding you the points but if know of a solution for that runtime error I will increase points to 80. By the way, just thought I should mention this it is an MDI application that loads a Dll full of MDI Child forms. This is the reason I needed some way of loading the Application object into the Dll. Anyway if you can help let me know otherwise I will just give ya the 50 eh!

Regards
WESTY :)
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350513
Westy,

The error is becasue the DLL will try to free is application object and so will the application - but now they are the same object.

Change the code so it is like this:

var
  SaveApplication : TApplication;

Procedure SetApplication(TheApplication : TApplication); Stdcall;

    begin
      SaveApplication := Application;
      Application := TheApplication;
    end;

Remember to restore the application again before exiting.

Williams2 et al have worked up a complete solution to the MDI forms in DLL problem - it may be found in http://www.experts-exchange.com/topics/comp/lang/delphi/Q.10104327 which solves other problems with MDI forms in DLLs.

I hope this helps...

Cheers,

Raymond
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:westy100697
ID: 1350514
rwilson,
           I appreciate the swift response on the problem and will award you 80 points okay. I will reject this answer for 50 points bump it up to 80 and you lock it again and I will award the points. Thanks again.

WESTY :)
0
 

Author Comment

by:westy100697
ID: 1350515
I have upped the points rwilson. Lock it again.

WESTy
0
 

Author Comment

by:westy100697
ID: 1350516
I have upped the points rwilson. Lock it again.

WESTy
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 80 total points
ID: 1350517
Thanks Westy!

Cheers,

Raymond.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now