{
HANDLE hFile;
DWORD dwFileSize;
hFile = CreateFile("Heimp.hmp", GENERIC_READ, 0,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
MessageBox(NULL, "hFile invalid.", "ERROR", MB_OK);
return FALSE;
}
dwFileSize = GetFileSize(hFile, NULL);
HANDLE hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if(hFileMap == NULL)
{
MessageBox(NULL, "Couldn't create file map.", "File I/O Error", MB_OK | MB_ICONSTOP);
return FALSE;
}
/*Map a view of the file*/
BYTE *pbFile = (BYTE *) MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0);
CloseHandle(hFile);
CloseHandle(hFileMap);
for(unsigned int ind = 0; ind < dwFileSize; ind++)
{
HeightMap[ind] = *(pbFile + ind);
}
UnmapViewOfFile((PVOID) pbFile);
return TRUE;
}
Memory Mapped Files. Need some help.
Well, I have a problem. I am trying to create a memory mapped file and load the info from it. Well, I step through using debugger, and hFileMap is being set to 0x0000000h.
Darn memory mapped files. Thanks for any help.
What does GetLastError() return when CreateFileMapping() fails?
EDIT: Also, try setting the third parameter to FILE_SHARE_READ
EDIT: Also, try setting the third parameter to FILE_SHARE_READ
Last error returns 1006. I would like to mention. When I get the file size. File size is being set to 0. File does exist and is filled with all my heightmap stuff.
One time, I was absolutely convinced that a file I was trying to read from was there when in reality I had actually moved it. When I forced the program to read from the file pointer, it shut the computer down hard, like someone had yanked the cord out of the wall. So, the moral of the story is, check your file path.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement