diff --git a/Core/Extensions/InteropExtensions.cs b/Core/Extensions/InteropExtensions.cs index 64cc3ccf..3b6b0b47 100644 --- a/Core/Extensions/InteropExtensions.cs +++ b/Core/Extensions/InteropExtensions.cs @@ -306,9 +306,10 @@ namespace Vanara.Extensions /// A pointer to the memory allocated by . public static IntPtr StructureToPtr(this T value, Func memAlloc, out int bytesAllocated) { - bytesAllocated = Marshal.SizeOf(value); + var ttype = typeof(T).IsEnum ? Enum.GetUnderlyingType(typeof(T)) : typeof(T); + bytesAllocated = Marshal.SizeOf(ttype); var ret = memAlloc(bytesAllocated); - Marshal.StructureToPtr(value, ret, false); + Marshal.StructureToPtr(Convert.ChangeType(value, ttype), ret, false); return ret; }