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

C / C++ / MFC

 
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 
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 
Dean Seo wrote:
By the way, in that case, the thing is that that code doesn't even comfile and it occurs an 'casting failed' error.

I overlooked it to assume that you did a double casting to take the const away. That is a common thing (a terrible thing, actually) that people do:
CString _str = TEXT("ABCD");
TCHAR* _tstr = (LPTSTR)(LPCTSTR)_str; //Using the LPCTSTR operator to get the pointer, and then casting the const away. A bad thing to do.



Dean Seo wrote:
wchar_t* _WideCharacter = (wchar_t*)(const wchar_t*)aaa // works!

You shouldn't say "works!". You should instead say "it compiles!". Yeah, it will compile. But it's a terrible thing to do. How about this instead?
A aaa;
const wchar_t* p = aaa;


There are several APIs (and functions that we may code) that will need a read-only string. For example, you may write a function that takes the path of a file and encrypts it. So, you'll just be accepting the string which will be the path, and you'll not be modifying the string itself. In cases like that (and in MOST cases), you will only need a read-only string. That's why CString gives you a LPCTSTR (const wchar_t*), which will be pointing to the internal buffer where CString is storing the string.

But there are those edge cases where might want to have direct write access to the internal buffer of CString. For such cases, CString provides the GetBuffer() method (which I already explained).

Conclusively, there is no excuse for abusing the LPCTSTR operator (using it to cast the const away and assigning it to a non-const variable is bad).
"Real men drive manual transmission" - Rajesh.

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 
AnswerRe: basic C struct newbee question Pin
«_Superman_»27-Jul-11 10:59
professional«_Superman_»27-Jul-11 10:59 
QuestionHow to Validate User's Password Pin
rick222227-Jul-11 7:53
rick222227-Jul-11 7:53 
AnswerRe: How to Validate User's Password Pin
Rajesh R Subramanian27-Jul-11 8:09
professionalRajesh R Subramanian27-Jul-11 8:09 
GeneralRe: How to Validate User's Password Pin
rick222230-Jul-11 4:46
rick222230-Jul-11 4:46 

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.