Can Delphi only use a .dll if required?

后端 未结 2 704
南笙
南笙 2020-12-19 09:46

I have added these two methods to the 1st unit of my Delphi 5 application.

function Inp(PortAddress: Integer): Integer; stdcall; external \'inpout32.dll\' na         


        
2条回答
  •  情深已故
    2020-12-19 10:22

    In Delphi versions prior to 2010, you have to use classic dynamic loading. Consider this typical (and simple) example calling the Beep function from Kernel32.dll (which you should not hardcode the path to in real code, of course!):

    type
      TBeepFunc = function(dwFreq: DWORD; dwDuration: DWORD): BOOL; stdcall;
    
    procedure TForm4.FormClick(Sender: TObject);
    var
      lib: HMODULE;
      prc: TBeepFunc;
    begin
    
      lib := LoadLibrary('C:\WINDOWS\System32\Kernel32.dll');
      if lib = 0 then RaiseLastOSError;
      try
        @prc := GetProcAddress(lib, 'Beep');
        if Assigned(prc) then
          prc(400, 2000)
        else
          ShowMessage('WTF? No Beep in Kernel32.dll?!');
      finally
        FreeLibrary(lib);
      end;
    end;
    

提交回复
热议问题