Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ActiveX Control Interprocess Communication (IPC)

Posted on 2008-10-15
5
Medium Priority
?
1,558 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

610 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