靜態呼叫DLL要怎麼改成動態呼叫呢??? |
答題得分者是:pprayer
|
shine0989
一般會員 發表:9 回覆:31 積分:8 註冊:2008-06-21 發送簡訊給我 |
請問各位大大
先前有發過文後來有得到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] |
pprayer
高階會員 發表:35 回覆:185 積分:174 註冊:2002-03-13 發送簡訊給我 |
請參考這個網址 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 發送簡訊給我 |
感謝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
一般會員 發表:9 回覆:31 積分:8 註冊:2008-06-21 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |