Solved

Easy question about dll's

Posted on 2002-03-08
4
230 Views
Last Modified: 2010-04-05
I need something like "ExitProc" but for dll's, because
"ExitProc should only be used when generating .EXE files."(Delphi help)
There is code that I was created for .exe files.
....
var SaveProc:Pointer;
....
SaveProc := ExitProc;
ExitProc := @MyExitProc

procedure MyExitProc;
begin
ExitProc := SaveProc
....
end;
0
Comment
Question by:trunin
4 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 6850270
Why not use the finalization part of a unit? Write the DLL code in a seperate unit, not the .dpr file, and add an initialization and a finalization part to it.
0
 
LVL 8

Accepted Solution

by:
TOndrej earned 50 total points
ID: 6850348
The help says "Inside a DLL, you can use the DLLProc variable instead."
But I think I've heard that there's a bug in the RTL which causes that your libraryproc is never called with DLL_PROCESS_DETACH (or was it DLL_THREAD_DETACH?).
You'd better test it for yourself.
Also try finalization sections, as Workshop_Alex suggested (Hi, Alex! :-)
0
 
LVL 1

Author Comment

by:trunin
ID: 6850403
Hi all.
To TOndrej:
I was tested it but when I unload dll then it allways call DLLProc with DLL_PROCESS_ATTACH parameter. :(

TO Workshop Alex:
I will try your idea later.
0
 
LVL 3

Expert Comment

by:cubud
ID: 6850704
procedure LibEntry(Reason: Integer);
begin
  if Reason = DLL_THREAD_DETACH then
  begin
    Do your code here
  end;
end;

begin
  DllProc := @LibEntry;
end.


http://www.howtodothings.com

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

19 Experts available now in Live!

Get 1:1 Help Now