【发布时间】:2011-09-06 19:51:17
【问题描述】:
我的 DLL 如何检测它是隐式加载还是显式加载?
MyTestDll.dll 示例
library MyTestDll;
uses SimpleShareMem, Windows, Dialogs;
procedure DetectMethodDllLoad: bool;
begin
// ?????
// need to detect loading method - implicit or explicit
end;
procedure MyTest; stdcall;
begin
if DetectMethodDllLoad then
ShowMessage('Working Program1 (implicit dll load)')
else
ShowMessage('Working Program2 (explicit dll load)');
end;
exports MyTest;
begin
end.
Program1.exe(隐式加载 dll)
procedure MyTest; stdcall; external 'MyTestDll.dll' Name 'MyTest';
procedure TForm1.Button1Click(Sender: TObject);
begin
MyTest;
end;
Program2.exe(显式加载 dll)
type
TMyTest = procedure; stdcall;
procedure TForm1.Button1Click(Sender: TObject);
var
MyTest: TMyTest;
H: HModule;
begin
H := LoadLibrary('MyTestDll.dll');
if H = 0 then
exit;
@MyTest := GetProcAddress(H, 'MyTest');
if Assigned(MyTest) then
MyTest;
FreeLibrary(H);
end;
如何实现DetectMethodDllLoad?
【问题讨论】:
-
你的问题不清楚。你能改写一下吗?
-
DLL 使用动态链接而不是静态链接。也许您希望绘制的区别在于隐式链接和显式链接。没关系,这里没有问题,我投票结束。
-
好吧,现在我将添加一个示例
-
在您更新问题之前获得了接近票数。我现在明白你了。
-
@David - 问题不在于链接,而在于加载。我认为 dll 术语的动态/静态加载没有任何问题。