靜態 動態呼叫dll封裝窗體 模態 非模態

2021-06-13 01:46:33 字數 2054 閱讀 5268

看到有網友需要這樣的例子,所以寫了乙個.  

有不對或不合理的地方請跟帖指導.

delph xe下測試通過.

dll專案檔案

library project10;

uses

sysutils,

classes,

forms,

unit14 in 'unit14.pas' ;

function edebtmoney(h: thandle): integer;

begin

tryshowmodal;

result := 0;

finally

free;

end;

end;

function getform(h: thandle): thandle;

begin

tryshow;

result := handle;

except on e : exception do

raise e.create(e.message);

end;

end;

exports edebtmoney, getform;

begin

end.

dll中窗體關閉事件

procedure tform1.formclose(sender: tobject; var action: tcloseaction);

begin

action := cafree;

end;

呼叫單元

unit unit13;

inte***ce

uses

windows, messages, sysutils, variants, classes, graphics, controls, forms,

dialogs, stdctrls;

type

tform13 = class(tform)

btn1: tbutton;

btn2: tbutton;

procedure btn1click(sender: tobject);

procedure btn2click(sender: tobject);

private

public

end;

var form13: tform13;

function myform(h: thandle) : thandle; stdcall;

implementation

function myform; external 'project10.dll' name 'getform';

//動態呼叫 模態視窗

procedure tform13.btn1click(sender: tobject);

type

tgetform = function (h: thandle) : integer; cdecl;

var dllform : tgetform;

dllhandle : thandle;

nn : integer;

begin

dllhandle := loadlibrary(pchar('project10.dll'));

tryif dllhandle <> 0 then

begin

dllform := getprocaddress(dllhandle, 'edebtmoney');

self.caption := inttostr(nn);

end;

finally

freelibrary(dllhandle);

end;

end;

//靜態呼叫 非模態視窗

procedure tform13.btn2click(sender: tobject);

var dllhandle : thandle;

begin

end;

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 是乙個可以被其它應用程式共享的程式模組,其中封裝了一...

DLL封裝呼叫

首先需要建立乙個dll,在vs選中檔案 新建 專案 名稱為mydll 在裡面隨便寫乙個方法 public static string name li public static string number 12567032 public static string age 21 public sta...