How to remove error of incompatible variable types in LoadLibrary() function?

570 views Asked by At

I have one line in my C++ program

HINSTANCE hInstLibrary = LoadLibrary("DLL_tut.dll");

Here I'm getting error saying that error C2664: 'LoadLibraryW' : cannot convert parameter 1 from 'const char [12]' to 'LPCWSTR'

I'm trying to implement program given in link http://www.codeguru.com/cpp/cpp/cpp_mfc/tutorials/article.php/c9855/DLL-Tutorial-For-Beginners.htm

Tried finding some solutions and found this one closest Incompatible var types I think, but I'm not understanding that how to covert that string of file, the last answer this question is more appropriate I guess. Can someone suggest how to remove this error ?

PS: not some homework, new to dlls and trying to understand by myself. stuck in this one last step.

1

There are 1 answers

3
No-Bugs Hare On BEST ANSWER

Try

HINSTANCE hInstLibrary = LoadLibrary(L"DLL_tut.dll");

or

HINSTANCE hInstLibrary = LoadLibrary(_TEXT("DLL_tut.dll"));

The thing is that your project is probably compiled with UNICODE macro defined, which causes LoadLibrary to use LoadLibraryW version, which requires Unicode string as a parameter.