简体   繁体   English

如何与WPF用户控件中托管的Delphi窗口通信?

[英]How can I communicate with a Delphi window hosted in a WPF User Control?

Well, actually I know I can communicate with the window itself, the plane GUI, through it's message pump, but let's say I want to call a COM exposed function in the Delphi DLL that produced and maintains that window? 好吧,实际上我知道我可以通过它的消息泵与窗口本身,平面GUI进行通信,但是让我说我​​想在生成并维护该窗口的Delphi DLL中调用COM公开函数吗? I would first somehow have to determine the module that owns the window. 首先,我将不得不确定拥有该窗口的模块。

Communications to the Delphi side are minimal: you are now hosted, your host ID is x , can you close, you must close, etc. The rest of the time I will expose my host as a COM object the Delphi code can more easily talk to. 与Delphi端的通信非常少:您现在已托管,您的主机ID为x ,可以关闭,必须关闭,等等。其余时间,我会将主机公开为COM对象,Delphi代码可以更轻松地讨论至。

If you have the HWND, you can use GetWindowLong/Ptr(GWL_HINSTANCE) to retrieve the module that the window is associated with. 如果您具有HWND,则可以使用GetWindowLong/Ptr(GWL_HINSTANCE)来检索与窗口关联的模块。

Another option is to have the DLL register its COM object in the ROT (Running Object Table) and then you can simply query the ROT for the COM object when needed. 另一个选择是让DLL在ROT(运行对象表)中注册其COM对象,然后您可以在需要时简单地向ROT查询COM对象。 No HWND needed. 无需HWND。

Since this is in process, and since you have a window available, you can send a user defined message to request the COM object. 由于此过程正在进行中,并且您具有可用的窗口,因此可以发送用户定义的消息来请求COM对象。 And then you are all set. 然后你们都准备好了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM