How about this?
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.InteropServices;
namespace OpenNETCF.Globalization
{
public class CultureInfoHelper
{
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 = EnumSystemLocales(fnPtr, LCID_INSTALLED);
}
return m_cultures.ToArray();
}
private const int LCID_INSTALLED = 0x01;
private const int LCID_SUPPORTED = 0x02;
[DllImport("coredll", SetLastError = true)]
private static extern int EnumSystemLocales(
IntPtr lpLocaleEnumProc, uint dwFlags);
}
}
Usage looks like this:
using OpenNETCF.Globalization;
....
static void Main()
{
foreach (CultureInfo ci in CultureInfoHelper.GetCultures())
{
Debug.WriteLine(string.Format("0x{0:x2}({1}) : {2}", ci.LCID, ci.Name, ci.EnglishName));
}
}
And output looks like this:
0x402(bg-BG) : Bulgarian (Bulgaria)
0x403(ca-ES) : Catalan (Catalan)
0x405(cs-CZ) : Czech (Czech Republic)
0x406(da-DK) : Danish (Denmark)
0x407(de-DE) : German (Germany)
0x408(el-GR) : Greek (Greece)
0x409(en-US) : English (United States)
...
0x400a(es-BO) : Spanish (Bolivia)
0x440a(es-SV) : Spanish (El Salvador)
0x480a(es-HN) : Spanish (Honduras)
0x4c0a(es-NI) : Spanish (Nicaragua)
0x500a(es-PR) : Spanish (Puerto Rico)