Browse Source

Add Record struct and field to ComVariant to ensure that it has proper binary size (4 pointers (16 bytes) on a 32-bit processor, 3 pointers (24 bytes) on a 64-bit processor). (#20017)

Based on dotnet/runtime implementation https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ComVariant.cs
pull/20023/head
Andrey Rusyaev 3 months ago
committed by GitHub
parent
commit
7aed580721
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 27
      src/Windows/Avalonia.Win32.Automation/Marshalling/ComVariant.cs

27
src/Windows/Avalonia.Win32.Automation/Marshalling/ComVariant.cs

@ -18,6 +18,25 @@ internal struct ComVariant : IDisposable
internal const short VARIANT_TRUE = -1; internal const short VARIANT_TRUE = -1;
internal const short VARIANT_FALSE = 0; internal const short VARIANT_FALSE = 0;
#if DEBUG
static unsafe ComVariant()
{
// Variant size is the size of 4 pointers (16 bytes) on a 32-bit processor,
// and 3 pointers (24 bytes) on a 64-bit processor.
// See definition in oaidl.h in the Windows SDK.
int variantSize = sizeof(ComVariant);
if (IntPtr.Size == 4)
{
Debug.Assert(variantSize == (4 * IntPtr.Size));
}
else
{
Debug.Assert(IntPtr.Size == 8);
Debug.Assert(variantSize == (3 * IntPtr.Size));
}
}
#endif
// Most of the data types in the Variant are carried in _typeUnion // Most of the data types in the Variant are carried in _typeUnion
[FieldOffset(0)] private TypeUnion _typeUnion; [FieldOffset(0)] private TypeUnion _typeUnion;
@ -32,6 +51,13 @@ internal struct ComVariant : IDisposable
public UnionTypes _unionTypes; public UnionTypes _unionTypes;
} }
[StructLayout(LayoutKind.Sequential)]
private struct Record
{
public IntPtr _record;
public IntPtr _recordInfo;
}
[StructLayout(LayoutKind.Explicit)] [StructLayout(LayoutKind.Explicit)]
private unsafe struct UnionTypes private unsafe struct UnionTypes
{ {
@ -56,6 +82,7 @@ internal struct ComVariant : IDisposable
[FieldOffset(0)] public IntPtr _dispatch; [FieldOffset(0)] public IntPtr _dispatch;
[FieldOffset(0)] public IntPtr _pvarVal; [FieldOffset(0)] public IntPtr _pvarVal;
[FieldOffset(0)] public IntPtr _byref; [FieldOffset(0)] public IntPtr _byref;
[FieldOffset(0)] public Record _record;
[FieldOffset(0)] public SafeArrayRef parray; [FieldOffset(0)] public SafeArrayRef parray;
[FieldOffset(0)] public SafeArrayRef*pparray; [FieldOffset(0)] public SafeArrayRef*pparray;
} }

Loading…
Cancel
Save