Как моя 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
?