use Dll

uses: WinProcs, WinTypes, SysUtils; 
var 
  ALibrary : THandle; //Windows uses handles for lots of things such as an open window or DLL 
  AFilename: string; ABuffer: array[0..255] of Char; //this is to convert Pascal string to PChar 
  aDLLFunctionName: function(parameter types):ReturnDataType; //this is a procedural-type variable! 
//initialise variables: 
  AFilename := 'mylibrary.dll'; StrPCopy(ABuffer,AFilename); 
  @aDLLFunctionName := nil; 
try 
  ALibrary := LoadLibrary(ABuffer); 
  if ALibrary > HINSTANCE_ERROR then 
  begin {its safe to use library} 
  //retrieve subroutine addresses: 
    @aDLLFunctionName := GetProcAddress(ALibrary, 'DLLFunctionName'); 
  //use function: 
    if assigned(aDLLFunctionName) then 
      x := aDLLFunctionName(parameter values); 
  end 
  else {there was a problem} 
  finally FreeLibrary(ALibrary);
end; 

 

posted @ 2011-12-30 16:15  司玲朦胧  阅读(111)  评论(0)    收藏  举报