I'm running AMD, XP Service Pack 1
Compiling with a .cpp extension using Borland Bcc32
I'm trying to teach myself how to use File Mapping.
This is just the pertinent parts of my program.
Any file can be used for lpstrFile. I'm presently using
a .txt file for testing, but I plan to put in a .bmp
once I get this working.
When I place "GetLastError" under each API, I get "The
operation completed successfully" until I get under
"ReadFile", then I get "The handle is invalid"
// -------------------------------- MAPVIEW STUFF
HANDLE MyFile;
LPVOID lpvObject;
HANDLE hMap;
HANDLE MyDataMap;
char *hData;
DWORD size;
hfile = CreateFile(lpstrFile, GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ,
(LPSECURITY_ATTRIBUTES) NULL,OPEN_EXISTING, FILE_ATTRIBUTE_READONLY,
(HANDLE) NULL);
size = GetFileSize(hfile,NULL);
hMap = CreateFileMapping((HANDLE)INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,size,"MyView");
MyDataMap = (HANDLE)OpenFileMapping(FILE_MAP_READ,TRUE,"MyView");
hData = (char*)MapViewOfFile(hMap,FILE_MAP_ALL_ACCESS,0,0,0);
hmem6 = GlobalAlloc(GHND,size);
lpvObject = (LPVOID)GlobalLock(hmem6);
ReadFile(MyDataMap,lpvObject,size,dwRead6,(LPOVERLAPPED)NULL);
UnmapViewOfFile(hMap);
UnmapViewOfFile(MyDataMap);
MyFile = CreateFile("Map.txt", GENERIC_WRITE,FILE_SHARE_WRITE,
(LPSECURITY_ATTRIBUTES) NULL,CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,(HANDLE) NULL);
WriteFile(MyFile,lpvObject,size,lpNumberOfBytesWritten1,LPOVERLAPPED(NULL));