CW2WEX Class


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on

The latest version of this topic can be found at CW2WEX Class.

This class is used by the string conversion macros CW2TEX and CT2WEX, and the typedef CW2W.

System_CAPS_ICON_important.jpg Important

This class and its members cannot be used in applications that execute in the Windows Runtime.

template <int t_nBufferLength = 128>  
class CW2WEX


The size of the buffer used in the translation process. The default length is 128 bytes.

Public Constructors

CW2WEX::CW2WEXThe constructor.
CW2WEX::~CW2WEXThe destructor.

Public Operators

CW2WEX::operator LPWSTRConversion operator.

Public Data Members

CW2WEX::m_pszThe data member that stores the source string.
CW2WEX::m_szBufferThe static buffer, used to store the converted string.

Unless extra functionality is required, use CW2TEX, CT2WEX, or CW2W in your code.

This class contains a fixed-size static buffer which is used to store the result of the conversion. If the result is too large to fit into the static buffer, the class allocates memory using malloc, freeing the memory when the object goes out of scope. This ensures that, unlike text conversion macros available in previous versions of ATL, this class is safe to use in loops and that it won't overflow the stack.

If the class tries to allocate memory on the heap and fails, it will call AtlThrow with an argument of E_OUTOFMEMORY.

By default, the ATL conversion classes and macros use the current thread's ANSI code page for the conversion.

The following macros are based on this class:

  • CW2TEX

  • CT2WEX

The following typedef is based on this class:

  • CW2W

For a discussion of these text conversion macros, see ATL and MFC String Conversion Macros.

See ATL and MFC String Conversion Macros for an example of using these string conversion macros.

Header: atlconv.h

The constructor.

CW2WEX(LPCWSTR psz, UINT nCodePage) throw(...);
CW2WEX( LPCWSTR  psz) throw(...);


The text string to be converted.

The code page. Not used in this class.


Creates the buffer required for the translation.

The destructor..

~CW2WEX() throw();


Frees the allocated buffer.

The data member that stores the source string.

LPWSTR m_psz;

The static buffer, used to store the converted string.

wchar_t m_szBuffer[t_nBufferLength];

Cast operator.

operator LPWSTR() const throw();

Return Value

Returns the text string as type LPWSTR.

CA2AEX Class
CA2WEX Class
CW2AEX Class
Class Overview