Question

I'm trying to the CreateFileMapping() function (on windows).

Now, in this piece of code:

hFile = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 
hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, sizeInBlocks*SO_BLOCK_SIZE, filename);

The file is created allright, but the value of hFileMapping is NULL! Which is weird because I'm using hFile (which is a valid handle!) and when I check GetLastError() status after the call to CreateFileMApping() I'm getting ERROR_PATH_NOT_FOUND, which is weird, because another function just used it to create the file.

Any ideas?

Was it helpful?

Solution

Ok, been doing some digging (should've been beforehand, I know). The last parameter of CreateFileMapping() should be a string NOT containing backslashes. And I've used the filepath I've created as that parameter (to make it a unique name). So, the error returned was actually applying to that parameter and NOT to the file handle passed as the first parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top