Click here to Skip to main content
15,885,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

i was passing a vector of CString to a DLL and in the debug mode when i tried to look to the content of the vector all was asian caracters 桔敲e, but when i chenged the code to maske it as string they worked fine.

how could i be able using CString instead of string?

thanj you
Posted
Comments
Sergey Alexandrovich Kryukov 15-Jan-12 21:38pm    
Let me see: you think Asian characters are wrong? Which are "fine"? European? American? What kind? Why? :-)
--SA

CString uses either the ASCII character set or the UNICODE character set depending on whether the UNICODE pre-processor macro is defined.
Visual Studio defines UNICODE by default.
std::string on the other hand always uses the ASCII character set.
You can explicitly use CStringA to use the ASCII version.
Or you can undefine the UNICODE pre-processor from Visual Studio by changing the Character Set property -
Project -> Properties -> Configuration Properties -> General -> Character Set -> Not Set.
 
Share this answer
 
Comments
Schehaider_Aymen 16-Jan-12 2:58am    
Well done _Superman_ .. it works fine I had no idea about the CStringA class. You saved me alot of casting time ^^.
JackDingler 17-Jan-12 17:38pm    
You can also use std::wstring if you need unicode support,
use native char* with 0-termination your transmitting such strings.

Everything else will bring you sooner or later trouble
 
Share this answer
 
Comments
Stefan_Lang 16-Jan-12 8:13am    
I'm torn between up- and downvoting this:

Up because I hate proprietary types such as CString and wouldn't touch them with a 10 foot pole if I had the choice. And I prefer obvious types that have no hidden functionality or structure, when I'm unsure on how to manipulate them properly. (so I can at least always check the debugger to see if my algorithms do what I expect them to)

Down because it's not clear whether the OP actually has a choice. And because there already is a working solution. Also the asian chars imply these are wide char strings, so you should at least suggest wchar* ;-)
KarstenK 16-Jan-12 8:18am    
you are absolutly right ;-)
Albert Holguin 16-Jan-12 15:54pm    
I upvoted... when dealing with dll interfaces, it's best to keep things as simple as possible... +5
yes use char* , if you use std::string make sure you are using correct CRT runtime on both ends.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900