DelphiFAQ Home Search:

Tracking DLL loading, attaching, detaching and unloading

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

The code snippet shows how your DLL can track its usage.

Library testdll;

uses
  Windows,   // DLL_PROCESS_nnn defined in here
  SysUtils, Classes;

procedure MyDLLProc(Reason: Integer);
begin
 case Reason of
   DLL_PROCESS_ATTACH:   // called when the DLL is loaded
   begin
   end;

   DLL_PROCESS_DETACH:   // called when the DLL is freed, if you want
                         // multithreaded, look at DLL_THREAD_DETACH
   begin
   end;
 end;
end;

begin
  DLLProc := @MyDLLProc;  // this sets the DLL entry point to the MyDLLProc.
                          // when ever the DLL is loaded or unloaded,
                          // this proc is called with:
                          //     DLL_PROCESS_ATTACH
                          //     DLL_PROCESS_DETACH
                          //     DLL_THREAD_ATTACH
                          //     DLL_THREAD_DETACH

  MyDLLProc(DLL_PROCESS_ATTACH); // because we interupted the default
                          // dllproc, we must recall our proc
                          // with the DLL_PROCESS_ATTACH reason.
end.
You don't like the formatting? Check out SourceCoder then!

Comments:

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.