Link to home
Start Free TrialLog in
Avatar of slicer123
slicer123

asked on

ActiveX Control Interprocess Communication (IPC)

I have an ActiveX (.ocx) control that starts a windows application (winapp.exe) via a spawn call (_spawnl from process.h). The control has a windowed (vs windowless) and thus an associated hWnd (CWnd::m_hWnd). I designed the control so that after the control spawns the winapp, it waits around until the winapp has initialized
itself, and sends back the WIN_APP_READY message to the control. This works as long as the winapp.exe knows the m_hWnd value of the control, but unless I pass that value via command line, I can't figure out how to get the winapp.exe to determine the control's m_hWnd. How can the winapp.exe find the controls m_hWnd via IPC? I looked into the following ways.

1. In the winapp.exe I tried to use EnumWindow() call with a FindWindowEx() to locate the control's m_hWnd, but the ActiveX control is not found because it is not a top level window, or an immediate child window.
2. SendMessage(HWND_BROADCAST,, ..) only sends to top level windows, thus the control does never receive the message.
3. Considering the control spawns a pid, I thought the winapp.exe could use the ppid to identify the hWnd (code examples seem too complex, and possibly prone to security model violations/errors).
4. Associate the control's m_hWnd using a mutex (if possible). I don't know that this would work, but thought it might be a way.

Any other ideas?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of slicer123
slicer123

ASKER

The reason I am looking for another solution is because it requires modifying the startup code of winapp.exe. Thus I was hoping for a simple method of using FindWindow calls. Basically I wanted the code to be as portable as possible, e.g. works under Xp and Vista, works under x86 and x64, does not trigger security model errors, does not blow up other apps, etc.
But failing this, another possibility according to some google results for topic "Spawning Applications and Discovering Window Handles"*, I found that one way is to have the controlling app run a timer event until finding the window has initialized, then passing the hWnd in an LPARAM via a user defined Windows Messaging Protocol.
* Borland C++ Builder 6 Developer's Guide By Bob Swart, Jarrod Hollingworth, Mark Cashman, Paul Gustavson, Chap 14, "Win32 API Functional Areas", pp 538
IMO the command line parameter method is the easiest and most compatible one for all Windows platforms - and since you have to change the code anyway, why shouldn't it be the startup code?
BTW, another simple way would be to put that value somewhere in the registry.
ty