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;
    

      

  • 相关阅读:
    Flask 服务器设置host=0.0.0.0之后外部仍然无法访问
    HTB::Sauna
    VulnHub::DC-4
    【CTFHub 技能树】RCE
    【CTFHub 技能树】反射型XSS
    VulnHub::DC-3
    HashMap中add()方法的源码学习
    equals和HashCode深入理解(转)
    AQS原理分析
    初步认识线程安全性
  • 原文地址:https://www.cnblogs.com/hejoy91/p/3527144.html
Copyright © 2011-2022 走看看