I'm creating a new component in Delphi, which instantiates a DLL
Unit UMyComponent
interface
type
TMyComponent = class(TComponent)
...
procedure MyDllCall;
end;
procedure Register;
implementation
function MyDll: Longint; stdcall; external 'MyDllName.dll' name 'MyFunction'
procedure TMyComponent.MyDllCall;
var
res: LongInt;
begin
res:= MyDll;
end;
...
procedure Register;
begin
RegisterComponents('My Tab', [TMyComponent]);
end;
end.
I have 2 questions:
Note that I put DLL declaration in the implementation in order not to expose the function call to callers.
Thanks for answering.
Your current code uses what is known as load-time linking . The dependency must be resolved when the module is loaded, otherwise it will fail to load. You need to use the alternative method, run-time linking .
In Delphi there are two ways to do that:
LoadLibrary
, GetProcAddress
and FreeLibrary
. delayed
keyword. Both approaches are covered in more detail in the documentation:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.