Do it this way ommitting the OFN structure:
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("TokenFile(*.tkn)|*.tkn||"));
if(dlg.DoModal() == IDOK)
{
m_txtFileName.SetWindowText(dlg.GetFileName().GetString());
}
Your errors are:
lpstrFileTitle
is the buffer to receive the selected file name, not the title for the dialog.lpstrFilter
can be also passed using the constructor. Note that '|' is used to separate the string.lpstrFile
is the file name to initialize the edit control, not the buffer to receive it. It may be also passed using the constructor.- UPDATE: When using
GetBuffer()
with CString
, you must call ReleaseBuffer()
.