Beispiel #1
0
        // Enumerate all system cultures and then try to find out which culture has
        // region name match the requested region name
        private static CultureData GetCultureDataFromRegionName(String regionName)
        {
            Contract.Assert(regionName != null);

            const uint LOCALE_SUPPLEMENTAL = 0x00000002;
            const uint LOCALE_SPECIFICDATA = 0x00000020;

            EnumLocaleData context = new EnumLocaleData();

            context.cultureName = null;
            context.regionName  = regionName;

            GCHandle contextHandle = GCHandle.Alloc(context);

            try
            {
                Interop.mincore_obsolete.EnumLocalesProcEx    callback = new Interop.mincore_obsolete.EnumLocalesProcEx(EnumSystemLocalesProc);
                Interop.mincore_private.LParamCallbackContext ctx      = new Interop.mincore_private.LParamCallbackContext();
                ctx.lParam = (IntPtr)contextHandle;

                Interop.mincore_obsolete.EnumSystemLocalesEx(callback, LOCALE_SPECIFICDATA | LOCALE_SUPPLEMENTAL, ctx, IntPtr.Zero);
            }
            finally
            {
                contextHandle.Free();
            }

            if (context.cultureName != null)
            {
                // we got a matched culture
                return(GetCultureData(context.cultureName, true));
            }

            return(null);
        }
Beispiel #2
0
        // Enumerate all system cultures and then try to find out which culture has 
        // region name match the requested region name
        private static CultureData GetCultureDataFromRegionName(String regionName)
        {
            Contract.Assert(regionName != null);

            const uint LOCALE_SUPPLEMENTAL = 0x00000002;
            const uint LOCALE_SPECIFICDATA = 0x00000020;

            EnumLocaleData context = new EnumLocaleData();
            context.cultureName = null;
            context.regionName = regionName;

            GCHandle contextHandle = GCHandle.Alloc(context);
            try
            {
                Interop.mincore_obsolete.EnumLocalesProcEx callback = new Interop.mincore_obsolete.EnumLocalesProcEx(EnumSystemLocalesProc);
                Interop.mincore_private.LParamCallbackContext ctx = new Interop.mincore_private.LParamCallbackContext();
                ctx.lParam = (IntPtr)contextHandle;

                Interop.mincore_obsolete.EnumSystemLocalesEx(callback, LOCALE_SPECIFICDATA | LOCALE_SUPPLEMENTAL, ctx, IntPtr.Zero);
            }
            finally
            {
                contextHandle.Free();
            }

            if (context.cultureName != null)
            {
                // we got a matched culture
                return GetCultureData(context.cultureName, true);
            }

            return null;
        }