I\'m following the definition for CFileDialog
, yet VS2013 is still telling me that there is no constructor available for the arguments that I\'m passing in.
The issue seems to be that you're using the incorrect string type.
The quick solution is to use TCHAR
and not char
. The better solution is to just use wide strings and make sure the build is Unicode.
When you create a project in Visual Studio, the default character set type that is used is Unicode, not MBCS and not "Not Set". This means that Windows API and MFC functions that take character arrays and pointers will be using wide characters. Therefore using char
, char *
, const char*
, on Windows API functions that expect wide strings will not compile.
The indication that your code is wrong, even if you knew nothing about Unicode or MBCS, is that the functions you're calling take types of LPCTSTR
-- that is not a const char *
, it is what it is, namely a constant pointer to a TCHAR
. If you stuck with knowing to use the types specified, you would have been good to go.
So the lesson is that if a function wants a type, provide a variable or expression of that type, not what you think the type is equivalent to.
Ok. So I've changed my code to the following:
CFile theFile;
TCHAR strFilter[] = { _T("TXT Files (*.txt)|*.txt|All Files (*.*)|*.*||") };
CFileDialog fDlg = CFileDialog(TRUE, _T(".txt"), NULL, 0, strFilter);
And, there are now no problems. Thank you for your responses!