惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
月光博客
月光博客
IT之家
IT之家
B
Blog RSS Feed
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - Franky
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
博客园_首页
B
Blog
V
V2EX
腾讯CDC
Vercel News
Vercel News
量子位
Microsoft Security Blog
Microsoft Security Blog

博客园 - 周黔

delphi firemonkey 12.3 动态绑定TFDMemTable到TStringGrid delphian firemonkey. android:exported 错误 RAD Studio 12 Delphi 12 实现手机无线wifi调试 (巧用Android Studio 2024 连WIFI) delphi 11 HMACSha512 Android Studio 2024 不需要三方插件,直接wifi 开发调试,真方便 CEF4Delphi(DELPHI Google Chrome 浏览器封装) 折腾 (2)--打开一个网页 CEF4Delphi(DELPHI Google Chrome 浏览器封装) 折腾 (1)--安装 Delphi WINAPI 任意拖动移动控件 DELPHI 调用标准C接口DLL char *value Apache NetBeans IDE 12.3 双击无反应怪事 [转]Regions and Clipping in GDI+ delphi 10.4 JSON 建立数组示例 delphi 10.3实现TNetHTTPClient 异步 POST 另类实现返回附加标记及Unicode 编码与解码 \u - 周黔 小程序开发笔记1 Delphi DLL 消息循环 Synchronize SendMessage PostMessage 用户中心 - 博客园 DELPHI GDI + TGPFont UnitPixel 问题解决 delphi DLL image 动态绘图 句柄处理 delphi 每英寸相素点取值偏差
delphi 跨版本DLL调用嵌入窗体实现
周黔 · 2019-11-26 · via 博客园 - 周黔

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

     因此,跨版本的DLL调用,实际上也就是把DLL当做一个独立程序,而数据连接这些需要在DLL中自己再实现一套,会有一定的麻烦,但是如果不得不这样做,这样的牺牲也是没办法的事(如果谁实现了协调的跨版本数据连接共享,希望留言指点一二)

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

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

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

跨版本相当于独立的程序调用,因此入口函数,就不能再处理  Application与 Screen了,咋们,就当这个DLL是一个独立EXE

如果传了  Application与 Screen ,就是建一个简单的FORM都会报地址错,因为相同的类在不同版本里面,其定义差异很大了。

加载DLL后

下面就是显示窗体了

直接上代码吧

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 常规代码,更具有兼容性。

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

就是普通的接口调用了

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代码。