Solved

ActiveX Control Interprocess Communication (IPC)

Posted on 2008-10-15
5
1,539 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:slicer123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 22723670
For IPC in general, see http://www.codeproject.com/KB/threads/Win32IPC.aspx ("Windows IPC"). Yet for your purpose, that'd be overkill -I'd just pass the window handle as a command line parameter, e.g.
// OCX
 
char buf[MAX_PATH];
 
sprintf(buf,"winapp.exe %d", m_hWnd);
 
// exe
 
#include <stdlib.h>
 
//...
 
LPWSTR pCmd = GetCommandLineW();
 
LPWSTR* pArgs = CommandLineToArgvW(pCmd,2);
 
HWND hOCX = (HWND) _wtoi(pArgs[1]);

Open in new window

0
 
LVL 2

Author Comment

by:slicer123
ID: 22723865
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 22724203
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?
0
 
LVL 86

Expert Comment

by:jkr
ID: 22724211
BTW, another simple way would be to put that value somewhere in the registry.
0
 
LVL 2

Author Closing Comment

by:slicer123
ID: 31506398
ty
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question