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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CString problem

Status
Not open for further replies.

makaveliuk

Programmer
Dec 1, 2003
46
GB
I have been having this problem a lot and have figured out where it lies, When I create a CString and format information into it, it puts a null character after every character causing some functions to think the string is terminated after the first character.

Is there a way round this?
 
Sounds like you have UNICODE defined in some areas and not in others. Is this the case?

Matt
 
Yes, you're right, I am storing data in the registry which needs to be written by one application and read by another.

The one writing the data is set to MBCS, the other UNICODE, but when I change either project settings, I get the error:

error LNK2001: unresolved external symbol _WinMain@16

How do I get round that? And which should I use? MBCS or UNICODE? I usually write software on the mac which only uses unicode.
 
Ok... there is an easy solution. In the program that has UNICODE defined do the following

At the top #include <atlconv.h>

When you have the UNICODE string and need to write it somewhere:

SomeFunction()
{
USES_CONVERSION; // macro from atl
char* asciiBuffer = T2A(myCString);
// write asciiBuffer where you need to
}

The other solution is to use MultiByteToWide and vice versa. Either way will work, but the API calls for conversion need to know of the code page (i believe 1252 is english)

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top