TIP: Click on subject to list as thread! ANSI
echo: delphi
to: MICHAEL JOSEPHSON
from: FRANCOIS PIETTE
date: 1997-07-06 10:11:00
subject: Calling a function in a user defined DLL10:11:3107/06/97

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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.