DELPHI中动态调用dll

EM9O8J

EM9O8J

2016-02-19 18:47

今天图老师小编给大家介绍下DELPHI中动态调用dll,平时喜欢DELPHI中动态调用dll的朋友赶紧收藏起来吧!记得点赞哦~
 

显式例子:

 ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

unit Main;

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, ExtCtrls, Grids, DBGrids, DB, DBTables, DBCtrls;

 

type

  TForm1 = class(TForm)

    Button1: TButton;

    Edit1: TEdit;

    Edit2: TEdit;

    Image1: TImage;

    DataSource1: TDataSource;

    Table1: TTable;

    Table1SpeciesNo: TFloatField;

    Table1Category: TStringField;

    Table1Common_Name: TStringField;

    Table1SpeciesName: TStringField;

    Table1Lengthcm: TFloatField;

    Table1Length_In: TFloatField;

    Table1Notes: TMemoField;

    Table1Graphic: TGraphicField;

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

    DBGrid1: TDBGrid;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

//  function GetInteger(I:Integer): Integer;stdcall;external 'DLLOne.dll';

//  function GetDouble(F:Double): Double;stdcall;external 'DLLOne.dll';

 

  TGetDouble = function (F:Double): Double; stdcall;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

 

procedure TForm1.Button1Click(Sender: TObject);

var D: Double;

    DLLHandle: THandle;

    Func: TGetDouble;

begin

  Image1.Picture.Assign(Table1Graphic);

  Table1Graphic.Assign(Image1.Picture);

  Exit;

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

  try

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

 

  //Edit1.Text := IntToStr(GetInteger(2));

  //D := GetDouble(2.2);

  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.

 

 

 

 

 

 

 

library DLLTwo;

 

{ Important note about DLL memory management: ShareMem must be the

  first unit in your library's USES clause AND your project's (select

  Project-View Source) USES clause if your DLL exports any procedures or

  functions that pass strings as parameters or function results. This

  applies to all strings passed to and from your DLL--even those that

  are nested in records and classes. ShareMem is the interface unit to

  the BORLNDMM.DLL shared memory manager, which must be deployed along

  with your DLL. To avoid using BORLNDMM.DLL, pass string information

  using PChar or ShortString parameters. }

 

uses

  SysUtils,

  Classes;

 

{$R *.res}

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

  begin

    Result := D;

  end;

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

  begin

    Result := I;

  end;

 

exports

  GetDoubleExt,

  GetInt;

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

 

begin

end.

展开更多 50%)
分享

猜你喜欢

DELPHI中动态调用dll

编程语言 网络编程
DELPHI中动态调用dll

C#中如何调用Delphi写的Dll

编程语言 网络编程
C#中如何调用Delphi写的Dll

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

在C#中动态调用native dll的导出函数

编程语言 网络编程
在C#中动态调用native dll的导出函数

Delphi中动态链接库(DLL)的建立和使用

Delphi
Delphi中动态链接库(DLL)的建立和使用

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

Delphi中的DLL封装和调用对象编写碰到的问题

编程语言 网络编程
Delphi中的DLL封装和调用对象编写碰到的问题

怎样在C#中调用Delphi6写的DLL

电脑网络
怎样在C#中调用Delphi6写的DLL

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Oracle聚焦网格和开发工具

Oracle聚焦网格和开发工具

Time can prove that I love you 时间能证明我有多爱你

Time can prove that I love you 时间能证明我有多爱你
下拉加载更多内容 ↓