library DLLEntryLib;
uses
SysUtils,
Windows,
Dialogs,
Classes;procedure DLLEntryPoint(dwReason: DWord);
begin
case dwReason of
DLL_PROCESS_ATTACH: ShowMessage('Attaching to process');
DLL_PROCESS_DETACH: ShowMessage('Detaching from process');
DLL_THREAD_ATTACH: MessageBeep(0);
DLL_THREAD_DETACH: MessageBeep(0);
end;
end;begin
DllProc := @DLLEntryPoint;
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.在调用此dll时候对话框'Attaching to process'可以弹出,因为在dll初始化时候有DLLEntryPoint(DLL_PROCESS_ATTACH)调用了procedure DLLEntryPoint(dwReason: DWord),可是'Detaching from process'对话框不能弹出,也就是DLL_PROCESS_DETACH在此没有作用,那么我想在dll freelibary是做一些善后工作,怎么才能执行DLL_PROCESS_DETACH中的代码?
uses
SysUtils,
Windows,
Dialogs,
Classes;procedure DLLEntryPoint(dwReason: DWord);
begin
case dwReason of
DLL_PROCESS_ATTACH: ShowMessage('Attaching to process');
DLL_PROCESS_DETACH: ShowMessage('Detaching from process');
DLL_THREAD_ATTACH: MessageBeep(0);
DLL_THREAD_DETACH: MessageBeep(0);
end;
end;begin
DllProc := @DLLEntryPoint;
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.在调用此dll时候对话框'Attaching to process'可以弹出,因为在dll初始化时候有DLLEntryPoint(DLL_PROCESS_ATTACH)调用了procedure DLLEntryPoint(dwReason: DWord),可是'Detaching from process'对话框不能弹出,也就是DLL_PROCESS_DETACH在此没有作用,那么我想在dll freelibary是做一些善后工作,怎么才能执行DLL_PROCESS_DETACH中的代码?
看到如下内容
When a DLL detaches from a process as a result of process termination or as a result of a call to FreeLibrary, the operating system does not call the DLL's entry-point function with the DLL_THREAD_DETACH value for the individual threads of the process. The DLL is only given DLL_PROCESS_DETACH notification. DLLs can take this opportunity to clean up all resources for all threads attached and known to the DLL.
但个别的process or thread为什么不调用这个入口函数就没有解释了
再关注一下
看看有没有人知道
查MSDN太慢了
DllProc管理应用程序发给dll的消息,相当于*.exe的WinProc函数管理应用程序的消息。调用dll就可以出现'Detaching from process'。(你没调用吧,所以没出现)
各位大侠调试以上代码就知道了
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TMainForm = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
MainForm: TMainForm;implementation{$R *.dfm}procedure TMainForm.Button1Click(Sender: TObject);
var
h: THandle;
begin
h := LoadLibrary('DllEntryLib.dll');
if h <> 0 then
begin
ShowMessage('Load Succeed!');
FreeLibrary(h);
end;
end;end.
高手帮帮忙啊!