您好,登錄后才能下訂單哦!
DLL鏈接庫代碼
Library Project1; uses Forms, Unit1 in 'Unit1.pas' {Form1}; Function ShowForm(AHandle:THandle):Boolean;StdCall; var AForm:TForm1; begin Result:=False; Application.Handle:=AHandle; AForm:=TForm1.Create(Application); Try AForm.ShowModal; Result:=True; Finally AForm.Free; end; end; {$R *.res} exports ShowForm; begin end.
Form中調用代碼
unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; TShowForm=Function (AHandle:THandle):Boolean;Stdcall; //001 var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var mainfrm,DllForm:THandle; //002 ShowForm:TShowForm; //003 begin mainfrm:=Form1.Handle; //004 DllForm:=LoadLibrary('hello.dll'); //005 Try begin if DllForm<>0 then begin @ShowForm:=GetProcAddress(DllForm,'ShowForm'); ShowForm(mainfrm); end else begin RaiseLastWin32Error; end; end; Finally FreeLibrary(DllForm); end; end; procedure TForm1.FormCreate(Sender: TObject); begin end; end.
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。