## Recommended Posts

##### Share on other sites
Quote:
 Original post by ForgottenMasterI have not been able to get this to work as LoadLibrary keeps failing with error code 126....after looking this up, it seems to mean that a dependency is missing.
Error 126 actually means "The specified module could not be found. "

Quote:
 Original post by ForgottenMaster// load the libraryHINSTANCE hinst = LoadLibrary( LPCWSTR( "TestDLL.dll" ) );
Read This. You can't do that any more than you can do:
float f = 123.456;LPCWSTR s = LPCWSTR(f);

##### Share on other sites
Quote:
 Original post by Evil SteveYou can't do that any more than you can do:

<nitpick>Bad phrasing here. Since his code will compile and your example won't, he can, in fact, do that more than you could do a floating point to pointer cast. :)</nitpick>

##### Share on other sites
Thanks a lot!, that's sorted it :)

##### Share on other sites
Quote:
Original post by SiCrane
Quote:
 Original post by Evil SteveYou can't do that any more than you can do:

<nitpick>Bad phrasing here. Since his code will compile and your example won't, he can, in fact, do that more than you could do a floating point to pointer cast. :)</nitpick>
Ah yes - somewhere in my brain I thought that'd compile, obviously not. Ok, pretend f is a pointer to a float then [smile]

##### Share on other sites
Quote:
 Original post by ForgottenMaster HINSTANCE hinst = LoadLibrary( LPCWSTR( "TestDLL.dll" ) );

A typical approach to dealing with string literals is to wrap them in the TEXT macro.

HINSTANCE hinst = LoadLibrary( TEXT( "TestDLL.dll" ) );

When compiling with UNICODE defined, the TEXT macro prefixes an "L" to the string, which tells the compiler to treat the string as UNICODE. When compiling with UNICODE not defined, the TEXT macro leaves the string as is, so the compiler treats the string as ANSI. The TEXT macro is defined in winnt.h, which should automatically be included in your project when windows.h is included.

One thing to note. LoadLibrary is usually used in conjunction with GetProcAddress, which expects an ANSI string argument. So don't wrap that argument with TEXT.