filenames with GetOpenFileName

Started by
2 comments, last by Jaggy 19 years, 12 months ago
Hey, me again. The MSDN library is crap, give me an example damnit...I don''t know how it justifies it''s 4gig installation or whatever it is... This is part of my code:

...
if ( GetSaveFileName( &openFile ) == TRUE )
{
   Game->saveLevel(openFile.lpstrFile);
}
which, hopefully passes the name of the file to my saveLevel function in game:

void cGameWorld::saveLevel(char* levNam)
{
	fstream File;

	File.open(levNam, ios::out | ios::binary);
...
Except it doesn''t. I ran it through the debugger and I''m getting access violations, and openFile.lpstrFile is actually NULL. So where is the filename the user types in actually stored? And if it is in lpstrFile, what kind of format?
Advertisement
GetOpenFileName() doesn''t allocate memory for the file name, you need to do that yourself before calling GetOpenFileName(). Allocate a buffer and assign it to the lpstrFile member before you open the dialog.
Technically, the return value from GetSaveFileName might not be "TRUE", but is specified to be "nonzero".

Yes, lpstrFile should contain the full path of the filename, if the return value is nonzero. I haven't used it in a while, but I think you need to point lpstrFile to already allocated memory (e.g. openFile.lpstrFile = myFileBuffer; ) and set nMaxFile to the size of your buffer before calling GetSaveFileName, so there's actually somewhere for it to store it.

[edited by - BriTeg on April 22, 2004 10:33:01 AM]
Brianmiserere nostri Domine miserere nostri

It works!

My first ever level editor, thanks to you both

This topic is closed to new replies.

Advertisement