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;
5 个解决方案
#1
第一次调用完成后指向接口的指针被释放掉了吧?
#2
对象与接口混用, procedure myfun(const ie:ieface);stdcall;
#3
楼上正确,加上const
#4
谢谢,已解决·
#1
第一次调用完成后指向接口的指针被释放掉了吧?
#2
对象与接口混用, procedure myfun(const ie:ieface);stdcall;
#3
楼上正确,加上const
#4
谢谢,已解决·