C2664 error c++ Visual Studio

6k Views Asked by At

I am trying to modify an old MFC program. After opening the project in Visual Studio 2013 there are many errors of the type below.

In AviPlay.cpp

#include "stdafx.h"
#include "AviPlay.h"

#define OPEN_AVI_VIDEO "open avivideo"
BOOL initAVI()
{
    return mciSendString(OPEN_AVI_VIDEO, NULL, 0, NULL) == 0;
}

The error thrown is error C2664: 'MCIERROR mciSendStringW(LPCWSTR,LPWSTR,UINT,HWND)' : cannot convert argument 1 from 'const char [14]' to 'LPCWSTR'

Should setting the compiler option for Strict to off, or some other compiler option, resolve this error? If not, I can modify the many lines of code manually. In that case, what might have changed in the last 15 years that would make code like this OK before but not OK now?

Thank you in advance.

2

There are 2 best solutions below

0
On

Also if you are creating a new project and facing this issue , then make the conformance mode to Default or No .

0
On

LPCWSTR tells you it is expecting a wchar_t string, not a char string. By default, all Windows APIs now accept wchar_t strings (unicode). You can change it back to char strings in the project properties, General page, Character Set. Setting it to 'Use Multibyte char set' will get it working as it used to.