Win32 inter-process communication-shared memory and win32 inter-process communication --

Source: Internet
Author: User

Win32 inter-process communication-shared memory and win32 inter-process communication --

Please kindly advise if you have any mistakes!

Recently, I looked at win32 inter-process communication. Simple Writing: using shared memory for inter-process communication

Use shared memory for inter-process communication:

1. Create a file ing kernel object in the WM_CREATE message

1 hMapFile = CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, BUF_SIZE, (LPCWSTR) szName );

 

2. Map the cache view where data needs to be shared, and put the data to be written into pbuf

1 pBuf = (char *) MapViewOfFile (2 hMapFile, 3 FILE_MAP_ALL_ACCESS, 4 BUF_SIZE-1); 7 GetWindowText (hEdit2, (LPWSTR) szSend, BUF_SIZE); 8 strncpy (pBuf, szSend, BUF_SIZE-1); 9 pBuf [BUF_SIZE-1] = '\ 0 ';

 

3. After the user process stops using the shared memory, call the UnmapViewOfFile function to cancel the view in the address space (you can set it in WM_DESTROY)

1 if (hMapFile) {2 UnmapViewOfFile (pBuf); 3 CloseHandle (hMapFile); 4}

 

Related Article

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.