Salut Michael Josephson !
Dans un message de Michael Josephson dat‚ du 29 Jun 97 23:57:20 il ‚tait
t:
MJ> In a Delphi program is possible to pick the DLL to call a
MJ> function from at runtime?
Sure it is ! It is a standard Windows feature.
Just call the Windows API LoadLibrary() to load the DLL in memory, given
the DLL's name and then call GetProcAddress() to retreive the function
address you wants to call inside the DLL, given the function name.
After using the Dll, do'nt forget to free it, releasing the memory.
Here is a sample code (Delphi 2):
// Define the function signature
TMyDllFunction = function(Arg1 : Integer) : Integer; stdcall;
var
LibHandle: THandle; // Dll handle once loaded in memory
MyDllFunction: TMyDllFunction; // Pointer to the Dll's function
x: Integer; // Some working variable
begin
// Load the Dll in memory
LibHandle := LoadLibrary('MyDll.dll');
if LibHandle < 32 then
raise Exception.Create('Unable to load MyDll.dll');
// Get the function address
@MyDllFunction := GetProcAddress(LibHandle, 'MyFunctionName');
if @MyDllFunction = nil then
raise Exception.Create('Failed to lookup MyFunctionName');
x := MyDllFunction(1234);
// More processing
// Free the Dll
FreeLibrary(LibHandle);
end;
Amiti‚s,
{-Francois Piette-}
francois.piette@ping.be
http://www.rtfm.be/fpiette
--- SvFido 1.32
---------------
* Origin: OverByte BBS (Embourg-Belgium) 32-4-3651395 VFC/V34+ (2:293/2202)
|