|
Free Educational Resource Center for teachers and students. Includes Interviews, Sourcecode, Free Software, Research Papers, Articles, Tutorials and much more.. |
R E S E A R C H A C T I V I T Y . C O M
Our Fellow Research Center for Ph.D Schollars |
|
| Home About Submit & Earn | Archives: C And C + + Programming » Dev Packages » Interviews » Php Mysql Programming » Windows Programming | |
|
Windows Programming > why unicode is important before you start to program
Why UICODE is important before you start program First of all you must have question in mind: What is UNICODE? Unicode is a coding system in which each character is stored in 2 bytes (16bits) rather than simple 8 bit character. Usually the characters you see on a standard english keyboard are stored in one byte, to test it, you simply create new text file in notepad and type only one character in it, then save an check its size, it will report 1 byte.
Single byte storage Now problem with 1 byte character storage is, it can store maximum value of 255 in 8 bits, so can store maximum 255 different characters in each byte. To solve this problem (keeping in view the international language) new system was introduced called 'unicode'. Using this system, we can store character in 2 bytes (16 bits), which gives us possibity to store huge variety of different values upto 65535. E.g. from range of 1665 to 1773 there are some arabic language characters. On the webpages to display this kind of characters you use &#THENUMBER; where 'THENUMBER' is the numaric value of the character. Let's come to the point. There are two kind of functions in windows api, the first one are non-unicode and the other are unicode. For example the function MessageBox is defined two way in windwos API, one MessageBoxA and second MessageBoxW, the one with 'A' on end is non-unicode version whcih accepts text defined using CHAR array, and the other one with ending 'W' is the unicode one which accepts wide character. Very simple to understand is use types: CHAR for non-unicode and WCHAR for unicode application NOTE: If you are using dev c++, your applciation is by default non-unicode, to enable it compile as unicode applciation simple put 2 defines on top of all the code as
And, if you are using Microsoft Visual Studio Express Edition, then your applciation is by default UNICODE enabled, to enable your application compile as non-unicode put 2 undefines on top of all code as
Besides, Mircorsoft Visul Studio provides a very good project options panel, through which you can change these settings, either to compile as UNICODE or Multibyte characterset applciation. So, do I have to maintain two separate source coes for same applciations?NO, the best solution is use TCHAR, as:
And, enclose every character string within a macro _T( ), that acts as per current characterset accordingly. e.g. Following code will compile as both unicode and non-unicode applciation:
PROBLEMS1.strcat and other standard string manipulation functions seem to be not compiled when compiling as UNICODE enabled, why? Well, when you are developing applciation for both you have to use windows specific functions, such as: use wcscat instead of strcat, use wsprintf instead of sprintf. There is windows specific alternate available for almost every string manipulatin function in windows. A full list of Win32 Equivalents for C Run-Time Functions is available at the end of this document. 2.Now problem is when you pass a string variable to this _T() macro, it gives a compiler error, such as:
Solution is: Simply do not use _T() when passing variable instead of constant character string, as:
Win32 Equivalents for C Run-Time FunctionsDirectly copied from Microsoft Win32 Software Development Kit (SDK), versions 3.1, 3.5, 3.51, and 4.0 Manual
|