I'll levae it for the reader to get some background on Unicode from the Internet, and will directly jump to its affect on Win32 programing.
One may have noticed use of new data types everywhere in win32 programs. Data types like LPCTSTR, LPWSTR, TCHAR etc...
Accompanying them exist these functions with have either an A/W or T pre/post pended.
A char is a char. One byte, everywhere. Wide characters are defined as wchar_t. If you look in WCHAR.H, you'll find something like :
typedef unsigned short wchar_t ; // 2bytes
When you are dealing with wide strings, you have to apend an L .. for eg :
wchar_t* str = L"Hello";
wchar_t ch = L'v';
Functions that one is used to working with ASCII strings wont work properly with wide characters. These are 2 byte long after all. So functions for wide strings exist.
printf - wprintf
strcpy - wcscpy
so on and so forth.
However, if you want to make your app work with both ASCII and UNICODE, you must use the 'T' flavoured functions/data types. These translate to ASCII or UNICODE depending upon if _UNICODE identifier is defined. For eg :
TCHAR tch;
now, TCHAR is defined as :
typedef wchar_t TCHAR ; // if _UNICODE is defined
One may have noticed use of new data types everywhere in win32 programs. Data types like LPCTSTR, LPWSTR, TCHAR etc...
Accompanying them exist these functions with have either an A/W or T pre/post pended.
A char is a char. One byte, everywhere. Wide characters are defined as wchar_t. If you look in WCHAR.H, you'll find something like :
typedef unsigned short wchar_t ; // 2bytes
When you are dealing with wide strings, you have to apend an L .. for eg :
wchar_t* str = L"Hello";
wchar_t ch = L'v';
Functions that one is used to working with ASCII strings wont work properly with wide characters. These are 2 byte long after all. So functions for wide strings exist.
printf - wprintf
strcpy - wcscpy
so on and so forth.
However, if you want to make your app work with both ASCII and UNICODE, you must use the 'T' flavoured functions/data types. These translate to ASCII or UNICODE depending upon if _UNICODE identifier is defined. For eg :
TCHAR tch;
now, TCHAR is defined as :
typedef wchar_t TCHAR ; // if _UNICODE is defined
typedef char TCHAR ; // Otherwise
Also, there exists a macro named : _T(x)/__T(x)/TEXT(x), which tranlates to L##x if _UNICODE is defined, and to simple x otherwise. So declaring a string which is intended to work with both A/U should be with the TEXT macro, like :
TEXT("Hello");
To support this, there exist functions and APIs which accept "T" flavoured arguments.
e.g.
_tcscpy, which is wcscpy if _UNICODE is defined, strcpy otherwise.
Disclaimer : The information in this weblog is provided “AS IS” with no warranties, and confers no rights.
This is a personal blog, and does not represent the thoughts, intentions or plans of my employer/peers. It is solely my opinion.
TEXT("Hello");
To support this, there exist functions and APIs which accept "T" flavoured arguments.
e.g.
_tcscpy, which is wcscpy if _UNICODE is defined, strcpy otherwise.
Disclaimer : The information in this weblog is provided “AS IS” with no warranties, and confers no rights.
This is a personal blog, and does not represent the thoughts, intentions or plans of my employer/peers. It is solely my opinion.
No comments:
Post a Comment