Enumerate locals in C# can be done by DLL-Import Win32 API function "EnumSystemLocales":
Code
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Globalization;
- namespace ListCulture
- {
- public partial class Form1 : Form
- {
- private const int LCID_INSTALLED = 0x01;
- private const int LCID_SUPPORTED = 0x02;
- private static IntPtr handle;
- private delegate int EnumLocalesHandler(string lpLocaleString);
- private static EnumLocalesHandler m_localesDelegate;
- private static List<CultureInfo> m_cultures;
- private static int EnumLocalesProc(string locale)
- {
- try
- {
- m_cultures.Add(CultureInfo.GetCultureInfo(
- int.Parse(locale, NumberStyles.HexNumber)));
- }
- catch
- {
- // failed for this locale - ignore and continue
- }
- return 1;
- }
- public static CultureInfo[] GetCultures()
- {
- if (m_localesDelegate == null)
- {
- m_cultures = new List<CultureInfo>();
- m_localesDelegate = new EnumLocalesHandler(EnumLocalesProc);
- IntPtr fnPtr = Marshal.GetFunctionPointerForDelegate(
- m_localesDelegate);
- int success = Win32ApiPInvoke.EnumSystemLocales(fnPtr, LCID_INSTALLED);
- }
- return m_cultures.ToArray();
- }
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- foreach (CultureInfo ci in GetCultures())
- {
- listBoxLocals.Items.Add(ci.LCID.ToString() + ", " + ci.Name + ", " + ci.EnglishName);
- }
- }
- }
- sealed public class Win32ApiPInvoke
- {
- [DllImport("coredll", SetLastError = true)]
- public static extern int EnumSystemLocales(IntPtr lpLocaleEnumProc, uint dwFlags);
- }
- }