Dave's Brain

Browse - Programming Tips - How do I send data from a Windows process to another?

Date: 2008nov10
Platform: win32
Keywords: interprocess, IPC, two

Q.  How do I send data from a Windows process to another?

A.  If you just want to send 2 numbers do this:

// This is the class name you used in your InitApplication() routine // of the receiver. Typically win32 apps have routine named // InitApplication() that calls RegisterClass() with a class name // and other stuff static LPCSTR gszReceiverClass = "ReceiverClass"; // CHANGE THIS!!!! // The Receiver needs to process this windows message #define WM_TWO_NUMBERS_TO_RECEIVER (WM_APP+1) BOOL SendReceiverNumbers(const WPARAM n1, const LPARAM n2) { HWND hwndRec; if ((hwndRec = FindWindow(gszReceiverClass, NULL)) == NULL) return FALSE; return PostMessage(hwndRec, WM_TWO_NUMBERS_TO_RECEIVER, n1, n2); }
If your numbers are small you can actually send 4 like this:
BOOL SendReceiver4Numbers(const WORD a, const WORD b, const WORD c, const WORD d) { return SendReceiverNumbers(MAKEWPARAM(a,b), MAKELPARAM(a,b)); // Use LOWORD() on the receiving side }
A Win32 Receiver does this:
case WM_TWO_NUMBERS_TO_RECEIVER: { int n1 = wParam; int n2 = lParam; // Do stuff with n1 and n2 } break;
If you want to pass more look at http://www.davekb.com/search.php?target=WM_COPYDATA

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.