1、VC6
#include <stdio.h> #include <windows.h> void main() { char* pc = "AAA"; HANDLE hMem = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4, pc); if (hMem == NULL) { printf("CreateFileMapping return NULL"); return; } void* pMem = MapViewOfFile(hMem, FILE_MAP_WRITE, 0, 0, 0); if (pMem == NULL) { printf("MapViewOfFile return NULL"); return; } UnmapViewOfFile(pMem); CloseHandle(hMem); // *** hMem = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4, pc); if (hMem == NULL) { printf("CreateFileMapping return NULL"); return; } pMem = MapViewOfFile(hMem, FILE_MAP_WRITE, 0, 0, 0); if (pMem == NULL) { printf("MapViewOfFile return NULL"); return; } UnmapViewOfFile(pMem); CloseHandle(hMem); // *** hMem = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4, pc); if (hMem == NULL) { printf("CreateFileMapping return NULL"); return; } pMem = MapViewOfFile(hMem, FILE_MAP_WRITE, 0, 0, 0); if (pMem == NULL) { printf("MapViewOfFile return NULL"); return; } UnmapViewOfFile(pMem); CloseHandle(hMem); }
2、
3、
4、
5、