Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ internal static partial class Interop
{
internal static partial class Ole32
{
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
[DllImport(Interop.Libraries.Ole32)]
internal static extern int CoGetStandardMarshal(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out IntPtr ppMarshal);
#pragma warning restore DLLIMPORTGENANALYZER015
[GeneratedDllImport(Interop.Libraries.Ole32)]
internal static partial int CoGetStandardMarshal(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out IntPtr ppMarshal);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ public class StandardOleMarshalObject : MarshalByRefObject, IMarshal
{
private static readonly Guid CLSID_StdMarshal = new Guid("00000017-0000-0000-c000-000000000046");

[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate int GetMarshalSizeMaxDelegate(IntPtr _this, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out int pSize);

[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate int MarshalInterfaceDelegate(IntPtr _this, IntPtr pStm, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags);

protected StandardOleMarshalObject()
{
}
Expand Down Expand Up @@ -60,13 +54,12 @@ unsafe int IMarshal.GetMarshalSizeMax(ref Guid riid, IntPtr pv, int dwDestContex
// would trigger QIs for random IIDs and the marshaler (aka stub
// manager object) does not really handle these well and we would
// risk triggering an AppVerifier break
IntPtr vtable = *(IntPtr*)pStandardMarshal.ToPointer();

// GetMarshalSizeMax is 4th slot
IntPtr method = *((IntPtr*)vtable.ToPointer() + 4);

GetMarshalSizeMaxDelegate del = (GetMarshalSizeMaxDelegate)Marshal.GetDelegateForFunctionPointer(method, typeof(GetMarshalSizeMaxDelegate));
return del(pStandardMarshal, ref riid, pv, dwDestContext, pvDestContext, mshlflags, out pSize);
fixed (Guid* riidPtr = &riid)
fixed (int* pSizePtr = &pSize)
{
// GetMarshalSizeMax is 5th slot (zero-based indexing)
return ((delegate* unmanaged[Stdcall]<IntPtr, Guid*, IntPtr, int, IntPtr, int, int*, int>)(*(IntPtr**)pStandardMarshal)[4])(pStandardMarshal, riidPtr, pv, dwDestContext, pvDestContext, mshlflags, pSizePtr);
}
}
finally
{
Expand All @@ -85,11 +78,11 @@ unsafe int IMarshal.MarshalInterface(IntPtr pStm, ref Guid riid, IntPtr pv, int
// would trigger QIs for random IIDs and the marshaler (aka stub
// manager object) does not really handle these well and we would
// risk triggering an AppVerifier break
IntPtr vtable = *(IntPtr*)pStandardMarshal.ToPointer();
IntPtr method = *((IntPtr*)vtable.ToPointer() + 5); // MarshalInterface is 5th slot

MarshalInterfaceDelegate del = (MarshalInterfaceDelegate)Marshal.GetDelegateForFunctionPointer(method, typeof(MarshalInterfaceDelegate));
return del(pStandardMarshal, pStm, ref riid, pv, dwDestContext, pvDestContext, mshlflags);
fixed (Guid* riidPtr = &riid)
{
// MarshalInterface is 6th slot (zero-based indexing)
return ((delegate* unmanaged[Stdcall]<IntPtr, IntPtr, Guid*, IntPtr, int, IntPtr, int, int>)(*(IntPtr**)pStandardMarshal)[5])(pStandardMarshal, pStm, riidPtr, pv, dwDestContext, pvDestContext, mshlflags);
}
}
finally
{
Expand Down