Click here to Skip to main content
15,888,610 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCString to TCHAR & TCHAR to CString Pin
Paulraj G6-Nov-07 20:29
Paulraj G6-Nov-07 20:29 
AnswerRe: CString to TCHAR & TCHAR to CString Pin
Cedric Moonen6-Nov-07 20:43
Cedric Moonen6-Nov-07 20:43 
GeneralRe: CString to TCHAR & TCHAR to CString Pin
Paulraj G6-Nov-07 20:59
Paulraj G6-Nov-07 20:59 
GeneralRe: CString to TCHAR & TCHAR to CString Pin
Cedric Moonen6-Nov-07 21:05
Cedric Moonen6-Nov-07 21:05 
GeneralRe: CString to TCHAR & TCHAR to CString Pin
CPallini6-Nov-07 21:14
mveCPallini6-Nov-07 21:14 
AnswerRe: CString to TCHAR; TCHAR to CString [incorrect] [modified] Pin
Llasus6-Nov-07 21:06
Llasus6-Nov-07 21:06 
GeneralHonestly Pin
CPallini6-Nov-07 21:28
mveCPallini6-Nov-07 21:28 
GeneralRe: CString to TCHAR & TCHAR to CString Pin
Cedric Moonen6-Nov-07 21:34
Cedric Moonen6-Nov-07 21:34 
Llasus wrote:
int temp = message.GetLength()*2; //multiply by 2 because of the CString format


Why multiply by 2 ? How do you know that a character is 2 bytes long ? It's only the case when UNICODE is enabled.


Llasus wrote:
tchar =(TCHAR*)malloc(temp+1); //add 1 for the NULL at the end: but doesn't work


Don't use malloc in C++. If you had used new, you won't have any problem with calculating the size. You just create an array of TCHAR and the compiler will allocate the correct size depending of UNICODE is set or not.

Llasus wrote:
memcpy(tchar, message, temp); //copy; now we have the TCHAR


Don't use memcpy to copy strings. Prefer to use the macro _tcscpy that will be strcpy if UNICODE is not declared or wscpy if UNICODE is declared (so you don't have to bother about it).

If you have garbage values at the end of your string, it's simply because you didn't put a ending zero at the end of your string.


Cédric Moonen
Software developer

Charting control [v1.2]

GeneralRe: CString to TCHAR & TCHAR to CString Pin
Raj Prathap7-Nov-07 0:09
Raj Prathap7-Nov-07 0:09 
GeneralRe: CString to TCHAR & TCHAR to CString Pin
toxcct7-Nov-07 0:30
toxcct7-Nov-07 0:30 
AnswerRe: CString to TCHAR & TCHAR to CString Pin
toxcct7-Nov-07 0:28
toxcct7-Nov-07 0:28 
QuestionWEB SERVER IN VC++ [modified] Pin
kansagous6-Nov-07 19:33
kansagous6-Nov-07 19:33 
AnswerRe: WEB SERVER IN VC++ Pin
shpid3r8-Nov-07 10:14
shpid3r8-Nov-07 10:14 
QuestionHollow Brush Pin
nitin36-Nov-07 19:24
nitin36-Nov-07 19:24 
AnswerRe: Hollow Brush Pin
Neo Andreson6-Nov-07 21:36
Neo Andreson6-Nov-07 21:36 
GeneralRe: Hollow Brush Pin
nitin36-Nov-07 22:08
nitin36-Nov-07 22:08 
GeneralRe: Hollow Brush [modified] Pin
Neo Andreson6-Nov-07 22:28
Neo Andreson6-Nov-07 22:28 
AnswerRe: Hollow Brush Pin
Mark Salsbery7-Nov-07 7:54
Mark Salsbery7-Nov-07 7:54 
Questionmenu on a button click event Pin
neha.agarwal276-Nov-07 17:55
neha.agarwal276-Nov-07 17:55 
QuestionRe: menu on a button click event Pin
Hamid_RT6-Nov-07 18:55
Hamid_RT6-Nov-07 18:55 
AnswerRe: menu on a button click event Pin
Prasann Mayekar6-Nov-07 21:45
Prasann Mayekar6-Nov-07 21:45 
Questionhow can i set message map for dynamic created CEdit [modified] Pin
mwolf1226-Nov-07 16:46
mwolf1226-Nov-07 16:46 
AnswerRe: how can i set message map for dynamic created CEdit Pin
Hamid_RT6-Nov-07 18:57
Hamid_RT6-Nov-07 18:57 
QuestionRe: how can i set message map for dynamic created CEdit Pin
fantasy12156-Nov-07 22:22
fantasy12156-Nov-07 22:22 
AnswerRe: how can i set message map for dynamic created CEdit Pin
mwolf1227-Nov-07 14:04
mwolf1227-Nov-07 14:04 

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.