高手帮忙:关于dll调用次数的问题(100分)

  • 主题发起人 hitppcat
  • 开始时间
H

hitppcat

Unregistered / Unconfirmed
GUEST, unregistred user!
以下是dll的begin ...end之间的代码<br>begin<br>&nbsp; if not assigned(DllProc) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; DllProc:=@DllMain;<br>&nbsp; &nbsp; &nbsp; DLLMain(DLL_PROCESS_ATTACH);<br>&nbsp; &nbsp; end;<br>end.<br>该dll在打开ie时被调用,可是我用dbgview观察,该部分一共被调用了三次。因为我自己定义的dllmain函数中有分配内存的操作,这样一来,会有泄漏。不知道怎么解决,高手帮忙啊!
 
DLLMain<br>里面<br>没<br>处理<br>DLL_PROCESS_DETACH<br>吗?
 
处理了<br>procedure DllMain(dwReason: DWORD);stdcall;<br>begin<br>&nbsp; &nbsp;OutputDebugString('in DllMain');<br>&nbsp; case dwReason of<br>&nbsp; &nbsp; Dll_Process_Attach:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; OutputDebugString('process attach');<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Dll_Process_Detach:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;OutputDebugString('process detach');<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Dll_Thread_Attach:;<br>&nbsp; &nbsp; Dll_Thread_Detach:;<br>&nbsp; end;<br>end;
 
L_PROCESS_DETACH<br>这些东西对delphi来说都是没有用的,定义了只是形式上跟c的一样!<br>实际上根本不是那么回事!对dllmain的调用已经被delphi接管了<br>begin end 就算是入口了,只要dll被调入,begin end 之间的代码就会运行<br>把dllmain 作为输出函数!然后再调用吧!
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
405
import
I
顶部