-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathIInspectable.cs
168 lines (152 loc) · 6.31 KB
/
IInspectable.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using WinRT.Interop;
namespace WinRT
{
#if EMBED
internal
#else
public
#endif
enum TrustLevel
{
BaseTrust = 0,
PartialTrust = BaseTrust + 1,
FullTrust = PartialTrust + 1
}
// IInspectable
#if !NET
[global::WinRT.ObjectReferenceWrapper(nameof(_obj))]
#endif
[Guid("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90")]
#if EMBED
internal
#else
public
#endif
partial class IInspectable
{
[Guid("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90")]
public unsafe struct Vftbl
{
public IUnknownVftbl IUnknownVftbl;
private void* _GetIids;
public delegate* unmanaged[Stdcall]<IntPtr, int*, IntPtr*, int> GetIids { get => (delegate* unmanaged[Stdcall]<IntPtr, int*, IntPtr*, int>)_GetIids; set => _GetIids = (void*)value; }
private void* _GetRuntimeClassName;
public delegate* unmanaged[Stdcall]<IntPtr, IntPtr*, int> GetRuntimeClassName { get => (delegate* unmanaged[Stdcall]<IntPtr, IntPtr*, int>)_GetRuntimeClassName; set => _GetRuntimeClassName = (void*)value; }
private void* _GetTrustLevel;
public delegate* unmanaged[Stdcall]<IntPtr, TrustLevel*, int> GetTrustLevel { get => (delegate* unmanaged[Stdcall]<IntPtr, TrustLevel*, int>)_GetTrustLevel; set => _GetTrustLevel = (void*)value; }
public static readonly Vftbl AbiToProjectionVftable;
public static readonly IntPtr AbiToProjectionVftablePtr;
#if !NET
private static readonly Delegate[] DelegateCache = new Delegate[3];
private delegate int _GetIidsDelegate(IntPtr pThis, int* iidCount, IntPtr* iids);
private delegate int _GetRuntimeClassNameDelegate(IntPtr pThis, IntPtr* className);
private delegate int _GetTrustLevelDelegate(IntPtr pThis, TrustLevel* trustLevel);
#endif
static Vftbl()
{
AbiToProjectionVftable = new Vftbl
{
IUnknownVftbl = IUnknownVftbl.AbiToProjectionVftbl,
#if !NET
_GetIids = (void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[0] = new _GetIidsDelegate(Do_Abi_GetIids)),
_GetRuntimeClassName = (void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[1] = new _GetRuntimeClassNameDelegate(Do_Abi_GetRuntimeClassName)),
_GetTrustLevel = (void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[2] = new _GetTrustLevelDelegate(Do_Abi_GetTrustLevel))
#else
_GetIids = (void*)(delegate* unmanaged<IntPtr, int*, IntPtr*, int>)&Do_Abi_GetIids,
_GetRuntimeClassName = (void*)(delegate* unmanaged<IntPtr, IntPtr*, int>)&Do_Abi_GetRuntimeClassName,
_GetTrustLevel = (void*)(delegate* unmanaged<IntPtr, TrustLevel*, int>)&Do_Abi_GetTrustLevel
#endif
};
AbiToProjectionVftablePtr = Marshal.AllocHGlobal(sizeof(Vftbl));
Marshal.StructureToPtr(AbiToProjectionVftable, AbiToProjectionVftablePtr, false);
}
#if NET
[UnmanagedCallersOnly]
#endif
private static int Do_Abi_GetIids(IntPtr pThis, int* iidCount, IntPtr* iids)
{
*iidCount = 0;
*iids = IntPtr.Zero;
try
{
(*iidCount, *iids) = MarshalBlittable<Guid>.FromManagedArray(ComWrappersSupport.GetInspectableInfo(pThis).IIDs);
}
catch (Exception ex)
{
return ex.HResult;
}
return 0;
}
#if NET
[UnmanagedCallersOnly]
#endif
private unsafe static int Do_Abi_GetRuntimeClassName(IntPtr pThis, IntPtr* className)
{
*className = default;
try
{
string runtimeClassName = ComWrappersSupport.GetInspectableInfo(pThis).RuntimeClassName;
*className = MarshalString.FromManaged(runtimeClassName);
}
catch (Exception ex)
{
return ex.HResult;
}
return 0;
}
#if NET
[UnmanagedCallersOnly]
#endif
private static int Do_Abi_GetTrustLevel(IntPtr pThis, TrustLevel* trustLevel)
{
*trustLevel = TrustLevel.BaseTrust;
return 0;
}
}
public static IInspectable FromAbi(IntPtr thisPtr) =>
new IInspectable(ObjectReference<Vftbl>.FromAbi(thisPtr, IID.IID_IInspectable));
private readonly ObjectReference<Vftbl> _obj;
public IntPtr ThisPtr => _obj.ThisPtr;
public static implicit operator IInspectable(IObjectReference obj) => obj.As<Vftbl>();
public static implicit operator IInspectable(ObjectReference<Vftbl> obj) => new IInspectable(obj);
#if NET
[Obsolete(AttributeMessages.GenericDeprecatedMessage)]
[EditorBrowsable(EditorBrowsableState.Never)]
[UnconditionalSuppressMessage("Trimming", "IL2091", Justification = AttributeMessages.GenericRequiresUnreferencedCodeMessage)]
#endif
public ObjectReference<I> As<I>() => _obj.As<I>();
public IObjectReference ObjRef { get => _obj; }
public IInspectable(IObjectReference obj) : this(obj.As<Vftbl>()) { }
public IInspectable(ObjectReference<Vftbl> obj)
{
_obj = obj;
}
public unsafe string GetRuntimeClassName(bool noThrow = false)
{
IntPtr __retval = default;
try
{
var hr = _obj.Vftbl.GetRuntimeClassName(ThisPtr, &__retval);
if (hr != 0)
{
if (noThrow)
return null;
Marshal.ThrowExceptionForHR(hr);
}
uint length;
char* buffer = Platform.WindowsGetStringRawBuffer(__retval, &length);
return new string(buffer, 0, (int)length);
}
finally
{
Platform.WindowsDeleteString(__retval);
}
}
}
}