• delphi dll 静态调用和动态调用方法总结


    dll 调用方法有 静态调用和动态调用两种方法

    用到的dll为上篇文章所编写的dll.

    总结如下:

    Unit Unit1;

    Interface

    Uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;

    Type
      TForm1 = Class(TForm)
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        Procedure Button1Click(Sender: TObject);
        Procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      End;

    Var
      Form1: TForm1;
     
    Implementation
    Function  Min(X, Y: Integer): Integer; external 'Project1.dll';
    Function Max(X, Y: Integer): Integer; external 'Project1.dll';
    procedure SynAPP(App:THandle);stdcall;external 'Project1.dll'; //这里的
    procedure ShowForm;stdcall;external 'Project1.dll';
    procedure showmyform;stdcall;external 'Project1.dll';
    {$R *.dfm}

    Procedure TForm1.Button1Click(Sender: TObject);
    Begin
      showmessage(inttostr(Min(1, 100)));//静态方法
      showmessage(inttostr(Max(1, 100)));//静态方法
    End;

    //动态方法

    Procedure TForm1.Button2Click(Sender: TObject);
    Type
      Tmax = Function(X, Y: Integer): Integer;
      THandle = Integer;
    Var
      mymax: Tmax;
      Handle: THandle;

    Begin
      Handle := LoadLibrary('Project1.dll');

      @mymax := GetProcAddress(Handle, 'Max');
      showmessage(inttostr(mymax(1, 100)));

      FreeLibrary(Handle);
    End;


    procedure TForm1.Button3Click(Sender: TObject);
    begin
      // SynAPP(Application.Handle);
      showmyform ;//静态方法
      //ShowForm ;
    end;

    End.

  • 相关阅读:
    常用PHP array数组函数
    每天学习30分钟新知识之html教程1
    laravel学习之路2: jwt集成
    JWT简介json web token bear token
    MDwiki 调研
    laravel学习之路1:认证相关
    OAuth 2.0介绍
    第一行代码 6.4 数据存储全方案-详解持久化数据- 数据库
    github(1)安装及使用图文详解
    Android集成讯飞语音、百度语音、阿里语音识别
  • 原文地址:https://www.cnblogs.com/fengju/p/6173820.html
Copyright © 2020-2023  润新知