-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathIContextCallback.cs
85 lines (75 loc) · 3.06 KB
/
IContextCallback.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using WinRT;
using WinRT.Interop;
#pragma warning disable 0169 // warning CS0169: The field '...' is never used
#pragma warning disable 0649 // warning CS0169: Field '...' is never assigned to
namespace WinRT.Interop
{
struct ComCallData
{
public int dwDispid;
public int dwReserved;
public IntPtr pUserDefined;
}
unsafe delegate int PFNCONTEXTCALL(ComCallData* data);
[Guid("000001da-0000-0000-C000-000000000046")]
unsafe interface IContextCallback
{
// The pUnk parameter is intentionally excluded here
// since it is required to always be null.
void ContextCallback(
PFNCONTEXTCALL pfnCallback,
ComCallData* pParam,
Guid riid,
int iMethod);
}
}
namespace ABI.WinRT.Interop
{
[Guid("000001da-0000-0000-C000-000000000046")]
unsafe class IContextCallback : global::WinRT.Interop.IContextCallback
{
[Guid("000001da-0000-0000-C000-000000000046")]
public struct Vftbl
{
global::WinRT.Interop.IUnknownVftbl IUnknownVftbl;
private void* _ContextCallback;
public delegate* unmanaged[Stdcall]<IntPtr, IntPtr, ComCallData*, Guid*, int, IntPtr, int> ContextCallback_4
{
get => (delegate* unmanaged[Stdcall]<IntPtr, IntPtr, ComCallData*, Guid*, int, IntPtr, int>)_ContextCallback;
set => _ContextCallback = (void*)value;
}
}
public static ObjectReference<Vftbl> FromAbi(IntPtr thisPtr) => ObjectReference<Vftbl>.FromAbi(thisPtr);
public static implicit operator IContextCallback(IObjectReference obj) => (obj != null) ? new IContextCallback(obj) : null;
public static implicit operator IContextCallback(ObjectReference<Vftbl> obj) => (obj != null) ? new IContextCallback(obj) : null;
protected readonly ObjectReference<Vftbl> _obj;
public IntPtr ThisPtr => _obj.ThisPtr;
public ObjectReference<I> AsInterface<I>() => _obj.As<I>();
public A As<A>() => _obj.AsType<A>();
public IContextCallback(IObjectReference obj) : this(obj.As<Vftbl>()) { }
public IContextCallback(ObjectReference<Vftbl> obj)
{
_obj = obj;
}
private unsafe struct ContextCallData
{
public IntPtr delegateHandle;
public ComCallData* userData;
}
private const int RPC_E_DISCONNECTED = unchecked((int)0x80010108);
public unsafe void ContextCallback(global::WinRT.Interop.PFNCONTEXTCALL pfnCallback, ComCallData* pParam, Guid riid, int iMethod)
{
var callback = Marshal.GetFunctionPointerForDelegate(pfnCallback);
var result = _obj.Vftbl.ContextCallback_4(ThisPtr, callback, pParam, &riid, iMethod, IntPtr.Zero);
GC.KeepAlive(pfnCallback);
if (result != RPC_E_DISCONNECTED)
{
Marshal.ThrowExceptionForHR(result);
}
}
}
}