I am trying to write a few functions that write and load a map.
However, the function does not error under MSVC++, but after I run the write function, it creates the file but the size is 0 bytes.
int x,y;
HANDLE map;
char fp[10] = "World.map";
map=CreateFile(fp,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(WriteFile(map,(void *)x,sizeof(int),NULL,NULL))
{
}
if(WriteFile(map,(void *)y,sizeof(int),NULL,NULL))
{
}
CloseHandle(map);
-And to load the map:
void LoadMap()
{
HANDLE map;
char fp[10] = "World.map";
map=CreateFile(fp,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
ReadFile(map,(void *)mapSizeX, sizeof(int),NULL,NULL);
ReadFile(map,(void *)mapSizeZ, sizeof(int),NULL,NULL);
CloseHandle(map);
}
So in short it doesn't write to a file, just creates one...so there is nothing to read(but I am sure I screwed up on that part too.)
Any Ideas?
[edited by - CtrlAltDel on December 9, 2002 8:12:14 PM][edited by - CtrlAltDel on December 9, 2002 8:18:22 PM]
Make sure you close the file handle after you''ve written to it (via CloseHandle()). Otherwise the changes won''t be saved, so you''ll end up with a file 0 bytes in size...
FILE_SHARE_WRITE means other files can open it and write to it, while you are - use FILE_SHARE_READ or 0. I do not think this is the source of your problem though...
Check the handle value against INVALID_HANDLE_VALUE to see it is actually suceeds in creating the file.
You may have to supply a variable address for the second-to-last parameter of WriteFile. It the version of the docs I checked, it doesn''t say that NULL is an acceptable option - same with ReadFile.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform.
You can accept analytics or continue with necessary cookies only.
Learn more