Archived

This topic is now archived and is closed to further replies.

Jaggy

filenames with GetOpenFileName

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites