private static unsafe String[] nativeEnumTimeFormats(String localeName, uint dwFlags, bool useUserOverride) { const uint LOCALE_SSHORTTIME = 0x00000079; const uint LOCALE_STIMEFORMAT = 0x00001003; EnumData data = new EnumData(); data.strings = new LowLevelList <string>(); GCHandle dataHandle = GCHandle.Alloc(data); try { EnumTimeFormatsProcEx callback = new EnumTimeFormatsProcEx(EnumTimeCallback); Interop.mincore_private.LParamCallbackContext cxt = new Interop.mincore_private.LParamCallbackContext(); cxt.lParam = (IntPtr)dataHandle; // Now call the enumeration API. Work is done by our callback function Interop.mincore_private.EnumTimeFormatsEx(callback, localeName, (uint)dwFlags, cxt); } finally { dataHandle.Free(); } if (data.strings.Count > 0) { // Now we need to allocate our stringarray and populate it string[] results = data.strings.ToArray(); if (!useUserOverride && data.strings.Count > 1) { // Since there is no "NoUserOverride" aware EnumTimeFormatsEx, we always get an override // The override is the first entry if it is overriden. // We can check if we have overrides by checking the GetLocaleInfo with no override // If we do have an override, we don't know if it is a user defined override or if the // user has just selected one of the predefined formats so we can't just remove it // but we can move it down. uint lcType = (dwFlags == TIME_NOSECONDS) ? LOCALE_SSHORTTIME : LOCALE_STIMEFORMAT; string timeFormatNoUserOverride = GetLocaleInfoFromLCType(localeName, lcType, useUserOverride); if (timeFormatNoUserOverride != "") { string firstTimeFormat = results[0]; if (timeFormatNoUserOverride != firstTimeFormat) { results[0] = results[1]; results[1] = firstTimeFormat; } } } return(results); } return(null); }
internal static extern bool EnumTimeFormatsEx(EnumTimeFormatsProcEx lpTimeFmtEnumProcEx, string lpLocaleName, uint dwFlags, void *lParam);
internal extern static bool EnumTimeFormatsEx(EnumTimeFormatsProcEx lpTimeFmtEnumProcEx, string lpLocaleName, uint dwFlags, mincore_private.LParamCallbackContext lParam);
internal extern static bool EnumTimeFormatsEx(EnumTimeFormatsProcEx lpTimeFmtEnumProcEx, string lpLocaleName, uint dwFlags, IntPtr lParam);
private static unsafe String[] nativeEnumTimeFormats(String localeName, uint dwFlags, bool useUserOverride) { const uint LOCALE_SSHORTTIME = 0x00000079; const uint LOCALE_STIMEFORMAT = 0x00001003; EnumData data = new EnumData(); data.strings = new LowLevelList<string>(); GCHandle dataHandle = GCHandle.Alloc(data); try { EnumTimeFormatsProcEx callback = new EnumTimeFormatsProcEx(EnumTimeCallback); Interop.mincore_private.LParamCallbackContext cxt = new Interop.mincore_private.LParamCallbackContext(); cxt.lParam = (IntPtr)dataHandle; // Now call the enumeration API. Work is done by our callback function Interop.mincore_private.EnumTimeFormatsEx(callback, localeName, (uint)dwFlags, cxt); } finally { dataHandle.Free(); } if (data.strings.Count > 0) { // Now we need to allocate our stringarray and populate it string[] results = data.strings.ToArray(); if (!useUserOverride && data.strings.Count > 1) { // Since there is no "NoUserOverride" aware EnumTimeFormatsEx, we always get an override // The override is the first entry if it is overriden. // We can check if we have overrides by checking the GetLocaleInfo with no override // If we do have an override, we don't know if it is a user defined override or if the // user has just selected one of the predefined formats so we can't just remove it // but we can move it down. uint lcType = (dwFlags == TIME_NOSECONDS) ? LOCALE_SSHORTTIME : LOCALE_STIMEFORMAT; string timeFormatNoUserOverride = GetLocaleInfoFromLCType(localeName, lcType, useUserOverride); if (timeFormatNoUserOverride != "") { string firstTimeFormat = results[0]; if (timeFormatNoUserOverride != firstTimeFormat) { results[0] = results[1]; results[1] = firstTimeFormat; } } } return results; } return null; }