Can the locale configuration of a system OR the keyboard type configuration of that system in anyway affect which API is called at the Kernel level? To be specific, if a program is invoking 'CreateFile()' API then the windows API documentation says that the call gets delegated to either CreateFileA or CreateFileW. If that program is being run on a system present in China with a Chinese Keyboard then which of the two functions will be called?
1 Answers
Unicode and Locale are two completely orthogonal concepts.
With regards to CreateFileA
vs CreateFileW
- the setting that controls this is a compile time setting: If the application is compiled to run with the Unicode character set, then CreateFileW
will be called, if the compile settings indicated that the application should be compiled as a multibyte application, then CreateFileA
will be called.
If you are using Visual Studio C++, then examine the Project settings of the application. Under Configuration Properties, on the page called "General" will be a setting "Character Set" - This can be set to "Use Unicode Character Set", or "Use Multi-Byte Character Set". The effect of this setting is to automatically add another property sheet to the solution - visible under the Property Manager: The "Unicode Support" property sheet adds the preprocessor definitions "_UNICODE,UNICODE
" - the "Multi-Byte Character Support" property sheet instead adds "_MBCS".
Now, if you look at the definition for CreateFile
you will see it is a macro itself, and when you build your application, all CreateFile
calls in the code will resolve to CreateFileW
calls if UNICODE
is defined, and CreateFileA
calls otherwise.
UNICODE
is used by windows.h
to switch between the Wide and Ansi versions of the windows API calls.
_MBCS
and _UNICODE
are used by the Microsoft C Runtime headers - principally tchar.h - to switch the c-library from supporting single byte to multi byte to unicode characters on functions that support that.

- 34,244
- 12
- 79
- 148
-
Thank you for the answer, it cleared many of my doubts. Just to get your opinion on one more thing: If a well known product company is selling its product say in China or Saudi Arabia or Iran I would presume that they will be careful enough to compile the code by defining UNICODE right? Else there might be chances that the software would crash if the file-name uses Unicode character set, right? It would be really helpful if you could clarify this. – The Kaykay Apr 12 '12 at 20:31
-
If you consult http://www.mydigitallife.info/ansi-code-page-for-windows-system-locale-with-identifier-constants-and-strings/ you can see that there are not a lot of unicode only locales. A person, living in China would, depending on their actual location, be quite able to develop a non-Unicode application, as long as all the characters in their file names could be encoded in the Chinese-traditional, or Simplified Chinese code pages. – Chris Becke Apr 13 '12 at 05:22