The
CFileDialog
will not create files or directories. It is a dialog to select files for opening or saving and returns the selected names. It is up to you to create the file from that path name if it does not exist yet.
There is also no need to pass a buffer in the
OPENFILENAME
structure because when not allowing multiple selections.
Then just use the
CFileDialog
GetPathName()
member function to retrieve the full name:
CFileDialog dlgFileDlg (TRUE, "xml", fileName.GetString(),
OFN_CREATEPROMPT, L"XML\0*.xml\0All\0*.*\0", this);
if ( dlgFile.DoModal () == IDOK )
{
CString m_strPathname = dlgFile.GetPathName();
}
When using
OFN_ALLOWMULTISELECT
set the buffer as done in your code. Then the returned string contains the
NULL
terminated directory name followed by also
NULL
terminated file names finally terminated by another
NULL
character. Maybe that is what you have observed.
But you can still use
CFileDialog
members to get the names within a loop:
if ( dlgFile.DoModal () == IDOK )
{
POSITION pos = dlgFile.GetStartPosition();
while (pos)
{
CString m_strPathname = dlgFile.GetNextPathName(pos);
}
}