CFileDialog strange GetFileName
-
I have following code:
CFileDialog fileDlg(TRUE, \_T("\*"), NULL, OFN\_PATHMUSTEXIST | OFN\_OVERWRITEPROMPT, \_T("All files (\*.\*)|\*.\*||"), NULL); if(IDOK == fileDlg.DoModal()) TRACE(">>>%s\\n", fileDlg.GetFileName());
and when I select a file, no mater what kind of file, I get:
>>>D
that is all ... why ? What I have done wrong here ?
-
I have following code:
CFileDialog fileDlg(TRUE, \_T("\*"), NULL, OFN\_PATHMUSTEXIST | OFN\_OVERWRITEPROMPT, \_T("All files (\*.\*)|\*.\*||"), NULL); if(IDOK == fileDlg.DoModal()) TRACE(">>>%s\\n", fileDlg.GetFileName());
and when I select a file, no mater what kind of file, I get:
>>>D
that is all ... why ? What I have done wrong here ?
You are passing an ANSI string to the
TRACE
macro. Therefore, an ANSI string is expected for the%s
parameter but you have a Unicode build andfileDlg.GetFileName()
returns a wide string. So you should use the_T()
macro also for theTRACE
argument:TRACE(_T(">>>%s\n"), fileDlg.GetFileName());
See also the examples at MFC Debugging Techniques[^].
-
You are passing an ANSI string to the
TRACE
macro. Therefore, an ANSI string is expected for the%s
parameter but you have a Unicode build andfileDlg.GetFileName()
returns a wide string. So you should use the_T()
macro also for theTRACE
argument:TRACE(_T(">>>%s\n"), fileDlg.GetFileName());
See also the examples at MFC Debugging Techniques[^].