刚写了个测试程序,不知是不是你想要的。<br>function exportinterface:ITest;返回ITest接口<br><br>dll部分:<br>//---project2.dpr---//<br>library Project2;<br>uses<br> SysUtils,<br> Classes,<br> Unit2 in 'Unit2.pas';<br><br>{$R *.res}<br>exports<br> exportinterface; //导出函数;<br>begin<br>end.<br><br>//--unit2.pas----//:<br>unit Unit2;<br>interface<br>uses<br> windows;<br>type<br> ITest=interface(IInterface)<br> procedure showmsg;<br> end;<br><br> TTest=class(TInterfacedObject,ITest)<br> private<br> FMsg:string;<br> public<br> procedure showmsg;<br> constructor create;<br> end;<br><br>function exportinterface:ITest;stdcall;<br><br>var<br> Test:ITest;<br><br>implementation<br><br>{ Test }<br>function exportinterface:ITest;<br>begin<br> if Test=nil then<br> Test:=TTest.Create;<br> result:=Test;<br>end;<br><br>constructor TTest.create;<br>begin<br> inherited;<br> FMSg:='dll import interface';<br>end;<br><br>procedure TTest.showmsg;<br>begin<br> messagebox(0,pchar(FMsg),pchar('Test'),MB_OK);<br>end;<br><br>end.<br><br>主程序unit1.pas:<br>函数声明:<br>function exportinterface:ITest;stdcall; external 'project2.dll';<br>调用:<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> CallTest:ITest;<br>begin<br> CallTest:=exportinterface;<br> CallTest.showmsg;<br>end;