Search This Blog

Friday, January 23, 2009

Interprocess communication between two application in MFC

This is the example to show how to send a cstring from one application to another.


Paste this follwing code at sender.

CString csData(_T(""));
csData=" This is the message";
COPYDATASTRUCT copyDT;//Is used for Interprocess communication
copyDT.dwData = NULL;
copyDT.cbData = _tcslen(csData) + 1;
copyDT.lpData = ( void* ) ( ( LPCTSTR ) csData );
HWND hWnd = ::FindWindow(NULL,"Receiver application");
// Finding the handle of receiver application and send

// WM_COPYDATA message is used for Interprocess communication
if(hWnd!=NULL)
{
::SendMessage( hWnd, WM_COPYDATA, 0, (LPARAM)&copyDT );
}


At receiver add WM_COPYDATA message.
Paste the following code

CString csReceived;
csReceived=(LPCTSTR)pCopyDataStruct->lpData;

2 comments:

Unknown said...

Thank u very much for this code.


Nitin Diwan

Unknown said...

Thank u very much for this code


Nitin Diwan