-
How to solve this error
Dear Experts,
i want to load a dll into my program and want to get the funcptr for some function while trying to do i am getting this error can you please tell me how to solve this i am using VS2005
Code:
error C2664: 'LoadLibraryW' : cannot convert parameter 1 from 'const char [71]' to 'LPCWSTR'
if i do type casting to LPCWSTR the error goes away but the dll does not load properly.
please tell me what is the reason.
-
You have set your project to use UNICODE or you are using the unicode version of LoadLibrary intentionally. Either pass a UNICODE string to the function or use the Ansi version of the function.
Code:
// ANSI version
HMODULE hModule = LoadLibraryA( "test.dll" );
Code:
//UNICODE version
HMODULE hModule = LoadLibraryW( L"test.dll" );
Code:
// Compile time flag version, will compile as UNICODE or ANSI depending on project settings
HMODULE hModule = LoadLibrary( _T("test.dll") );
-
Thanks for the reply,
can you please tell me which is the setting for unicode character to be done,
is it at the general->character set , there we have to select the setting,
can you please explain .
-
You can turn Unicode off in your Project Settings.
But you may not want to do this. Unless you have a good reason, you should use Unicode; that's why it's enabled by default. Just use the _T macro as nvoigt explained and you'll do fine.