Say I want to a generated a wrapper function to CreateFile function
This new function will not generate a real file on the disk but create file mapping object and return a handle to the new object.
I've looked at this example, Creating Named Shared Memory, and tried to implement my function:
#define BUF_SIZE 256
TCHAR szName[] = TEXT("Global\\MyFileMappingObject");
HANDLE MyCreateFile()
{
HANDLE hMapFile = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // maximum object size (high-order DWORD)
BUF_SIZE, // maximum object size (low-order DWORD)
szName); // name of mapping object
return hMapFile;
}
Problem
This looked OK to me, however, when tried using the returned HANDLE
in ReadFile function I got error code 6 The handle is invalid.
Question
Can file mapping object and file object be used interchangeably? If so, then what is the issue with my code? If not, any idea how can such function be implemented?