I have a VS project which is compiled using the unicode character set.
I load a dll using LoadLibrary and that dll is also built using the unicode character set.
I use a method exposed by the dll which returns me a std::string.

I am having some trouble with converting this std::string to TCHAR* (which is passed an an argument to some other function). The c_str() method of std::string returns a const char* and I used mbstowcs_s to convert this const char* to TCHAR*. The compilation works fine(using VC8 compiler) but during run time I see some illegal characters instead of the strings which I expected.
What I am suspecting is that the dll which I load, has been compiled using the unicode character set but it still uses std::string instead of std::wstring.std::string is by default narrow and when I try to convert them using mbstowcs_s, I am getting these illegal characters. Can someone please correct me if I am wrong.

I load another dll in my project which also returns me a string but is compiled using the multi-byte character set and there the mbstowcs_s gives me a proper TCHAR*.

Has anyone any suggestions? I fear I am doing some very elementary mistake.

I have a VS project which is compiled using the unicode character set.
I load a dll using LoadLibrary and that dll is also built using the unicode character set.
I use a method exposed by the dll which returns me a std::string.

I am having some trouble with converting this std::string to TCHAR* (which is passed an an argument to some other function). The c_str() method of std::string returns a const char* and I used mbstowcs_s to convert this const char* to TCHAR*. The compilation works fine(using VC8 compiler) but during run time I see some illegal characters instead of the strings which I expected.
What I am suspecting is that the dll which I load, has been compiled using the unicode character set but it still uses std::string instead of std::wstring.std::string is by default narrow and when I try to convert them using mbstowcs_s, I am getting these illegal characters. Can someone please correct me if I am wrong.

I load another dll in my project which also returns me a string but is compiled using the multi-byte character set and there the mbstowcs_s gives me a proper TCHAR*.

Has anyone any suggestions? I fear I am doing some very elementary mistake.

Never mind. I got the person who wrote the library to use multi-byte character set. No issue now!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.