接口问题,就想在Dll中调用主程序的方法,一直出错,请指教
-------类申明--------
type ieface=interface
procedure domessage(s:string);
end;
type Tmyobj=class(TInterfacedObject,ieface)
public
procedure domessage(s:string);
end;
implementation
{ myobj }
procedure Tmyobj.domessage(s: string);
begin
showmessage(s);
end;
-------主程序-------
procedure TForm1.Button2Click(Sender: TObject);
var h:Thandle;
PlugFun:Tpro;
begin
H := LoadLibrary(pchar('mydll.dll'));
try
PlugFun:=GetProcAddress(H, 'myfun');
PlugFun(newbase); //调用两次以上就出错
finally
freeLibrary(H);
end;
end;
---------dll文件--------
procedure myfun(ie:ieface);stdcall;
begin
ie.domessage('asdfasdf');
end;
exports
myfun;
[解决办法]
对象与接口混用, procedure myfun(const ie:ieface);stdcall;