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}