Click here to Skip to main content
15,313,725 members
Articles / Desktop Programming / WTL
Posted 29 Jun 2002


15 bookmarked

CStringW and CStringA

Rate me:
Please Sign up or sign in to vote.
4.69/5 (3 votes)
29 Jun 2002
CStringW and CStringA for WTL


After doing endless string programming I got sick of doing string conversion and so split CString into a UNICODE and ANSI version (CStringW and CStringA). I replicated the WTL string class and replaced the internal data representation from TCHAR to wchar_t for CStringW and char for CStringA, modifying all functions depending on the internal data representation.

The classes behave exactly like CString. Just include "StringA.h" and "StringW.h" like you include "atlmisc.h". Even _ATL_MIN_CRT is supported. It's the same like MFC 7.0 is doing it, which gave me the inspiration by the way.

If you want to see unicode strings while debugging, don't forget to switch on Tools/Options/Debug/Display unicode strings. Which is not enabled by default.

Additionally you shoud modify your Autoexp.dat file to see the content of CStringW and CStringA like you are used from CString.

Add these two lines into the section [AutoExpand]:

CStringW =<m_pchData,su>
CStringA =<m_pchData,s>


#include "StringA.h"
#include "StringW.h"

CStringW sTestW( L"Test" );
CStringA sTestA( "Test" );

// convert
CStringW sConvertW = sTestA;
CStringA sConvertA = sTestW;

I couldn't test all functions and probably some constructors are missing. If you find an error or have a suggestion please feel free and add a message to the discussion.

I hope you'll like and use it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Oskar Wieland
Web Developer
Germany Germany
No Biography provided

Comments and Discussions

GeneralATL7.1 in WinDDK Pin
mnjrupp7-Sep-10 8:05
Membermnjrupp7-Sep-10 8:05 
QuestionCompile Errors Pin
pscholl21-May-07 2:34
Memberpscholl21-May-07 2:34 
Questionhow to CStrinA Pin
see_u_shree19-Jan-07 20:47
Membersee_u_shree19-Jan-07 20:47 
AnswerRe: how to CStrinA Pin
vlad.gs4-Feb-07 21:20
Membervlad.gs4-Feb-07 21:20 
GeneralConvert CString to UNICODE Pin
kiranin1-Dec-06 20:31
Memberkiranin1-Dec-06 20:31 
AnswerRe: Convert CString to UNICODE Pin
Michał Zalewski19-Jan-07 22:41
MemberMichał Zalewski19-Jan-07 22:41 
QuestionHow to copy CString to CStringA Pin
dharani22-Nov-06 20:12
Memberdharani22-Nov-06 20:12 
GeneralTHANK YOU!!!!! Pin
ericb_summit10-Oct-05 6:03
Memberericb_summit10-Oct-05 6:03 
THANK YOU KIND SIR... I was having nightmares at the thought of enabling _UNICODE in my app and and patch oh, say, 25,000 lines of code only to have UTF-8 support for small things like labels.
GeneralCStringW Format Pin
David Smulders14-Jan-05 3:16
MemberDavid Smulders14-Jan-05 3:16 
GeneralROT COM Question Pin
Alois Kraus3-Jan-03 3:31
MemberAlois Kraus3-Jan-03 3:31 
GeneralConfused Pin
Rashid Thadha30-Jun-02 22:23
MemberRashid Thadha30-Jun-02 22:23 
GeneralRe: Confused Pin
Paul Selormey30-Jun-02 23:24
MemberPaul Selormey30-Jun-02 23:24 
GeneralRe: Confused Pin
_Magnus_1-Jul-02 3:25
Member_Magnus_1-Jul-02 3:25 
GeneralRe: Confused Pin
Mike Player1-Jul-02 3:42
MemberMike Player1-Jul-02 3:42 
GeneralRe: Confused Pin
_Magnus_1-Jul-02 5:17
Member_Magnus_1-Jul-02 5:17 
GeneralRe: Confused Pin
1-Jul-02 4:14
suss1-Jul-02 4:14 

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.