passing in ascii/unicode strings to LoadLibrary

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Dec 2006
Posts: 36
Reputation: unclepauly is an unknown quantity at this point 
Solved Threads: 0
unclepauly unclepauly is offline Offline
Light Poster

passing in ascii/unicode strings to LoadLibrary

 
0
  #1
Jun 23rd, 2007
hi,

i have this code:


HINSTANCE hComponent = ::LoadLibrary("Component1.dll");


i get this compile error:

Error 1 error C2664: 'LoadLibraryW' : cannot convert parameter 1 from 'const char [15]' to 'LPCWSTR' c:\Documents and Settings\Administrator\Desktop\Component1\Client1\Client1.cpp 9

so i changed the code:


HINSTANCE hComponent = ::LoadLibrary((LPCWSTR)"Component1.dll");


however GetLastError returns ERROR_MODULE_NOT_FOUND. the dll IS in the exe directory though, so its not the location that is the problem. in addition, if i call LoadLibraryA, the function loads the library successfully.

so why is LoadLibrary((LPCWSTR)"Component1.dll"); failing?

thanks!
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: passing in ascii/unicode strings to LoadLibrary

 
0
  #2
Jun 23rd, 2007
Use the conversion macros (for ASCII/UNICODE compatibility), not indiscriminate casting to make the compiler STFU.


::LoadLibrary( TEXT("Component1.dll") );


Just because you managed to silence your compiler is in no way a measure of run-time success.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 36
Reputation: unclepauly is an unknown quantity at this point 
Solved Threads: 0
unclepauly unclepauly is offline Offline
Light Poster

Re: passing in ascii/unicode strings to LoadLibrary

 
0
  #3
Jun 23rd, 2007
thats great thank you.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 2718 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC