CW2AEX Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

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

This class is used by the string conversion macros CT2AEX, CW2TEX, CW2CTEX, and CT2CAEX, and the typedef CW2A.

Important

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

Syntax

template<int t_nBufferLength = 128>  
class CW2AEX

Parameters

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

Members

Public Constructors

Name Description
CW2AEX::CW2AEX The constructor.
CW2AEX::~CW2AEX The destructor.

Public Operators

Name Description
CW2AEX::operator LPSTR Conversion operator.

Public Data Members

Name Description
CW2AEX::m_psz The data member that stores the source string.
CW2AEX::m_szBuffer The static buffer, used to store the converted string.

Remarks

Unless extra functionality is required, use CT2AEX, CW2TEX, CW2CTEX, CT2CAEX, or CW2A 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. If you want to override that behavior for a specific conversion, specify the code page as the second parameter to the constructor for the class.

The following macros are based on this class:

  • CT2AEX

  • CW2TEX

  • CW2CTEX

  • CT2CAEX

The following typedef is based on this class:

  • CW2A

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

Example

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

Requirements

Header: atlconv.h

CW2AEX::CW2AEX

The constructor.

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

Parameters

psz
The text string to be converted.

nCodePage
The code page used to perform the conversion. See the code page parameter discussion for the Windows SDK function MultiByteToWideChar for more details.

Remarks

Allocates the buffer used in the translation process.

CW2AEX::~CW2AEX

The destructor.

~CW2AEX() throw();

Remarks

Frees the allocated buffer.

CW2AEX::m_psz

The data member that stores the source string.

LPSTR m_psz;

CW2AEX::m_szBuffer

The static buffer, used to store the converted string.

char m_szBuffer[ t_nBufferLength];

CW2AEX::operator LPSTR

Conversion operator.

operator LPSTR() const throw();

Return Value

Returns the text string as type LPSTR.

See Also

CA2AEX Class
CA2CAEX Class
CA2WEX Class
CW2CWEX Class
CW2WEX Class
Class Overview