Problems with CFileDialog instantiation

前端 未结 2 2105
感动是毒
感动是毒 2021-01-13 22:44

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.

2条回答
  •  走了就别回头了
    2021-01-13 23:17

    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.

提交回复
热议问题