DELPHI中動態呼叫dll

2021-03-31 08:57:00 字數 2574 閱讀 1119

顯式例子

:unit main;

inte***ce

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;

table1***mon_name: tstringfield;

table1speciesname: tstringfield;

table1lengthcm: tfloatfield;

table1length_in: tfloatfield;

table1notes: tmemofield;

table1graphic: tgraphicfield;

dbgrid1: tdbgrid;

procedure button1click(sender: tobject);

private

public

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;

varform1: tform1;

implementation

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;

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;

uses

sysutils,

classes;

function getdoubleext(d:double):double ;stdcall;

begin

result := d;

end;

function getint(i:integer): integer;stdcall;

begin

result := i;

end;

exports

getdoubleext,

getint;

begin

end.

delphi動態呼叫dll窗體

宣告 tshowform function ahandle thandle acaption pchar boolean stdcall 呼叫 procedure tform1.n5click sender tobject var mainfrm,dllform thandle showform t...

Delphi 動態與靜態呼叫DLL

摘要 本文闡述了 windows 環境下動態連結庫的概念和特點,對靜態呼叫和動態呼叫兩種呼叫方式作出了比較,並給出了 delphi 中應用動態連結庫的例項。一 動態連結庫的概念 動態連結庫 dynamic link library 縮寫為 dll 是一個可以被其它應用程式共享的程式模組,其中封裝了一...

DELPHI中建立呼叫DLL

一,新建 new other dll wizard 二,library new uses sysutils,classes,dialogs procedure dll begin showmessage delphi end exports dll begin end.三,儲存,四,project ...

Delphi動態呼叫C 寫的DLL

c dll 檔案,建議用最簡單的c 編輯工具。不會加入很多無關的dll檔案。本人用codeblocks mingw。不像 vs2010,dll編譯成功,呼叫的時候會提示缺其他dll。系統生成的main.h和main.cpp ifndef main h define main h include to...

Delphi中怎麼呼叫vb的DLL

vb直接生成的是activex dll,經過改造,也能生成標準的windows dll。不知道你說的vb生成的dll是哪一類?1.標準的windows dll,delphi的例子很多。無需等vb生成的dll。2.如果是vb生成的active x dll,那麼 首先註冊vb的activex dll,然...