Click here to Skip to main content
15,894,015 members
Articles / Desktop Programming / Win32

Inter-Process Communication (IPC) Introduction and Sample Code

Rate me:
Please Sign up or sign in to vote.
4.91/5 (57 votes)
19 Dec 2009Ms-PL8 min read 251.6K   12.2K   195  
This article will cover general IPC technologies in All-In-One Code Framework. The IPC technologies include Named Pipes, File Mapping, MailSlot, etc.
========================================================================
    WIN32 APPLICATION : CppSendWM_COPYDATA Project Overview
========================================================================

/////////////////////////////////////////////////////////////////////////////
Use:

IPC based on the Windows message WM_COPYDATA is a mechanism for exchanging 
data among Windows applications in the local machine. The receiving 
application must be a Windows application. The data being passed must not 
contain pointers or other references to objects not accessible to the 
application receiving the data. While WM_COPYDATA is being sent, the 
referenced data must not be changed by another thread of the sending process. 
The receiving application should consider the data read-only. The lParam 
parameter is valid only during the processing of the message. The receiving 
application should not free the memory referenced by lParam. If the receiving 
application must access the data after SendMessage returns, it needs to copy 
the data into a local buffer.

CppSendWM_COPYDATA demonstrates how a sending process passes the data to  
other Windows applications by using SendMessage and WM_COPYDATA.


/////////////////////////////////////////////////////////////////////////////
Project Relation:

CppSendWM_COPYDATA -> CppReceiveWM_COPYDATA
CppSendWM_COPYDATA sends data to CppReceiveWM_COPYDATA through the  
WM_COPYDATA message.


/////////////////////////////////////////////////////////////////////////////
Code Logic:

1. Find the handle of the receiving Window (FindWindow)

2. Prepare the COPYDATASTRUCT struct with the data to be sent. 
(COPYDATASTRUCT)

3. Send the COPYDATASTRUCT struct through the WM_COPYDATA message to the 
receiving Window.


/////////////////////////////////////////////////////////////////////////////
References:

MSDN: WM_COPYDATA Message
http://msdn.microsoft.com/en-us/library/ms649011.aspx

MSDN: Using Data Copy
http://msdn.microsoft.com/en-us/library/ms649009.aspx

Inter Process Communication using WM_COPYDATA
http://www.codersource.net/mfc_ipc_wm_copydata.aspx


/////////////////////////////////////////////////////////////////////////////

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
China China
Microsoft All-In-One Code Framework delineates the framework and skeleton of Microsoft development techniques through typical sample codes in three popular programming languages (Visual C#, VB.NET, Visual C++). Each sample is elaborately selected, composed, and documented to demonstrate one frequently-asked, tested or used coding scenario based on our support experience in MSDN newsgroups and forums. If you are a software developer, you can fill the skeleton with blood, muscle and soul. If you are a software tester or a support engineer like us, you may extend the sample codes a little to fit your specific test scenario or refer your customer to this project if the customer's question coincides with what we collected.
http://cfx.codeplex.com/

Comments and Discussions