W
wangchw0001
Unregistered / Unconfirmed
GUEST, unregistred user!
dll代码:<br>function GetAllForm(lst1 : TListBox) : Boolean;<br>var<br> i : Integer;<br>begin<br> Result := true;<br> try<br> for i:=0 to Application.ComponentCount-1 do<br> begin<br> if (Application.Components is TForm) then<br> lst1.Items.Add(Application.Components.Name)<br> end;<br> except<br> Result := False;<br> end;<br>end;<br><br>exports<br> GetAllForm;<br><br>begin<br>end.<br><br>主程序调用的代码:<br>unit uMain;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, Buttons;<br><br>type<br> AllDllForm = function(lst1 : TListBox) : Boolean;<br> TfrmMain = class(TForm)<br> lst1: TListBox;<br> btn1: TBitBtn;<br> procedure btn1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> frmMain: TfrmMain;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TfrmMain.btn1Click(Sender: TObject);<br>var<br> DLLHandle1: THandle;<br> DLLSub1: AllDllForm;<br>begin<br> DLLHandle1 := LoadLibrary('prjDLL.dll');<br> if DLLHandle1 <> 0 then<br> begin<br> @DLLSub1 := GetProcAddress(DLLHandle1, 'GetAllForm');<br> if Assigned(DLLSub1) then<br> begin<br> if DLLSub1(lst1) then<br> ShowMessage('');<br> end;<br> end;<br>end;<br><br>end.