ChartDirector 6.0 (C++ Edition)

UTF8toTCHAR


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.

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

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

A typical usage is like:

obj->functionRequiringTCHAR(UTF8toTCHAR(aUTF8String));

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

MethodInheritedDescription
UTF8toTCHAR(Self)Constructs a UTF8toTCHAR object.
const_TCHAR_ptr(Self)Operator for implicit casting to TCHAR*.