Posted on 17-10-2012
Filed Under (Technology) by bigbang

I am working on a special project with an unusual design.

In my application/process, I will create a sub process to do some work. In my process, I need to get the feedback from sub process. I want to pass the Window handle of my application/process to this sub process, so I can post message from this sub process.

How can I pass Window Handle to sub process? My sub process is a command line application without Windows UI and with the main function like this:

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       LPTSTR lpCmdLine, int nCmdShow)

I post this question in stackoverflow and get the answer:

Window handles (HWNDs) are global to the system so you can just print the handle as a decimal number into a string buffer, pass it as a string on the command line when you spawn your sub-process with CreateProcess, and call _wtoi() or similar to convert the string back to a handle again.

If you want to create the subprocess by CreateProcess API, then just pass the handle string to the sub process.

© 2012, The Big Bang on Reading Busy. All rights reserved.
On republishing this post you must provide link to the original post.

Post a Comment