This forum is deprecated.
I have two Exes. Exe1 and Exe2 . communication between two exe is established using TIdTCPClient. On CLicking "Merge" button in exe1. i should get the handle of exe2, through which i will get the fmx form to merge it into the panel of exe 1. I am getting the exact handle of exe 2 form . But on using the below code, it is returning NULL
"TCommonCustomForm *wd1 = Fmx::Platform::Win::FindWindow(fmxHandle); " // wd1 becomes null
The Fmx::Platform::Win::FindWindow() function takes a Win32 HWND as input and returns the FMX Form object that owns the HWND. Although an HWND is a global resource and can be accessed across process boundaries, each process has its own memory address space and objects in each process cannot be directly accessed across process boundaries. Which means the HWND you pass to FindWindow() must belong to a Form that exists in the same process that is calling FindWindow(), which is not the case in your situation, which is why FindWindow() returns NULL.
So, you will not be able to merge your UIs together at the FMX level, you would only be able to do so at the Win32 API level, using the Win32 SetParent() function. Which you should not do across process boundaries at all, since FMX is not designed for cross-process sharing of its windows.
In fact, it is not even possible anyway, because an FMX Panel does not have its own HWND, like a VCL Panel does. All child controls in FMX are window-less! Only Forms have HWNDs, since they are the only UI element that directly interacts with the OS. All child controls in FMX are custom-drawn by FMX. Parent/child relationships are managed only by FMX, not by the OS.
Instead of fmx ,if vcl forms are used . Will it work?
I tried using FindControl(), but this is also returning NULL
That will not work either, for the same reasons. You can't use the Vcl.Controls.FindControl() function across process boundaries because of the same address space limitations, and you should not use SetParent() across process boundaries for HWNDs that are not intended to be shared that way.
can you suggest some ways to link form of one exe into another?
As I already told you, you can't merge your UIs across process boundaries, so stop trying, it is not going to work. You need to redesign your approach.
Why do you have 2 separate EXEs with their own UIs, communicating over TCP, and why are you trying to merge the UIs together at all? What is the actual goal here? It sounds like maybe the 2nd EXE is just a work-horse for the 1st EXE, is that right? If so, then it likely doesn't need its own UI at all. The 1st EXE should control the whole UI by itself, sending data to the 2nd EXE for processing and then getting results back to display.