Advertisement

Quick GetOpenFileName() Question...

Started by November 11, 2000 08:21 PM
0 comments, last by DisKordCoder 24 years, 1 month ago
I need to put the filename output buffer from a GetOpenFileName() function into a file.open() fstream function. I have my buffer named as FileBuff and it holds the data, but its in a wierd type that cannot be put into the open() fucntion as that accepts a Char pointer. Anyone?
Alright when you created the OPENFILENAME structure you supplied it with a char* or char[] variable to hold the path and filename of the file that gets opened by the dialog. It was the lpStrFile member. After you call GetOpenFileName( &ofn ); Where ofn is your instance of the OPENFILENAME struct, you need to open the file like you would any other file but pass is the char string variable that was used in the lpStrFile member.

char* lpstrMyFile;
OPENFILENAME ofn;

ofn.lpStrFile = lpstrMyFile;

GetOpenFileName( &ofn );

file.open( lpstrMyFile );

Just like that. But of course as you know, ofn needs to be filled in with more data then just that one. Also if you fill in the OPENFILENAME struct the other way, then you need to put the lpstrMyFile variable in the 8th position. For ex,

    OPENFILENAME ofn = { sizeof(OPENFILENAME),	// lStructSizehWnd,			// hwndOwnerNULL,			// hInstancestrFilter,		// lpstrFilterNULL,			// lpstrCustomFilter0,			// nMaxCustomFilter1,			// nFilterIndexlpstrMyFile,		// lpstrFile (HERE!!!!!!!!!!!!!)MAX_FILENAME,		// nMaxFileNULL,			// lpstrFileTitleMAX_FILENAME,		// nMaxFileTitle"C:\\",	                // lpstrInitialDir"Open File",		// lpstrTitleOFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,		// Flags0,			// nFileOffset1,			// nFileExtension"*.txt",		//lpstrDefEx0,			// lCustDataNULL,			// lpfnHookNULL			// lpTemplateName};  


-Snyper

Edited by - Snyper on November 12, 2000 1:34:15 AM

Edited by - Snyper on November 12, 2000 1:35:12 AM
=============================Where's the 'any' key?=============================

This topic is closed to new replies.

Advertisement