Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4595248
  • 博文数量: 671
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 7310
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-14 09:56
文章分类

全部博文(671)

文章存档

2011年(1)

2010年(2)

2009年(24)

2008年(271)

2007年(319)

2006年(54)

我的朋友

分类:

2007-04-21 15:19:57

动态调用Dll:
 
在type部分定义函数类型
 
 TGetDouble = function (F:Double): Double; stdcall;
 
在调用时:

procedure TForm1.Button1Click(Sender: TObject);

var

    D: Double;

    DLLHandle: THandle;

    Func: TGetDouble;

begin

 

  DLLHandle := LoadLibrary('DLLOne.dll');

  try

  @Func := GetProcAddress(DLLHandle, 'GetDouble');

 

  if Assigned(@Func) then

  begin

    D := Func(2.2);

    Edit2.Text := FloatToStr(D);

  end;

 

  finally

  FreeLibrary(DLLHandle);

  end;

end;

 

end.

 

隐式调用:

 

library DLLOne;

 

uses

  SysUtils,

  Classes;

 

{$R *.res}

 

  function GetDoubleExt(F:Double): Double;stdcall;external 'DLLTwo.dll';

  function GetInt(I:Integer): Integer;stdcall;external 'DLLTwo.dll';

 

  function GetInteger(I:Integer): Integer;stdcall;

  begin

    Result := GetInt(I);

  end;

 

  function GetDouble(D:Double): Double;stdcall;

  begin

    Result := GetDoubleExt(D);

  end;

 

exports

  GetInteger,

  GetDouble;

 

begin

end.

阅读(3658) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~