Jump to content
  • Advertisement
Sign in to follow this  
Kranar

Converting to LPCTSTR from a plain C-String

This topic is 4330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am writing a program in plain C, not C++, but I need to call LoadLibrary to load a DLL. It's really frustrating since LoadLibrary expects an LPCTSTR and will fail when given a plain const char*. The code is basically the following: HINSTANCE hlib = LoadLibrary(libpath); // libpath is a const char* Now libpath must remain a const char*, I do not have control over it. How can I convert it to an LPCTSTR though? The code must remain C, can't use any C++ for this. Thank you.

Share this post


Link to post
Share on other sites
Advertisement
An LPCTSTR is either a const char* or a const wchar * depending on if you build with UNICODE defined or not.

If your building as multi byte then you should be fine. As long as you pass it a const char* then your good. I guess it would also take a char *. If your building as UNICODE then pass it a const wchar *.

Cheers
Chris

Share this post


Link to post
Share on other sites
Personally, I'd force it to use the non-unicode version; LoadLibraryA():
HINSTANCE hlib = LoadLibraryA(libpath); // libpath is a const char*

But ideally you should expect a LPCTSTR rather than a LPCSTR

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!