首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

接口有关问题,就想在Dll中调用主程序的方法,一直出错

2012-09-15 
接口问题,就想在Dll中调用主程序的方法,一直出错,请指教-------类申明--------type iefaceinterfaceproce

接口问题,就想在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;

热点排行