delphi 跨版本DLL调用嵌入窗体实现

       delphi 能实现把别的DLL的窗体句柄查到后,贴到PANL之中,此类文章网上很多,而若是是delphi不一样版本开发的DLL互调时,一些控件内部的定义有所区别,由于没法(至少目前我以为理论上不可行)实现不一样版本的DLL融合一体式的共用同一个appcation.app

     所以,跨版本的DLL调用,实际上也就是把DLL当作一个独立程序,而数据链接这些须要在DLL中本身再实现一套,会有必定的麻烦,可是若是不得不这样作,这样的牺牲也是没办法的事(若是谁实现了协调的跨版本数据链接共享,但愿留言指点一二)函数

 Function GETInterfacedFunc(iApplication:TApplication;iScreen: TScreen;Imode:integer;Userinfo:String):IInterfacedFunc ;stdcall;

 上面的代码,是常规的DELPHI 的DLL调用实现,也就是传入   orm

iApplication:TApplication;iScreen: TScreen; 而后返回调用接口。
 Function GETInterfacedFunc(Imode:integer;Userinfo:String):IInterfacedFunc ;stdcall;    

跨版本至关于独立的程序调用,所以入口函数,就不能再处理  Application与 Screen了,咋们,就当这个DLL是一个独立EXEblog

加载DLL后接口

下面就是显示窗体了开发

直接上代码吧it

function Tform.Showform(Parent: THandle;PHeight:integer;PWidth:integer ): boolean;
begin
  frm:=TfrmMain.Create(nil);  //
  DM:=TDM.Create(application); //application
  if  WINAPI.Windows.SetParent(frm.Handle,Parent)=0 then
  begin
    Result:=False;
    frm.Free;
    Exit;
  end;
 SetWindowLong(frm.Handle,GWL_STYLE,GetWindowLong(frm.Handle,GWL_STYLE) and not (WS_CAPTION or WS_THICKFRAME));
//   //WS_CAPTION和WS_THICKFRAME分别表示标题栏和边框
WINAPI.Windows.MoveWindow(frm.Handle,0,0,PWidth,PHeight,True);
 frm.Show;
end;  

使用winAPI 来实现窗体的处理,比直接用delphi 常规代码,更具备兼容性。io

外部EXE中的调用代码,我想不须要特别列出,其实与同版本调用,已是完样同样的了。function

就是普通的接口调用了form

IInterfacedFunc=interface
  ['{1440EC99-A782-4E12-9F82-3020C8D887B4}']
    Function Showform(Parent: THandle;PHeight:integer;PWidth:integer):boolean;stdcall;
    procedure Resize(PHeight:integer;PWidth:integer);stdcall;
    procedure CloseForm ;stdcall;
    procedure SetCloseProc(Proc:TCloseProc);stdcall;
 end;

  附:接口pas代码。

相关文章
相关标签/搜索