⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadlibraryu.pas

📁 DelphiWin32核心API参考光盘内容.是学习书籍中的源码,便于学习.
💻 PAS
字号:
unit LoadLibraryU;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
   hMod: THandle;                          // holds the DLL handle
   ModuleFileName: array[0..255] of char;  // holds the DLL name

   {this is the prototype for the function imported from the DLL}
   MyFunction: function(ExampleName, Comments: ShortString): Boolean;
begin
   {explicitly load the DLL}
   hMod := LoadLibrary('EXAMPLE.DLL');
   if (hMod=0) then Exit;

   {retrieve the address of the desired function}
   @MyFunction := GetProcAddress(hMod, 'ShowAboutBox' );

   {if the address was returned...}
   if (@MyFunction<>nil) then
   begin
     {call the function to display an about box}
     MyFunction('LoadLibrary Example','This example demonstrates loading '+
                'a dynamic link library via the LoadLibrary function.');

     {retrieve the module filename}
     GetModuleFileName(GetModuleHandle('EXAMPLE.DLL'), @ModuleFileName[0],
                       SizeOf(ModuleFileName));

     {display the DLLs name}
     ShowMessage('The loaded DLL was: '+ModuleFileName);
   end
   else
     {indicate an error}
     ShowMessage('GetProcAddress Failed');

   {free the DLL}
   FreeLibrary(hMod);
end;


end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -