Click here to Skip to main content
15,949,741 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Serial Comms TimeOut Formula Pin
louis30-Jun-03 3:26
louis30-Jun-03 3:26 
GeneralMFC Edit Ctrl Pin
frackasse30-Jun-03 2:24
frackasse30-Jun-03 2:24 
GeneralRe: MFC Edit Ctrl Pin
David Crow30-Jun-03 2:40
David Crow30-Jun-03 2:40 
GeneralRe: MFC Edit Ctrl Pin
frackasse30-Jun-03 3:04
frackasse30-Jun-03 3:04 
GeneralRe: MFC Edit Ctrl Pin
David Crow30-Jun-03 3:22
David Crow30-Jun-03 3:22 
General,Serial Comms TimeOut Formula Pin
louis30-Jun-03 2:23
louis30-Jun-03 2:23 
QuestionHow to covert CString to TCHAR and CString to LPCWSTR? Pin
julych30-Jun-03 1:26
julych30-Jun-03 1:26 
AnswerRe: How to covert CString to TCHAR and CString to LPCWSTR? Pin
RChin30-Jun-03 1:39
RChin30-Jun-03 1:39 
If you need to copy a CString object to an array of TCHAR you could do:
<font color="green">
// assume strText is your CString ...
</font>

TCHAR *czArray = NULL; 

<font color="green">// allocate character array</font>
czArray = new TCHAR[strText.GetLength() + 1]; 
_tcscpy(czArray, (LPCTSTR)strText);

<font color="green">// DO WHATEVERR

// Cleanup</font>
delete [] czArray;


The CString object has the LPCTSTR operator cast, so you can just cast your CString object to a LPCWSTR (LPCSTR if not unicode). Note that this is used in the above example for the _tcscpy function

For further reading, have a look at the strings section of Codeproject, there are a few good articles that is a must-read.




"..Even my comments have bugs!"

Inspired by Toni78

AnswerRe: How to covert CString to TCHAR and CString to LPCWSTR? Pin
Peter Weyzen30-Jun-03 8:45
Peter Weyzen30-Jun-03 8:45 
Generalpointer to the app Pin
andyg.10130-Jun-03 1:16
andyg.10130-Jun-03 1:16 
GeneralRe: pointer to the app Pin
RChin30-Jun-03 1:43
RChin30-Jun-03 1:43 
GeneralRe: pointer to the app Pin
andyg.10130-Jun-03 2:21
andyg.10130-Jun-03 2:21 
GeneralRe: pointer to the app Pin
David Crow30-Jun-03 2:43
David Crow30-Jun-03 2:43 
GeneralRe: pointer to the app Pin
RChin30-Jun-03 3:23
RChin30-Jun-03 3:23 
GeneralVisual Studio 6.0 Pin
Bernhard30-Jun-03 1:13
Bernhard30-Jun-03 1:13 
GeneralRe: Visual Studio 6.0 Pin
Ryan Binns30-Jun-03 2:27
Ryan Binns30-Jun-03 2:27 
GeneralGot problems with COptionTree Pin
mike :D30-Jun-03 0:16
mike :D30-Jun-03 0:16 
GeneralRe: Got problems with COptionTree Pin
Dominik Reichl30-Jun-03 0:41
Dominik Reichl30-Jun-03 0:41 
GeneralRe: Got problems with COptionTree Pin
mike :D30-Jun-03 2:00
mike :D30-Jun-03 2:00 
GeneralRe: Got problems with COptionTree Pin
mike :D30-Jun-03 4:01
mike :D30-Jun-03 4:01 
Generalabout disable or enable Network card Pin
BensonCHUANG30-Jun-03 0:06
BensonCHUANG30-Jun-03 0:06 
GeneralDisassembler for IBM PC (SoftIce) Pin
BhaskarBora29-Jun-03 23:45
BhaskarBora29-Jun-03 23:45 
GeneralRe: Disassembler for IBM PC (SoftIce) Pin
Dominik Reichl30-Jun-03 0:47
Dominik Reichl30-Jun-03 0:47 
GeneralRe: Disassembler for IBM PC (SoftIce) Pin
BhaskarBora30-Jun-03 2:49
BhaskarBora30-Jun-03 2:49 
GeneralCreateService() Hangs Pin
vlvl29-Jun-03 23:42
vlvl29-Jun-03 23:42 

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.