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;

  • 相关阅读:
    搭建zabbix监控
    liunx 下ctrl+D问题解决方案
    linux配置双线策略
    Discuz! X2.5读写分离
    慢谈MYSQL常用SQL语句
    CentOS 6.5系统安装配置LAMP(Apache+PHP5+MySQL)服务器环境
    自动抓包shell脚本
    zabbix实施部署原理架构
    ftp搭建教程
    DNS搭建教程
  • 原文地址:https://www.cnblogs.com/findumars/p/3579636.html
Copyright © 2011-2022 走看看