by Michael S. Kaplan, published on 2005/02/27 08:25 -05:00, original URI: http://blogs.msdn.com/b/michkap/archive/2005/02/27/381189.aspx
The other day I posted about the Microsoft Win32 to Microsoft .NET Framework API Map and commented that there were some mistakes in the NLS functions there.
Here is a quick list of things I would change (I will send the link as feedback, too). The key to the changed table:
The APIs that were not included here but were put elsewhere, or not included at all:
Win32 function | Description | .NET Framework API |
---|---|---|
ConvertDefaultLocale | Converts a default locale value to an actual locale identifier. |
Actually, you would use the static System.Globalization.CultureInfo.CreateSpecificCulture() method to create a specific culture from a neutral one, which is what that API does. |
EnumCalendarInfo | Enumerates calendar information for a specified locale. |
Access the System.Globalization.CultureInfo.DateTimeFormat property to get a System.Globalization.DateTimeFormatInfo object, and then access its properties: Let's not forget the most important part -- you need to look at the information after setting the desired Calendar on the culture, first! |
EnumDateFormats | Enumerates the long or short date formats that are available for a specified locale. |
System.DateTime.GetDateTimeFormats(System.Globalization.CultureInfo) Or alternately, DateTimeFormatInfo.GetAllDateTimePatterns() |
EnumDateFormatsEx | Enumerates the long or short date formats that are available for a specified locale, including date formats for any alternate calendars. |
Iterate through the calendars: Or alternately, DateTimeFormatInfo.GetAllDateTimePatterns() |
EnumSystemCodePages | Enumerates the code pages that are either installed on or supported by a system. |
This will not get all of the code pages and will show many repeats of those it does get -- it will also sometimes retrieve IDs that are not supported. There is not a good enumeration methodology for the supported code pages in .NET 1.1 -- but look for new enumeration methods in 2.0! |
EnumSystemGeoID | Enumerates all GeoIDs on the system. |
GeoID is not supported in .NET 1.1 and it is actually region-based, not language based. .NET 2.0 will support a RegionInfo.GeoId property. |
EnumSystemLocales | Enumerates the locales that are either installed on or supported by a system. |
System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures) Note that there is no method that can be used to get the alternate sorts, one of the important features this API supports. |
EnumTimeFormats | Enumerates the time formats that are available for a specified locale. |
System.DateTime.GetDateTimeFormats Or alternately, DateTimeFormatInfo.GetAllDateTimePatterns() |
GetACP | Retrieves the current ANSI code-page identifier for the system. |
Try Encoding.Default.CodePage, instead. |
GetCalendarInfo | Retrieves information about a calendar. |
System.Globalization.CultureInfo.DateTimeFormat This will only work for the currently selected Calendar -- make sure to set the Calendar from which you would like information, first. |
GetLocaleInfo | Retrieves information about a locale. |
Well, instead of that, how about everything under: |
GetOEMCP | Retrieves the current original equipment manufacturer (OEM) code-page identifier for the system. |
The real OEMCP of a system is based on the default system locale, which can be changed. The Installed UI language cannot be. |
GetSystemDefaultLangID | Retrieves the language identifier of the system locale. |
The default LANGID of a system is based on the default system locale, which can be changed. The Installed UI language cannot be. |
GetSystemDefaultLCID | Retrieves the system default locale identifier. |
The system default LCID is the default system locale, which can be changed. The Installed UI language cannot be. |
GetThreadLocale | Retrieves the current locale for the calling thread. |
Either of the following: The most important change that occurs when the thread locale is changed is the resource language in the thread, meaning System.Threading.Thread.CurrentUICulture may be more accurate here. |
GetUserGeoID | Gets information about the user's location. |
System.Globalization.RegionInfo GeoID is not supported in .NET 1.1, but 2.0 will support a RegionInfo.GeoId property. |
IsValidCodePage | Determines whether a specified code page is valid. |
Yikes! This is time consuming and will not detect all valid code pages, and will claim some are valid that may not be supported. How about calling Encoding.GetEncoding() with a CodePage identifier and trapping both ArgumentException and NotSupportedException, instead? |
LCMapString | Maps one character string to another, performing a specified locale-dependent transformation. |
System.Globalization.SortKey This is only one of the many possible uses of LCMapString, which also supports uppercase/lowercase, Hiragana/Katakana, fullwidth/halfwidth, traditional/simplified mappings. Of these, only the case mappings are supported in .NET. |
SetThreadLocale | Sets the current locale for the calling thread. | System.Threading.Thread.CurrentCulture
Note Sets langid only. The most important change that occurs when the thread locale is changed is the resource language in the thread, meaning System.Threading.Thread.CurrentUICulture may be more accurate here. |
This post brought to you by "E" (U+0045, a.k.a. LATIN CAPITAL LETTER E)
# AC on 27 Feb 2005 5:51 AM:
# Michael Kaplan on 27 Feb 2005 4:06 PM:
referenced by
2008/03/20 That's no gap, dear; that's a huge freaking chasm!
2005/04/15 From Win32 to .NET (and vice versa)