Solved

Help..Mapping Application.Handle!!

Posted on 1998-12-10
7
193 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

16 Experts available now in Live!

Get 1:1 Help Now