Click here to Skip to main content
15,887,267 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionTypedef struct help Pin
WebDev.ChrisG28-Jul-11 9:13
WebDev.ChrisG28-Jul-11 9:13 
AnswerRe: Typedef struct help Pin
Richard Andrew x6428-Jul-11 9:20
professionalRichard Andrew x6428-Jul-11 9:20 
GeneralRe: Typedef struct help Pin
WebDev.ChrisG28-Jul-11 9:23
WebDev.ChrisG28-Jul-11 9:23 
GeneralRe: Typedef struct help Pin
Richard Andrew x6428-Jul-11 9:25
professionalRichard Andrew x6428-Jul-11 9:25 
GeneralRe: Typedef struct help Pin
Albert Holguin28-Jul-11 9:43
professionalAlbert Holguin28-Jul-11 9:43 
GeneralRe: Typedef struct help Pin
Albert Holguin28-Jul-11 10:11
professionalAlbert Holguin28-Jul-11 10:11 
QuestionIs CString really based on TCHAR? Pin
Dean Seo27-Jul-11 20:50
Dean Seo27-Jul-11 20:50 
AnswerRe: Is CString really based on TCHAR? Pin
Rajesh R Subramanian27-Jul-11 21:05
professionalRajesh R Subramanian27-Jul-11 21:05 
Dean Seo wrote:
CString _str = TEXT("ABCD");
TCHAR* _tstr = _str;

That's not acceptable. _tstr is a pointer to a char (or wchar_t based on your build). But, _str is a CString variable and so, this conversion won't work.

Dean Seo wrote:
CString _str = TEXT("ABCD");
TCHAR* _tstr = (TCHAR*)(LPCTSTR)_str;

That's not a good thing to do either. LPCTSTR (with the added C in between means that it's a const). By explicitly casting it to a TCHAR*, you're casting the const away and then you are assigning it to a TCHAR* later.

Remember that CString is a C++ class. It uses a string (a char* or a wchar_t*) internally to store the contents, but it does a lot of other things as well. If you really need to acquire a pointer to the location where the class is storing the string, then there's this CString::GetBuffer()[^] method. There are some quirks associated with this method though, and you need to exercise caution while using it. If you call it, you want to make sure that you call CString::ReleaseBuffer()[^] immediately after you're done with the buffer. If you don't know what that means, you don't want to use that method.

I strongly recommend that you read the following essays:

The Complete Guide to C++ Strings, Part I - Win32 Character Encodings[^]

The Complete Guide to C++ Strings, Part II - String Wrapper Classes[^]

CString Management[^]
"Real men drive manual transmission" - Rajesh.

GeneralRe: Is CString really based on TCHAR? Pin
Dean Seo27-Jul-11 21:31
Dean Seo27-Jul-11 21:31 
AnswerRe: Is CString really based on TCHAR? Pin
Rajesh R Subramanian27-Jul-11 21:51
professionalRajesh R Subramanian27-Jul-11 21:51 
GeneralRe: Is CString really based on TCHAR? [modified] Pin
Dean Seo28-Jul-11 19:35
Dean Seo28-Jul-11 19:35 
AnswerRe: Is CString really based on TCHAR? Pin
Rajesh R Subramanian28-Jul-11 20:57
professionalRajesh R Subramanian28-Jul-11 20:57 
GeneralRe: Is CString really based on TCHAR? Pin
Rajesh R Subramanian29-Jul-11 8:16
professionalRajesh R Subramanian29-Jul-11 8:16 
GeneralRe: Is CString really based on TCHAR? Pin
Dean Seo30-Jul-11 20:43
Dean Seo30-Jul-11 20:43 
GeneralRe: Is CString really based on TCHAR? Pin
Rajesh R Subramanian30-Jul-11 22:44
professionalRajesh R Subramanian30-Jul-11 22:44 
Questionbasic C struct newbee question Pin
Member 811717127-Jul-11 9:01
Member 811717127-Jul-11 9:01 
GeneralRe: basic C struct newbee question Pin
David Crow27-Jul-11 10:14
David Crow27-Jul-11 10:14 
GeneralRe: basic C struct newbee question Pin
Member 811717127-Jul-11 10:38
Member 811717127-Jul-11 10:38 
GeneralRe: basic C struct newbee question Pin
David Crow27-Jul-11 10:52
David Crow27-Jul-11 10:52 
GeneralRe: basic C struct newbee question Pin
Albert Holguin27-Jul-11 12:09
professionalAlbert Holguin27-Jul-11 12:09 
GeneralRe: basic C struct newbee question Pin
Maximilien27-Jul-11 13:13
Maximilien27-Jul-11 13:13 
AnswerRe: basic C struct newbee question Pin
Maximilien27-Jul-11 10:21
Maximilien27-Jul-11 10:21 
AnswerRe: basic C struct newbee question Pin
Albert Holguin27-Jul-11 10:26
professionalAlbert Holguin27-Jul-11 10:26 
GeneralRe: basic C struct newbee question Pin
Member 811717127-Jul-11 10:34
Member 811717127-Jul-11 10:34 
GeneralRe: basic C struct newbee question Pin
Albert Holguin27-Jul-11 12:12
professionalAlbert Holguin27-Jul-11 12:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.