jump Index ScientificPsychic.com
Scientific Psychic Expand your mind

2010-03-28
 

Error C2664 LoadLibraryW cannot convert parameter to LPCWSTR



I recently used Microsoft Visual Studio 2008 to write a simple program to load a dynamic link library (DLL) module and invoke some of its entry points. I did not expect to get the error message C2664 from the simple LoadLibrary statement:

HINSTANCE hinstLib = LoadLibrary("azspellaid.dll");

Error C2664: 'LoadLibraryW': cannot convert parameter 1 from 'const char [15]' to 'LPCWSTR'


There are two ways of fixing this problem. The first one is to cast the quoted string with a Long Pointer to Const Wide String (LPCWSTR):

HINSTANCE hinstLib = LoadLibrary((LPCWSTR)L"azspellaid.dll");


The C2664 error can also be resolved by keeping the original code and changing the character set of the project defaults from "unicode character set" to "multi-byte character set" as shown in this image:




© Copyright  - Antonio Zamora