ChartDirector 7.1 (C++ Edition)

TCHARtoUTF8


ChartDirector always uses UTF8 strings in its API. MFC, however, uses TCHAR strings, which can be MBCS strings or 2-byte UNICODE strings, depending on the project configuration. Sometimes it may be necessary to convert from one type of string to another.

TCHARtoUTF8 is a utility class to convert from TCHAR strings to UTF8 strings. A related utility class UTF8toTCHAR converts UTF8 strings to TCHAR strings. To use TCHARtoUTF8, please include the header file "ChartViewer.h" in the code.

TCHARtoUTF8 has a constructor that accepts a TCHAR string, and an implicit type casting operator to cast to const char *. Thus it can be used like a function that accepts a TCHAR string as input and returns a UTF8 string as output. Note that the memory required for the output is from the TCHARtoUTF8 object, so it must be used before the object is destroyed.

A typical usage is like:

obj->functionRequiringUTF8(TCHARtoUTF8(aTCHARString));

In the above, the TCHARtoUTF8 object is destroyed after the function returns, so the converted UTF8 string is valid for the lifetime of the function call.

MethodInheritedDescription
TCHARtoUTF8(Self)Constructs a TCHARtoUTF8 object.
const_char_ptr(Self)Operator for implicit casting to const char*.