}
}
- GCHandle contextHandle = GCHandle.Alloc(data);
- try
- {
- // Now call the enumeration API. Work is done by our callback function
-#if CORECLR
- Interop.Kernel32.EnumCalendarInfoExEx(EnumCalendarsCallback, localeName, ENUM_ALL_CALENDARS, null, CAL_ICALINTVALUE, (IntPtr)contextHandle);
-#else
- IntPtr callback = AddrofIntrinsics.AddrOf<Func<IntPtr, uint, IntPtr, IntPtr, Interop.BOOL>>(EnumCalendarsCallback);
- Interop.Kernel32.EnumCalendarInfoExEx(callback, localeName, ENUM_ALL_CALENDARS, null, CAL_ICALINTVALUE, (IntPtr)contextHandle);
-#endif
- }
- finally
+ unsafe
{
- contextHandle.Free();
+ Interop.Kernel32.EnumCalendarInfoExEx(EnumCalendarsCallback, localeName, ENUM_ALL_CALENDARS, null, CAL_ICALINTVALUE, Unsafe.AsPointer(ref data));
}
// Copy to the output array
}
// EnumCalendarInfoExEx callback itself.
-#if !CORECLR
- [NativeCallable(CallingConvention = CallingConvention.StdCall)]
-#endif
- private static unsafe Interop.BOOL EnumCalendarInfoCallback(IntPtr lpCalendarInfoString, uint calendar, IntPtr pReserved, IntPtr lParam)
+ // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
+ private static unsafe Interop.BOOL EnumCalendarInfoCallback(char* lpCalendarInfoString, uint calendar, IntPtr pReserved, void* lParam)
{
- EnumData context = (EnumData)((GCHandle)lParam).Target;
+ ref EnumData context = ref Unsafe.As<byte, EnumData>(ref *(byte*)lParam);
try
{
- string calendarInfo = new string((char*)lpCalendarInfoString);
+ string calendarInfo = new string(lpCalendarInfoString);
// If we had a user override, check to make sure this differs
if (context.userOverride != calendarInfo)
}
}
- GCHandle contextHandle = GCHandle.Alloc(context);
- try
+ unsafe
{
-#if CORECLR
- Interop.Kernel32.EnumCalendarInfoExEx(EnumCalendarInfoCallback, localeName, (uint)calendar, null, calType, (IntPtr)contextHandle);
-#else
// Now call the enumeration API. Work is done by our callback function
- IntPtr callback = AddrofIntrinsics.AddrOf<Func<IntPtr, uint, IntPtr, IntPtr, Interop.BOOL>>(EnumCalendarInfoCallback);
- Interop.Kernel32.EnumCalendarInfoExEx(callback, localeName, (uint)calendar, null, calType, (IntPtr)contextHandle);
-#endif // CORECLR
- }
- finally
- {
- contextHandle.Free();
+ Interop.Kernel32.EnumCalendarInfoExEx(EnumCalendarInfoCallback, localeName, (uint)calendar, null, calType, Unsafe.AsPointer(ref context));
}
// Now we have a list of data, fail if we didn't find anything.
public IntList calendars; // list of calendars found so far
}
-#if !CORECLR
- [NativeCallable(CallingConvention = CallingConvention.StdCall)]
-#endif
- private static Interop.BOOL EnumCalendarsCallback(IntPtr lpCalendarInfoString, uint calendar, IntPtr reserved, IntPtr lParam)
+ // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
+ private static unsafe Interop.BOOL EnumCalendarsCallback(char* lpCalendarInfoString, uint calendar, IntPtr reserved, void* lParam)
{
- EnumCalendarsData context = (EnumCalendarsData)((GCHandle)lParam).Target;
+ ref EnumCalendarsData context = ref Unsafe.As<byte, EnumCalendarsData>(ref *(byte*)lParam);
try
{
// If we had a user override, check to make sure this differs
using System.Collections.Generic;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
{
Debug.Assert(!GlobalizationMode.Invariant);
- return Interop.Kernel32.GetLocaleInfoEx(lpLocaleName, lcType, (IntPtr)lpLCData, cchData);
+ return Interop.Kernel32.GetLocaleInfoEx(lpLocaleName, lcType, lpLCData, cchData);
}
private string GetLocaleInfo(LocaleStringData type)
context.cultureName = null;
context.regionName = regionName;
- GCHandle contextHandle = GCHandle.Alloc(context);
- try
- {
-#if CORECLR
- Interop.Kernel32.EnumSystemLocalesEx(EnumSystemLocalesProc, LOCALE_SPECIFICDATA | LOCALE_SUPPLEMENTAL, (IntPtr)contextHandle, IntPtr.Zero);
-#else
- IntPtr callback = AddrofIntrinsics.AddrOf<Func<IntPtr, uint, IntPtr, Interop.BOOL>>(EnumSystemLocalesProc);
- Interop.Kernel32.EnumSystemLocalesEx(callback, LOCALE_SPECIFICDATA | LOCALE_SUPPLEMENTAL, (IntPtr)contextHandle, IntPtr.Zero);
-#endif
- }
- finally
+ unsafe
{
- contextHandle.Free();
+ Interop.Kernel32.EnumSystemLocalesEx(EnumSystemLocalesProc, LOCALE_SPECIFICDATA | LOCALE_SUPPLEMENTAL, Unsafe.AsPointer(ref context), IntPtr.Zero);
}
if (context.cultureName != null)
}
// EnumSystemLocaleEx callback.
-#if !CORECLR
- [NativeCallable(CallingConvention = CallingConvention.StdCall)]
-#endif
- private static unsafe Interop.BOOL EnumSystemLocalesProc(IntPtr lpLocaleString, uint flags, IntPtr contextHandle)
+ // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
+ private static unsafe Interop.BOOL EnumSystemLocalesProc(char* lpLocaleString, uint flags, void* contextHandle)
{
- EnumLocaleData context = (EnumLocaleData)((GCHandle)contextHandle).Target;
+ ref EnumLocaleData context = ref Unsafe.As<byte, EnumLocaleData>(ref *(byte*)contextHandle);
try
{
- string cultureName = new string((char*)lpLocaleString);
+ string cultureName = new string(lpLocaleString);
string regionName = GetLocaleInfoEx(cultureName, LOCALE_SISO3166CTRYNAME);
if (regionName != null && regionName.Equals(context.regionName, StringComparison.OrdinalIgnoreCase))
{
}
// EnumSystemLocaleEx callback.
-#if !CORECLR
- [NativeCallable(CallingConvention = CallingConvention.StdCall)]
-#endif
- private static unsafe Interop.BOOL EnumAllSystemLocalesProc(IntPtr lpLocaleString, uint flags, IntPtr contextHandle)
+ // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
+ private static unsafe Interop.BOOL EnumAllSystemLocalesProc(char* lpLocaleString, uint flags, void* contextHandle)
{
- EnumData context = (EnumData)((GCHandle)contextHandle).Target;
+ ref EnumData context = ref Unsafe.As<byte, EnumData>(ref *(byte*)contextHandle);
try
{
- context.strings.Add(new string((char*)lpLocaleString));
+ context.strings.Add(new string(lpLocaleString));
return Interop.BOOL.TRUE;
}
catch (Exception)
}
// EnumTimeFormatsEx callback itself.
-#if !CORECLR
- [NativeCallable(CallingConvention = CallingConvention.StdCall)]
-#endif
- private static unsafe Interop.BOOL EnumTimeCallback(IntPtr lpTimeFormatString, IntPtr lParam)
+ // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
+ private static unsafe Interop.BOOL EnumTimeCallback(char* lpTimeFormatString, void* lParam)
{
- EnumData context = (EnumData)((GCHandle)lParam).Target;
-
+ ref EnumData context = ref Unsafe.As<byte, EnumData>(ref *(byte*)lParam);
try
{
- context.strings.Add(new string((char*)lpTimeFormatString));
+ context.strings.Add(new string(lpTimeFormatString));
return Interop.BOOL.TRUE;
}
catch (Exception)
EnumData data = new EnumData();
data.strings = new StringList();
- GCHandle dataHandle = GCHandle.Alloc(data);
- try
- {
-#if CORECLR
- Interop.Kernel32.EnumTimeFormatsEx(EnumTimeCallback, localeName, (uint)dwFlags, (IntPtr)dataHandle);
-#else
- // Now call the enumeration API. Work is done by our callback function
- IntPtr callback = AddrofIntrinsics.AddrOf<Func<IntPtr, IntPtr, Interop.BOOL>>(EnumTimeCallback);
- Interop.Kernel32.EnumTimeFormatsEx(callback, localeName, (uint)dwFlags, (IntPtr)dataHandle);
-#endif
- }
- finally
- {
- dataHandle.Free();
- }
+
+ // Now call the enumeration API. Work is done by our callback function
+ Interop.Kernel32.EnumTimeFormatsEx(EnumTimeCallback, localeName, (uint)dwFlags, Unsafe.AsPointer(ref data));
if (data.strings.Count > 0)
{
EnumData context = new EnumData();
context.strings = new StringList();
- GCHandle contextHandle = GCHandle.Alloc(context);
- try
- {
-#if CORECLR
- Interop.Kernel32.EnumSystemLocalesEx(EnumAllSystemLocalesProc, flags, (IntPtr)contextHandle, IntPtr.Zero);
-#else
- IntPtr callback = AddrofIntrinsics.AddrOf<Func<IntPtr, uint, IntPtr, Interop.BOOL>>(EnumAllSystemLocalesProc);
- Interop.Kernel32.EnumSystemLocalesEx(callback, flags, (IntPtr)contextHandle, IntPtr.Zero);
-#endif
- }
- finally
+
+ unsafe
{
- contextHandle.Free();
+ Interop.Kernel32.EnumSystemLocalesEx(EnumAllSystemLocalesProc, flags, Unsafe.AsPointer(ref context), IntPtr.Zero);
}
CultureInfo [] cultures = new CultureInfo[context.strings.Count];
{
EnumData context = new EnumData();
context.strings = new StringList();
- GCHandle contextHandle = GCHandle.Alloc(context);
- try
- {
-#if CORECLR
- Interop.Kernel32.EnumSystemLocalesEx(EnumAllSystemLocalesProc, Interop.Kernel32.LOCALE_REPLACEMENT, (IntPtr)contextHandle, IntPtr.Zero);
-#else
- IntPtr callback = AddrofIntrinsics.AddrOf<Func<IntPtr, uint, IntPtr, Interop.BOOL>>(EnumAllSystemLocalesProc);
- Interop.Kernel32.EnumSystemLocalesEx(callback, Interop.Kernel32.LOCALE_REPLACEMENT, (IntPtr)contextHandle, IntPtr.Zero);
-#endif
- }
- finally
+
+ unsafe
{
- contextHandle.Free();
+ Interop.Kernel32.EnumSystemLocalesEx(EnumAllSystemLocalesProc, Interop.Kernel32.LOCALE_REPLACEMENT, Unsafe.AsPointer(ref context), IntPtr.Zero);
}
for (int i=0; i<context.strings.Count; i++)