//process1#include#include using namespace std;int main(){ cout << "server" << endl; HANDLE hEvent; HANDLE hFileMap = NULL; char *p = '\0'; hEvent = CreateEvent(NULL, false, false, "MyEvent"); if(hEvent == NULL) { printf("createEvent failed\n"); return 0; } hFileMap = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,BUFSIZ,"haha"); if(hFileMap == NULL) { cout << "hFileMap create wrong" << endl; return 0; } p = (char*)MapViewOfFile(hFileMap,FILE_MAP_READ|FILE_MAP_WRITE,0,0,0); if(p == NULL) { cout << "p create wrong" << endl; return 0; } cin >> p; UnmapViewOfFile(p); CloseHandle(hFileMap); SetEvent(hEvent); CloseHandle(hEvent); return 0;}//process2#include #include using namespace std;int main(){ HANDLE hEvent; HANDLE hFilemap = NULL; char *p; hEvent = CreateEvent(NULL, false, false, "MyEvent"); if(hEvent == NULL) { return 0; } hFilemap = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,BUFSIZ,"haha"); if(hFilemap == NULL) { cout << "hFileMap create failed" << endl; return 0; } p = (char*)MapViewOfFile(hFilemap,FILE_MAP_READ|FILE_MAP_WRITE,0,0,0); WaitForSingleObject(hEvent, INFINITE); cout << p << endl; UnmapViewOfFile(p); CloseHandle(hFilemap); CloseHandle(hEvent); getchar(); return 0;}