Enumerate locals in C#

      Enumerate locals in C#

      Enumerate locals in C# can be done by DLL-Import Win32 API function "EnumSystemLocales":

      Source Code

      1. using System;
      2. using System.Collections.Generic;
      3. using System.ComponentModel;
      4. using System.Data;
      5. using System.Drawing;
      6. using System.Linq;
      7. using System.Text;
      8. using System.Windows.Forms;
      9. using System.Runtime.InteropServices;
      10. using System.Globalization;
      11. namespace ListCulture
      12. {
      13. public partial class Form1 : Form
      14. {
      15. private const int LCID_INSTALLED = 0x01;
      16. private const int LCID_SUPPORTED = 0x02;
      17. private static IntPtr handle;
      18. private delegate int EnumLocalesHandler(string lpLocaleString);
      19. private static EnumLocalesHandler m_localesDelegate;
      20. private static List<CultureInfo> m_cultures;
      21. private static int EnumLocalesProc(string locale)
      22. {
      23. try
      24. {
      25. m_cultures.Add(CultureInfo.GetCultureInfo(
      26. int.Parse(locale, NumberStyles.HexNumber)));
      27. }
      28. catch
      29. {
      30. // failed for this locale - ignore and continue
      31. }
      32. return 1;
      33. }
      34. public static CultureInfo[] GetCultures()
      35. {
      36. if (m_localesDelegate == null)
      37. {
      38. m_cultures = new List<CultureInfo>();
      39. m_localesDelegate = new EnumLocalesHandler(EnumLocalesProc);
      40. IntPtr fnPtr = Marshal.GetFunctionPointerForDelegate(
      41. m_localesDelegate);
      42. int success = Win32ApiPInvoke.EnumSystemLocales(fnPtr, LCID_INSTALLED);
      43. }
      44. return m_cultures.ToArray();
      45. }
      46. public Form1()
      47. {
      48. InitializeComponent();
      49. }
      50. private void Form1_Load(object sender, EventArgs e)
      51. {
      52. foreach (CultureInfo ci in GetCultures())
      53. {
      54. listBoxLocals.Items.Add(ci.LCID.ToString() + ", " + ci.Name + ", " + ci.EnglishName);
      55. }
      56. }
      57. }
      58. sealed public class Win32ApiPInvoke
      59. {
      60. [DllImport("coredll", SetLastError = true)]
      61. public static extern int EnumSystemLocales(IntPtr lpLocaleEnumProc, uint dwFlags);
      62. }
      63. }

      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.