Windows API Internationalization Programming
UNICODE Handling
Handling UNICODE in windows primarily needs vast knowledge and
understanding, but here we will only introduce basic issues.
The purpose for handling UNICODE is to process different language
data as a unified one.
- Use TCHAR For String
-
Include tchar.h and use the type TCHAR for
the string. TCHAR means WCHAR when UNICODE is defined and type 'char'
otherwise.
- Put literals between _T or _TEXT macro.
(e.g. _T("Hello!"))
- Make a Process Covering TCHAR
-
Use _tWinMain that can handle TCHAR instead of WinMain
in the application entry point.
-
Use functions that cover TCHAR(both multi-byte/unicode).
(*see the mapping in the chart below.)
(e.g. strcpy -> _tcscpy)
- Add UNICODE Option
-
Create
the source files in UTF-8, if possible, and compile them with UNICODE options
(UNICODE, _UNICODE).
*When you use Visual C++ 6.0, the following configurations are needed.
1. Delete "_MBCS", and insert "UNICODE" and "_UNICODE" on C/C++ tab
selected "General", in project settings (*Needed both in "Release" and "Debug").
2. Specify "wWinMainCRTStartup" in "Entry Point Symbol" on Link tab
selected "Output", in project settings (*Needed both in "Release" and "Debug").
3. If you use MFC, install "Static Libraries for Unicode" and "Shared Libraries for Unicode"
from Visual Studio CD.
The mapping between multi-byte function and both UNICODE and TCHAR are listed below.
----------------------------------------
Multi-byte UNICODE TCHAR
----------------------------------------
strcpy wcscpy _tcscpy
strncpy wcsncpy _tcsncpy
strcat wcscat _tcscat
strncat wcsncat _tcsncat
strlen wcslen _tcslen
strcmp wcscmp _tcscmp
strncmp wcsncmp _tcsncmp
strstr wcsstr _tcsstr
sscanf swscanf _tscanf
sprintf swprintf _stprintf
_scprintf _scwprintf _sctprintf
strtok wcstok _tcstok
strchr wcschr _tcschr
_strdup _wcsdup _tcsdup
printf wprintf _tprintf
scanf wscanf _tscanf
std::cout std::wcout None
std::cin std::wcin None
fopen _wfopen _tfopen
fprintf fwprintf _ftprintf
fputs fputws _fputts
fgets fgetws _fgetts
fscanf fwscanf _ftscanf
fgetc fgetwc _fgettc
fputc fputwc _fputtc
getc fgetwc _gettc
getchar getwchar _gettchar
gets getws _getts
putc putwc _puttc
puts putws _putts
strtod wcstod _tcstod
strtol wcstol _tcstol
strtoul wcstoul _tcstoul
atof _wtof _tstof
atol _wtol _tstol, _ttol
atoi _wtoi _tstoi, _ttoi
system _wsystem _tsystem
----------------------------------------
Go to Internationalization Programming Top
Copyright (C) 2012 Kokusaika JP, Inc.
All rights reserved. No reproduction or republication without written permission.