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;

  • 相关阅读:
    分布式计算原理
    消息的有序性
    CAP再解释
    数据建模
    领导层级的跨越
    如何上云|什么是多机房多活架构
    mysql导出导入数据
    Qt 串口 封装好的类 直接使用
    C++ 在类的定义时初始化非静态变量
    Qt error C3646: 未知重写说明符
  • 原文地址:https://www.cnblogs.com/findumars/p/3579636.html
Copyright © 2011-2022 走看看