) Windows Process Communication Methods

Source: Internet
Author: User

A process is usually defined as a runningProgramInstance, which consists of two parts:

One is the kernel object used by the operating system to manage processes. The kernel object is also used by the system to store process statistics.

The other is the address space, which contains all executable modules or DLL modules.CodeAnd data. It also contains dynamically allocated space. Such as thread stack and heap allocation space. Each process is assigned its own virtual address space. When a thread in the process is running, the thread can access the memory of the process that only belongs to it. Memory of other processes is hidden and cannot be accessed by running threads.

In order to communicate between two processes, the following methods can be used for reference:

1. Clipboard clipboard: Commonly Used in the 16-bit era, supported by cwnd

2. The windows message standard and the dedicated wm_copydata message sendmessage () receiving end must have a window

3. Use shared memory (shared memory)

A. Set a shared memory area

Handle createfilemapping (handle, lpsecurity_attributes, DWORD, lpcstr)

Generate a file-mapping core object

Lpvoid mapviewoffile (
Handle hfilemappingobject,
DWORD dwdesiredacess,
DWORD dwfileoffsethigh,
DWORD dwfileoffsetlow,
DWORD dwnumberofbytestomap
);

Get the shared memory pointer

B. Find out the shared memory

It is determined that the memory should be presented in a peer-to-peer manner. Each process must have the same capabilities, generate shared memory, and initialize it. Each process
You should call createfilemapping () and then call getlasterror (). if the returned error code is error_already_exists, the process can assume that the shared memory domain has been opened and initialized by other processes, otherwise, the process can reasonably consider itself as the first place, and then initialize the shared memory.

In the client/server architecture, only the server process should generate and initialize the shared memory. All processes should use

Handle openfilemapping (DWORD dwdesiredaccess,
Bool binherithandle,
Lptstr lpname );

Call mapviewoffile () to obtain the shared memory pointer.

C. synchronous processing (mutex)

D. Cleaning up bool unmapviewoffile (lpcvoid lpbaseaddress );

Closehandle ()

4. Dynamic Data Exchange (DDE) enables inter-application transfer by maintaining global memory allocation

The method is to manually place a large amount of data in the global memory, and then use the window message to pass the memory pointer. this is the method used in the 16-bit win era, because there is no global or local memory in Win32, and currently there is only one kind of memory: virtual memory.

5. Message Pipe)

It is used to set a permanent communication channel between applications. Through this channel, you can read and write data as if your applications were accessing a flat file.

Anonymous pipeline (anonymous pipes)

One-way flow, and can only flow between processes on the same computer.

Named Pipes)

Two-way, cross-network, any process can easily grasp, the data put into the pipeline has a fixed format, and the use of readfile () can only read a multiple of this size.

Can be used in I/O Completion Ports

6. mailslots)

Broadcast Communication, a new method provided in 32 systems, supports data exchange between different hosts, and only supports mail slot customers in Win9x

7. Windows Socket)

It has all the functions of the message pipeline, but complies with a set of communication standards so that applications on different operating systems can communicate with each other.

8. Internet communication: allows applications to upload or download files from Internet addresses.

9. RPC: Remote Procedure Call is rarely used because it is not compatible with Unix RPC.

10. Serial/parallel communication (Serial/parallel communication)

It allows applications to communicate with other applications through serial or parallel ports.

11. COM/DCOM performs inter-process data exchange through the proxy stub of the com system, but it can only transmit data when calling interface functions, data can be transferred between different hosts through DCOM.

 

BetterArticle

Method 1: wm_copydata
Hwnd hreceivedatawindow = findwindow (null ,....)
Copydatastruct data;
Data. cbdata = strlen (pstr );
Data. lpdata = pstr;
Sendmessage (hreceivedatawindow, wm_copydata, (wparam) getfocus (), (lparam) & data ); Ref. The simplest way to http://www.cppblog.com/TechLab/archive/2005/12/30/2272.aspx Method 2: DLL sharing
# Pragma data_seg (". ashare ")
Int iwhatyouuseintwo = 0;
# Pragma data_seg ()
Method 3: image files
Createfilemapping
Ref. The most basic, the most efficient method the best reference book windows core programming chapter 17th memory ing file http://blog.codingnow.com/2005/10/interprocess_communications.html
Method 4: anonymous pipe: createpipe
Method 5: Named Pipe: createnamedpipe Ref. http://www.pediy.com/bbshtml/bbs8/pediy8-724.htm Method 6: email Channel
Createmailslot

Method 7: network interface, socket, But Nic required. Enable IPC between different hosts Another summary of the better article http://www.seeitco.com/doc/Html/Visual%20C++/205637623.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.