MeLight
MeLight

Reputation: 5575

Cannot create file mapping for a file I just opened, get "path not found"

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?

Upvotes: 0

Views: 3308

Answers (1)

MeLight
MeLight

Reputation: 5575

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.

Upvotes: 1

Related Questions