Клиент сервер Файлы проецируемы в память

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//CLIENT #include <windows.h> #include <stdio.h> #include <conio.h> #include <tchar.h>
#define BUF_SIZE 256 TCHAR szName[]=TEXT("Global\\MyFileMappingObject");
int _tmain() { HANDLE hMapFile; LPCTSTR pBuf; POINT pt; TCHAR buf[32]={0};
GetCursorPos (&pt); wsprintf (buf, _T("pt.x: %d pt.y: %d"), pt.x, pt.y); hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE, 0, BUF_SIZE, szName);
if (hMapFile == NULL) { printf("Could not create file mapping object (%d).\n", GetLastError()); return 1; } pBuf = (LPTSTR) MapViewOfFile(hMapFile,FILE_MAP_ALL_ACCESS,0,0,BUF_SIZE);
if (pBuf == NULL) { printf("Could not map view of file (%d).\n", GetLastError());
CloseHandle(hMapFile);
return 1; }
CopyMemory((PVOID)pBuf, buf, (_tcslen(buf) * sizeof(TCHAR))); _getch(); UnmapViewOfFile(pBuf);
CloseHandle(hMapFile);
return 0; }
//// SERVER #include <windows.h> #include <stdio.h> #include <conio.h> #include <tchar.h> #pragma comment(lib, "user32.lib")
#define BUF_SIZE 256 TCHAR szName[]=TEXT("Global\\MyFileMappingObject");
int _tmain() { HANDLE hMapFile; LPCTSTR pBuf;
hMapFile = OpenFileMapping( FILE_MAP_ALL_ACCESS, FALSE,szName);
if (hMapFile == NULL) { printf("Could not open file mapping object (%d)\n", GetLastError()); return 1; }
pBuf = (LPTSTR) MapViewOfFile(hMapFile,FILE_MAP_ALL_ACCESS, 0,0, BUF_SIZE);
if (pBuf == NULL) { printf("Could not map view of file (%d).\n",GetLastError());
CloseHandle(hMapFile);
return 1; }
MessageBox(NULL, pBuf, TEXT("Process2"), MB_OK);
UnmapViewOfFile(pBuf);
CloseHandle(hMapFile);
return 0; }