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

360 views Asked by At

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? 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.

2

There are 2 answers

5
David Heffernan On

Since this is in process, and since you have a window available, you can send a user defined message to request the COM object. And then you are all set.

0
Remy Lebeau On

If you have the HWND, you can use GetWindowLong/Ptr(GWL_HINSTANCE) to retrieve the module that the window is associated with.

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. No HWND needed.