zoukankan      html  css  js  c++  java
  • 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;
    

      

  • 相关阅读:
    VMware rhel 7 网卡绑定
    VMware 克隆虚拟机后网卡无法启动
    rhel7 批量新建和删除用户
    2019.3.27 Linux 学习
    20180313前端笔试
    javascript中的一些问题
    flex布局学习笔记(阮一峰flex布局教程)
    个推面试总结
    笔试题目整理
    @JsonFormat与@DateTimeFormat注解的使用
  • 原文地址:https://www.cnblogs.com/hejoy91/p/3527144.html
Copyright © 2011-2022 走看看