• Delphi中的dll操作


    利用delphi dll wizard进行dll的编写。
    
    创建:保存时改dll名称
    
    library test2;
    
    uses
      SysUtils,
      Classes,
      forms,
      dialogs;
    
    {$R *.res}
    function test():string;
    begin
      showmessage('a');
    end;
    exports
      test;//必须的
    begin
    end.
    
    调用:在调用单元的implement下面 function test():string;external 'xxxxxxx	est2.dll';
    
    button中调用test方法即可。
    
    动态调用dll:
    
    type
      //晚绑定,也就是动态调用外部函数主要用以下三个命令:
      //LoadLibrary:获取 DLL
      //GetProcAddress:获取函数
      //FreeLibrary:释放
    
      //定义一个过程类型,参数要和需要的函数一致
      TMB = function(hWnd: HWND; lpText, lpCaption: PChar; uType: UINT): Integer; stdcall;
    
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        MB: TMB;  {声明函数 MB}
        inst: LongWord;  {声明一个变量来记录要使用的 DLL 句柄}
      public
        { Public declarations }
      end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      inst := LoadLibrary('user32.dll');
      if inst <> 0 then
        MB := GetProcAddress(inst, 'MessageBoxW');
    
    end;
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      FreeLibrary(inst);  {记得释放}
    end;
    

      

  • 相关阅读:
    LVM
    作业
    软件工程随笔
    woj1005-holding animals-01pack woj1006-Language of animals-BFS
    woj1002-Genesis woj1003-birthofnoah woj1004-noah's ark
    C++ new delete malloc free
    centos7+腾讯云服务器搭建wordpress
    C++ inline与operator
    next v5升级到next v7需要注意的地方
    python = 赋值顺序 && C++ side effect
  • 原文地址:https://www.cnblogs.com/hejoy91/p/3527144.html
Copyright © 2020-2023  润新知