全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1767
推到 Plurk!
推到 Facebook!

靜態呼叫DLL要怎麼改成動態呼叫呢???

答題得分者是:pprayer
shine0989
一般會員


發表:9
回覆:31
積分:8
註冊:2008-06-21

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-04-26 17:10:35 IP:123.204.xxx.xxx 訂閱
請問各位大大
先前有發過文後來有得到jow大大給的範例

但是小弟想要改成動態的不知道要怎麼改???

這是DLL裡的語法

[code delphi]

library TestDll009;
...
...


uses
SysUtils,
Classes,
Forms,
fChild1 in 'UNIT\fChild1.pas' {frmChild1},
fChild2 in 'UNIT\fChild2.pas' {frmChild2};
{$R *.res}
function GetChildForm(MDIMainForm: TForm; AClassName: string; var f: TForm): Boolean;
var
I: Integer;
begin
f := nil;
for I := 0 to MDIMainForm.MDIChildCount-1 do
begin
if MDIMainForm.MDIChildren[I].ClassNameIs(AClassName) then
begin
f := MDIMainForm.MDIChildren[I];
Break;
end;
end;

if f = nil then
begin
if AClassName = 'TfrmChild1' then f := TfrmChild1.Create(MDIMainForm)
else
if AClassName = 'TfrmChild2' then f := TfrmChild2.Create(MDIMainForm)
end;
Result := f <> nil;

end;

exports GetChildForm;


[/code]


小弟都改不成功. ><"
一直報錯...

是DLL裡也要變動嗎??

這是MDI主FORM呼叫DLL的呼叫方式

[code delphi]

function GetChildForm(MDIMainForm: TForm; AClassName: string; var f: TForm): Boolean; external 'TestDll009.dll';

procedure TMainForm.DLL11Click(Sender: TObject);
var
f: TForm;
begin
if GetChildForm(Self,'TfrmChild1',f) then
begin
f.WindowState := wsMaximized;
f.BringToFront;
end;
MainMDIspeedButtonCheck;
end;

[/code]




編輯記錄
shine0989 重新編輯於 2010-04-26 17:45:07, 註解 無‧
shine0989 重新編輯於 2010-04-26 17:46:38, 註解 無‧
shine0989 重新編輯於 2010-04-26 17:47:29, 註解 無‧
shine0989 重新編輯於 2010-04-29 16:04:28, 註解 無‧
pprayer
高階會員


發表:35
回覆:185
積分:174
註冊:2002-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-04-26 19:37:00 IP:114.32.xxx.xxx 訂閱

請參考這個網址
http://www.swissdelphicenter.ch/torry/showcode.php?id=1109


1.要先宣告一種funciton類別
2. 用LoadLiarary 取得 dll 的 handle
3. 用GetProcAddress取得dll handle 內 某個 function的位址並回傳到一個 函式類別的變數
4.使用該函式類別變數
5.用FreeLibrary 釋放 dll handle

type
TWTSRegisterSessionNotification = function(Wnd: HWND; dwFlags: DWORD): BOOL; stdcall;
var
hWTSapi32dll: THandle;
WTSRegisterSessionNotification: TWTSRegisterSessionNotification;
begin
Result := False;
hWTSAPI32DLL := LoadLibrary('Wtsapi32.dll');
if (hWTSAPI32DLL > 0)
then
begin
try
@WTSRegisterSessionNotification :=
GetProcAddress(hWTSAPI32DLL, 'WTSRegisterSessionNotification');
if Assigned(WTSRegisterSessionNotification)
then
begin
Result:= WTSRegisterSessionNotification(Wnd, dwFlags);
end;
finally
if
hWTSAPI32DLL > 0
then
FreeLibrary(hWTSAPI32DLL);
end;
end;
end;

shine0989
一般會員


發表:9
回覆:31
積分:8
註冊:2008-06-21

發送簡訊給我
#3 引用回覆 回覆 發表時間:2010-04-29 16:06:23 IP:123.204.xxx.xxx 訂閱
感謝pprayer大大的回覆...

看了大大的範例..
小弟一直試不出來><" 唉...

請問大大能否將這個↓


[code delphi]

function GetChildForm(MDIMainForm: TForm; AClassName: string; var f: TForm): Boolean; external 'TestDll009.dll';

procedure TMainForm.DLL11Click(Sender: TObject);
var
f: TForm;
begin
if GetChildForm(Self,'TfrmChild1',f) then
begin
f.WindowState := wsMaximized;
f.BringToFront;
end;
MainMDIspeedButtonCheck;
end;

[/code]

改成動態呼叫的方式呢??


===================引 用 pprayer 文 章===================

請參考這個網址
http://www.swissdelphicenter.ch/torry/showcode.php?id=1109


1.要先宣告一種funciton類別
2. 用LoadLiarary 取得 dll 的 handle
3. 用GetProcAddress取得dll handle 內 某個 function的位址並回傳到一個 函式類別的變數
4.使用該函式類別變數
5.用FreeLibrary 釋放 dll handle

[code delphi]

type
TWTSRegisterSessionNotification = function(Wnd: HWND; dwFlags: DWORD): BOOL; stdcall;
var
hWTSapi32dll: THandle;
WTSRegisterSessionNotification: TWTSRegisterSessionNotification;
begin
Result := False;
hWTSAPI32DLL := LoadLibrary('Wtsapi32.dll');
if (hWTSAPI32DLL > 0) then
begin
try @WTSRegisterSessionNotification :=
GetProcAddress(hWTSAPI32DLL, 'WTSRegisterSessionNotification');
if Assigned(WTSRegisterSessionNotification) then
begin
Result:= WTSRegisterSessionNotification(Wnd, dwFlags);
end;
finally
if hWTSAPI32DLL > 0 then
FreeLibrary(hWTSAPI32DLL);
end;
end;
end;

[/code]

編輯記錄
shine0989 重新編輯於 2010-04-29 16:07:45, 註解 無‧
shine0989 重新編輯於 2010-04-29 16:09:06, 註解 無‧
shine0989 重新編輯於 2010-05-04 15:43:33, 註解 請問有那位好心的大大能指點小弟呢??‧
shine0989
一般會員


發表:9
回覆:31
積分:8
註冊:2008-06-21

發送簡訊給我
#4 引用回覆 回覆 發表時間:2010-05-07 10:43:42 IP:123.204.xxx.xxx 訂閱
請問有那位好心的大大能指點小弟呢??

或是能給小弟範例看看!!

就是呼叫相同的DLL
但是一個是用動態的另一個是用靜態的!!
(希望能以我PO的範例來改 ^^")
編輯記錄
shine0989 重新編輯於 2010-05-07 10:45:40, 註解 無‧
系統時間:2024-05-04 3:16:33
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!