See
/Zc:wchar_t (wchar_t Is Native Type)[
^]:
Quote:
If you upgrade from earlier versions of Visual C++ and encounter compiler error C2664 because the code is trying to implicitly convert a wchar_t to unsigned short, we recommend that you change the code to fix the error, instead of setting /Zc:wchar_t-.
There may be one solution but I'm not sure if it works (just give it a try):
Change the parameter types in the function declarations (e.g. by editing the library header file) to
__wchar_t
(resp.
*__wchar_t
and
const *__wchar_t
) and cast the parameters when calling the functions:
int Connect(__wchar_t *str);
wchar_t lpParam[] = L"test";
BluetoothClient::Connect((__wchar_t *)lpParam);
[UPDATE]
After the solution has been verified as working, I will explain what is done here.
Depending on the compiler setting,
wchar_t
is defined as
unsigned short
or the built-in type
__wchar_t
.
Because the library has been build using the built-in type, the function declaration must use that type to make the linker happy. When the application is build with the same setting,
LPWSTR
will be
__wchar_t *
as required. Otherwise
LPWSTR
will be
unsigned short *
which leads to the linker error. So changing the function declaration to use the correct type
__wchar_t *
avoids the linker error.
But when doing so the compiler would complain about passing a
LPWSTR
argument (which is
unsigned short *
) where a
__wchar_t *
is expected. This is solved by casting the parameter to the required type.
[/UPDATE]