Problems implementing CFileDialog

I follow the definition for CFileDialog, but VS2013 still tells me that there is no constructor for the arguments I pass.

My code is:

CFile theFile;
char strFilter[] = { "TXT Files (*.txt)|*.txt|All Files (*.*)|*.*||" };
CFileDialog fDlg = CFileDialog(TRUE, ".txt", NULL, 0, strFilter);

Resulting error:

1 IntelliSense: no constructor instance "CFileDialog :: CFileDialog" corresponds to the argument list Argument types: (int, const char [5], int, int, char [46]) c: \ Users \ Jonathan \ Documents \ Visual Studio 2013 \ Projects \ SDI \ SDI \ MainFrm.cpp 131 21 SDI

And the constructor CFileDialogfor the link:

explicit CFileDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
    LPCTSTR lpszDefExt = NULL,
    LPCTSTR lpszFileName = NULL,
    DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
    LPCTSTR lpszFilter = NULL,
    CWnd* pParentWnd = NULL,
    DWORD dwSize = 0,
    BOOL bVistaStyle = TRUE);

What is the problem?

+4
source share
2 answers

The problem is that you are using the wrong string type.

- TCHAR, char. - , Unicode.

Visual Studio, Unicode, MBCS, "Not Set". , Windows API MFC, , . , char, char *, const char*, Windows API, , .

, Unicode MBCS, , , , LPCTSTR - const char *, , , a TCHAR. , , .

, , , , , , , .

+4

Ok. :

CFile theFile;
TCHAR strFilter[] = { _T("TXT Files (*.txt)|*.txt|All Files (*.*)|*.*||") };
CFileDialog fDlg = CFileDialog(TRUE, _T(".txt"), NULL, 0, strFilter);

. !

+1

All Articles