Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
StandardOleMarshalObject.cs
Go to the documentation of this file.
2
4{
5 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
6 private delegate int GetMarshalSizeMaxDelegate(IntPtr _this, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out int pSize);
7
8 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
9 private delegate int MarshalInterfaceDelegate(IntPtr _this, IntPtr pStm, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags);
10
11 private static readonly Guid CLSID_StdMarshal = new Guid("00000017-0000-0000-c000-000000000046");
12
14 {
15 }
16
17 private IntPtr GetStdMarshaler(ref Guid riid, int dwDestContext, int mshlflags)
18 {
19 IntPtr iUnknownForObject = Marshal.GetIUnknownForObject(this);
20 if (iUnknownForObject != IntPtr.Zero)
21 {
22 try
23 {
24 IntPtr ppMarshal = IntPtr.Zero;
25 if (Interop.Ole32.CoGetStandardMarshal(ref riid, iUnknownForObject, dwDestContext, IntPtr.Zero, mshlflags, out ppMarshal) == 0)
26 {
27 return ppMarshal;
28 }
29 }
30 finally
31 {
32 Marshal.Release(iUnknownForObject);
33 }
34 }
36 }
37
38 int IMarshal.GetUnmarshalClass(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out Guid pCid)
39 {
40 pCid = CLSID_StdMarshal;
41 return 0;
42 }
43
44 unsafe int IMarshal.GetMarshalSizeMax(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out int pSize)
45 {
46 IntPtr stdMarshaler = GetStdMarshaler(ref riid, dwDestContext, mshlflags);
47 try
48 {
49 IntPtr intPtr = *(IntPtr*)stdMarshaler.ToPointer();
50 IntPtr ptr = *(IntPtr*)((byte*)intPtr.ToPointer() + (nint)4 * (nint)sizeof(IntPtr));
52 return getMarshalSizeMaxDelegate(stdMarshaler, ref riid, pv, dwDestContext, pvDestContext, mshlflags, out pSize);
53 }
54 finally
55 {
56 Marshal.Release(stdMarshaler);
57 }
58 }
59
60 unsafe int IMarshal.MarshalInterface(IntPtr pStm, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags)
61 {
62 IntPtr stdMarshaler = GetStdMarshaler(ref riid, dwDestContext, mshlflags);
63 try
64 {
65 IntPtr intPtr = *(IntPtr*)stdMarshaler.ToPointer();
66 IntPtr ptr = *(IntPtr*)((byte*)intPtr.ToPointer() + (nint)5 * (nint)sizeof(IntPtr));
68 return marshalInterfaceDelegate(stdMarshaler, pStm, ref riid, pv, dwDestContext, pvDestContext, mshlflags);
69 }
70 finally
71 {
72 Marshal.Release(stdMarshaler);
73 }
74 }
75
76 int IMarshal.UnmarshalInterface(IntPtr pStm, ref Guid riid, out IntPtr ppv)
77 {
78 ppv = IntPtr.Zero;
79 return -2147467263;
80 }
81
83 {
84 return -2147467263;
85 }
86
87 int IMarshal.DisconnectObject(int dwReserved)
88 {
89 return -2147467263;
90 }
91}
static int CoGetStandardMarshal(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out IntPtr ppMarshal)
static Delegate GetDelegateForFunctionPointer(IntPtr ptr, Type t)
Definition Marshal.cs:1414
static unsafe int Release(IntPtr pUnk)
Definition Marshal.cs:766
static IntPtr GetIUnknownForObject(object o)
Definition Marshal.cs:231
delegate int MarshalInterfaceDelegate(IntPtr _this, IntPtr pStm, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags)
IntPtr GetStdMarshaler(ref Guid riid, int dwDestContext, int mshlflags)
delegate int GetMarshalSizeMaxDelegate(IntPtr _this, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out int pSize)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string StandardOleMarshalObjectGetMarshalerFailed
Definition SR.cs:1854
Definition SR.cs:7
int UnmarshalInterface(IntPtr pStm, ref Guid riid, out IntPtr ppv)
int MarshalInterface(IntPtr pStm, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags)
int GetUnmarshalClass(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out Guid pCid)
int GetMarshalSizeMax(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out int pSize)
static readonly IntPtr Zero
Definition IntPtr.cs:18
unsafe void * ToPointer()
Definition IntPtr.cs:210