Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting CString to const char* in UNICODE environment 1

Status
Not open for further replies.

titanandrews

Programmer
Feb 27, 2003
130
US
Hello All,
I have come to the conclusion that strings in C++ are a pain in the ass. Why can't they all be UNICODE? Why is there 50,000 string classes? [mad]
Ok, I'm over it now... Could someone please tell me how to convert a CString to a const char* in UNICODE environment? The following code:
Code:
int retValue = system(myCommand.GetBuffer(myCommand.GetLength()));
works fine in a non UNICODE environment, but in UNICODE enabled environment, I get this from C++ compiler:
Code:
error C2664: 'system' : cannot convert parameter 1 from 'unsigned short *' to 'const char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

I tried reinterpret_cast, but it just gives me garbage.


many thanks,

Barry
 
WideCharToMultiByte() can convert a Unicode string to a char * (Where you can specify the destination codepage).

Also wcstombs() can do the job.

Yes, there are a lot of string classes and functions for string manipulation ... and it is pretty confusing.
It's like going to the supermarket to buy soup : If you don't know anything about soup you are lost. You will have to read all the text on the packages, decide for one, bring it home to your lab and test it ... Much easier if only tomato soup was available ;-)

/JOlesen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top