头文件:#include <charconv.h>
库:charconv.lib
CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC();
TBool chineseLanguageSupported = EFalse;
if( converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGbk,
iEikonEnv->FsSession()) == CCnvCharacterSetConverter::EAvailable )
{
chineseLanguageSupported = ETrue;
}
else if ( converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGb2312,
iEikonEnv->FsSession() ) == CCnvCharacterSetConverter::EAvailable )
{
chineseLanguageSupported = ETrue;
}
HBufC* iInfoText;
// The following string is "Nokia" in simplified Chinese
TText8 *str = (TText8*)"这是一个最好的时代!";
TInt state=CCnvCharacterSetConverter::KStateDefault;
TPtrC8 source( str );
iInfoText = HBufC::NewL( source.Length() );
TPtr16 ptr = iInfoText->Des();
if( chineseLanguageSupported )
{
TRAP_IGNORE( converter->ConvertToUnicode( ptr, source, state ) )
}
gc.UseFont(iFont);
gc.DrawText(iInfoText->Des(), rect, Rect().Height()/2, CGraphicsContext::ECenter );
gc.DiscardFont();
CleanupStack::PopAndDestroy(); // converter
delete iInfoText;