Search code examples
c++stringunicodecompiler-errorsc2664

VS2017 C++ compiler error C2664 can not convert argument


Using VS2017 I compile the code below using the unicode character set

STDMETHODIMP Load(LPCOLESTR lpwszFileName, const AM_MEDIA_TYPE *pmt) {
 TCHAR *szExtension = PathFindExtension(lpwszFileName);

and I get the following error

error C2664: 'LPSTR PathFindExtensionA(LPCSTR)': cannot convert argument 1 from 'LPCOLESTR' to 'LPCSTR'

The same code under VS2008 compiles just fine. What seems to be to problem here and why the compiler chooses the ANSI version of the PathFindExtenstion instead of the unicode one ?


Solution

  • The problem was that the VS2017 variable

    %(PreprocessorDefinitions)

    was missing from Preprocessor Definitions. Now the definers /D _UNICODE and /D UNICODE are added correctly to the compiler parameter's list.

    The missing the %(PreprocessorDefinitions)