zoukankan      html  css  js  c++  java
  • DLL的静态调用和动态调用

    // ------------------------------------DLL源代码 circle.dproj -------------------------------------
    library circle;

    uses
    SysUtils,
    Classes,
    Math;

    {$R *.res}

    function CircleArea(const radius : double) : double; stdcall;
    begin
    result := radius * radius * PI;
    end;

    exports CircleArea;

    begin

    end.

    // ------------------------------------调用DLL--------------------------------------------------

    var
    Form1: TForm1;

    function CircleArea(const radius : double) : double; external 'circle.dll'; // 静态调用

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    ShowMessage('static: ' + FormatFloat(',.00',CircleArea(StrToFloat(Edit1.Text))));
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    type
    TCircleAreaFunc = function (const radius: double) : double; stdcall;
    var
    dllHandle : cardinal;
    circleAreaFunc : TCircleAreaFunc;
    begin
    dllHandle := LoadLibrary('circle.dll'); // 动态调用
    if dllHandle <> 0 then
    begin
    @circleAreaFunc := GetProcAddress(dllHandle, 'CircleArea');
    if Assigned (circleAreaFunc) then
    ShowMessage('dynamic: ' + FormatFloat(',.00',circleAreaFunc(StrToFloat(Edit1.Text))))
    else
    ShowMessage('"CircleArea" function not found');
    FreeLibrary(dllHandle); // 释放动态库
    end
    else
    begin
    ShowMessage('circle.dll not found / not loaded');
    end;
    end;

  • 相关阅读:
    re模块
    Docker的使用
    flask中请求勾子
    flask中的蓝图实现模块化的应用
    HTTP中常见的各种状态码详解及解决方案
    git快速入门
    2st week blog 1
    web个人介绍
    CentOS7下shell脚本实现限定范围类的随机数
    CentOS7下shell脚本大小比较
  • 原文地址:https://www.cnblogs.com/findumars/p/3579636.html
Copyright © 2011-2022 走看看