DLL的静态调用和动态调用
2014-03-04 07:07
344 查看
// ------------------------------------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;
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和动态dll(创建、区别、调用方式)
- 【VB技巧】VB静态调用与动态调用dll详解
- DLL专题之动态连接库的静态调用(1)
- C# 中静态调用C++dll 和C# 中动态调用C++dll
- vb.net静态动态调用c++dll的方法
- Delphi 动态与静态调用DLL
- DLL DEF文件编写方法 VC++ 调用、调试DLL的方法 显式(静态)调用、隐式(动态)调用
- Delphi 动态与静态调用DLL
- C++调用DLL有两种方法——静态调用和动态调用
- DLL专题之动态连接库的静态调用(2)
- DLL静态(显示)调用,动态(隐式)调用
- 在C++中调用DLL中的函数——静态调用和动态调用
- .h .lib .dll文件,静态链接库与动态链接库,静态调用与动态调用
- C++ 编写DLL 动态及静态调用DLL方法
- dll 调用,动态,静态
- 【VB技巧】VB静态调用与动态调用dll详解
- Delphi 类库(DLL)动态调用与静态调用示例讲解
- VC中使用动态链接库DLL:静态调用和动态调用
- C# 中静态调用C++dll 和C# 中动态调用C++dll
- dll的静态调用和动态调用使用说明及简单实例