Click here to Skip to main content
16,017,650 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello all, I am tring to communicate between 2 applications using wm_copydata.

I am not sure how to pass HWND using COPYDTASTRUCT.

C++
HWND hWnd = FindWindow(NULL, "Advisor");
	if (hWnd)
	{
/////Sending Application.
		COPYDATASTRUCT cds;
		ZeroMemory(&cds, sizeof(COPYDATASTRUCT));
		cds.dwData = WM_CREATE;
		cds.lpData = (HWND)ResulthWnd;
		cds.cbData = sizeof(ResulthWnd);
		SendMessage(hWnd,WM_COPYDATA,(WPARAM)ResulthWnd,(LPARAM)&cds);
         }

////////Receiving Application
switch (pCopyDataStruct->dwData)
	{
	case WM_CREATE:
         HWND SenderWnd = (HWND)pCopyDataStruct->lpData;
break;
         }



Can someone please help.

Thanks in advance.
Posted

1 solution

The member cds.lpData should be a pointer, (LPARAM)&ResultWnd (please fix the typo in the world "Result"), not HWND.

I would like to note, that exchanging data between two different processes is the artifact of the legacy Windows API created even before NT technology and is not a mainstream OS feature. The processes in real multi-process systems are supposed to be isolated and communicating only via IPC, such as sockets. So, WM_COPYDATA is neither safe not robust. You need to make a careful decision about it and consider alternative. The apparent simplicity of the approach could be very deceiving.

See also:
http://www.flounder.com/wm_copydata.htm[^],
Interprocess Communication Between .NET and MFC Using WM_COPYDATA[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900