首页 > 其他 > 详细

DLL的静态调用和动态调用

时间:2014-03-04 19:43:06      阅读:426      评论:0      收藏:0      [点我收藏+]

// ------------------------------------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;

DLL的静态调用和动态调用,布布扣,bubuko.com

DLL的静态调用和动态调用

原文:http://www.cnblogs.com/findumars/p/3579636.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!