Communicating Between Hinstances

Say I have two or three instances of the same application open and I want to be able to communicate between them (or have a common variable that can be changed by either opened instance).
The only example I could think of is a bmp editor where you can select a color from one bitmap and can start drawing in another bitmap with that color. I already have that function between child windows, but now I want it between separate instances of the application.

So how would I get the HINSTANCE value of all opened versions of my app? Is this where I could use the PreviousInstance variable from WinMain, or am I supposed to use shell/hook functions?
That's a classic IPC (Interprocess Communication ) question, which is a whole new endeavor for you newbieg.

Various ways to do it, such as memmory maped files, pipes, or windows messaging. However, hPreviousInstance won't likely get you anywhere. That's a holdover from 16 bit Windows, where processes were not isolated from each other.

One fairly easy way to do it is with just Windows Messaging. The FindWindow() Api function will return to you the HWND of another instance of your app if you input the Class Name and the Window Caption, which is something you set. Obtaining the HWND in that manner allows you to SendMessage() that instance. A useful API function that can come into play there is RegisterWindowMessage(). With that you can create your own custom messages, and use the WPARAM and LPARAM parameters to send data back and forth. Might be worth looking into.
Thanks Freddie1, once again you are AWESOME!
Hey, about that tutorial you gave me the link to in another post, have you ever considered writing a book on Windows API for C++? And if you have written one then what's the title so I can get it?

http://www.jose.it-berater.org/smfforum/index.php?PHPSESSID=cc76bddfbb165cedf476000ee3fd2303&board=380.0
Last edited on
Never wrote any books and likely never will. That material referenced above was an attempt to help PowerBASIC coders to get started in C and C++. Many of the more advanced PowerBASIC coders see a benifit in that there is such a large user base of C family coders and so much C code and examples out there. Also, many would like to become more familiar with calling Windows Api functions.

A lot of that material is stuff I've never seen in any books and a lot of it took me a long time to figure out, so I thought others might find it useful. Thanks for the kind words! I can tell from your questions that you are plowing through some heavy duty stuff!
Topic archived. No new replies allowed.