Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ComActivator.cs
Go to the documentation of this file.
1using System;
4using System.IO;
9
11
12[SupportedOSPlatform("windows")]
13public static class ComActivator
14{
15 [ComVisible(true)]
16 private sealed class BasicClassFactory : IClassFactory
17 {
18 private readonly Guid _classId;
19
21 private readonly Type _classType;
22
28
30 {
32 {
33 return typeof(object);
34 }
35 if (outer != null)
36 {
37 throw new COMException(string.Empty, -2147221232);
38 }
39 Type[] interfaces = classType.GetInterfaces();
40 foreach (Type type in interfaces)
41 {
42 if (type.GUID == riid)
43 {
44 return type;
45 }
46 }
47 throw new InvalidCastException();
48 }
49
63
77
78 [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
89
90 public void LockServer([MarshalAs(UnmanagedType.Bool)] bool fLock)
91 {
92 }
93 }
94
95 [ComVisible(true)]
97 {
99
100 private readonly Guid _classId;
101
103 private readonly Type _classType;
104
110
111 [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
116
117 public void LockServer([MarshalAs(UnmanagedType.Bool)] bool fLock)
118 {
119 }
120
122 {
124 licInfo.cbLicInfo = 12;
125 licInfo.fRuntimeKeyAvail = runtimeKeyAvail;
126 licInfo.fLicVerified = licVerified;
127 }
128
129 public void RequestLicKey(int dwReserved, [MarshalAs(UnmanagedType.BStr)] out string pBstrKey)
130 {
132 }
133
138
149 }
150
152
153 [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
155 {
157 {
159 }
160 if (cxt.InterfaceId != typeof(IClassFactory).GUID && cxt.InterfaceId != typeof(IClassFactory2).GUID)
161 {
162 throw new NotSupportedException();
163 }
164 if (!Path.IsPathRooted(cxt.AssemblyPath))
165 {
166 throw new ArgumentException(null, "cxt");
167 }
168 Type type = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
170 {
171 return new LicenseClassFactory(cxt.ClassId, type);
172 }
173 return new BasicClassFactory(cxt.ClassId, type);
174 }
175
176 [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
178 {
180 {
182 }
183 string text = (register ? "ComRegisterFunctionAttribute" : "ComUnregisterFunctionAttribute");
184 Type type = Type.GetType("System.Runtime.InteropServices." + text + ", System.Runtime.InteropServices", throwOnError: false);
185 if (type == null)
186 {
187 return;
188 }
189 if (!Path.IsPathRooted(cxt.AssemblyPath))
190 {
191 throw new ArgumentException(null, "cxt");
192 }
193 Type type2 = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
194 Type type3 = type2;
195 bool flag = false;
196 while (type3 != null && !flag)
197 {
198 MethodInfo[] methods = type3.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
200 foreach (MethodInfo methodInfo in array)
201 {
202 if (methodInfo.GetCustomAttributes(type, inherit: true).Length != 0)
203 {
204 if (!methodInfo.IsStatic)
205 {
206 string resourceFormat = (register ? SR.InvalidOperation_NonStaticComRegFunction : SR.InvalidOperation_NonStaticComUnRegFunction);
208 }
209 ParameterInfo[] parameters = methodInfo.GetParameters();
210 if (methodInfo.ReturnType != typeof(void) || parameters == null || parameters.Length != 1 || (parameters[0].ParameterType != typeof(string) && parameters[0].ParameterType != typeof(Type)))
211 {
212 string resourceFormat2 = (register ? SR.InvalidOperation_InvalidComRegFunctionSig : SR.InvalidOperation_InvalidComUnRegFunctionSig);
214 }
215 if (flag)
216 {
217 string resourceFormat3 = (register ? SR.InvalidOperation_MultipleComRegFunctions : SR.InvalidOperation_MultipleComUnRegFunctions);
219 }
220 object[] array2 = new object[1];
221 if (parameters[0].ParameterType == typeof(string))
222 {
223 array2[0] = $"HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\CLSID\\{cxt.ClassId:B}";
224 }
225 else
226 {
227 array2[0] = type2;
228 }
229 methodInfo.Invoke(null, array2);
230 flag = true;
231 }
232 }
233 type3 = type3.BaseType;
234 }
235 }
236
237 [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
238 [CLSCompliant(false)]
263
264 [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
265 [CLSCompliant(false)]
268 {
270 {
272 }
274 if (IsLoggingEnabled())
275 {
276 }
277 if (reference.InterfaceId != Guid.Empty || reference.ClassFactoryDest != IntPtr.Zero)
278 {
279 throw new ArgumentException(null, "pCxtInt");
280 }
281 try
282 {
284 ClassRegistrationScenarioForType(cxt, register: true);
285 }
286 catch (Exception ex)
287 {
288 return ex.HResult;
289 }
290 return 0;
291 }
292
293 [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
294 [CLSCompliant(false)]
297 {
299 {
301 }
303 if (IsLoggingEnabled())
304 {
305 }
306 if (reference.InterfaceId != Guid.Empty || reference.ClassFactoryDest != IntPtr.Zero)
307 {
308 throw new ArgumentException(null, "pCxtInt");
309 }
310 try
311 {
313 ClassRegistrationScenarioForType(cxt, register: false);
314 }
315 catch (Exception ex)
316 {
317 return ex.HResult;
318 }
319 return 0;
320 }
321
322 private static bool IsLoggingEnabled()
323 {
324 return false;
325 }
326
327 [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
328 private static Type FindClassType(Guid clsid, string assemblyPath, string assemblyName, string typeName)
329 {
330 try
331 {
334 Assembly assembly = aLC.LoadFromAssemblyName(assemblyName2);
335 Type type = assembly.GetType(typeName);
336 if (type != null)
337 {
338 return type;
339 }
340 }
341 catch (Exception)
342 {
343 if (!IsLoggingEnabled())
344 {
345 }
346 }
347 throw new COMException(string.Empty, -2147221231);
348 }
349
350 [RequiresUnreferencedCode("The trimmer might remove types which are needed by the assemblies loaded in this method.")]
352 {
355 {
356 if (!s_assemblyLoadContexts.TryGetValue(assemblyPath, out value))
357 {
360 }
361 }
362 return value;
363 }
364}
static object CreateAggregatedObject(object pUnkOuter, object comObject)
BasicClassFactory(Guid clsid, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type classType)
static IntPtr GetObjectAsInterface(object obj, Type interfaceType)
void CreateInstance([MarshalAs(UnmanagedType.Interface)] object pUnkOuter, ref Guid riid, out IntPtr ppvObject)
static Type GetValidatedInterfaceType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type classType, ref Guid riid, object outer)
void LockServer([MarshalAs(UnmanagedType.Bool)] bool fLock)
LicenseClassFactory(Guid clsid, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.Interfaces)] Type classType)
void CreateInstanceInner(object pUnkOuter, ref Guid riid, string key, bool isDesignTime, out IntPtr ppvObject)
void LockServer([MarshalAs(UnmanagedType.Bool)] bool fLock)
void RequestLicKey(int dwReserved, [MarshalAs(UnmanagedType.BStr)] out string pBstrKey)
void CreateInstanceLic([MarshalAs(UnmanagedType.Interface)] object pUnkOuter, [MarshalAs(UnmanagedType.Interface)] object pUnkReserved, ref Guid riid, [MarshalAs(UnmanagedType.BStr)] string bstrKey, out IntPtr ppvObject)
void CreateInstance([MarshalAs(UnmanagedType.Interface)] object pUnkOuter, ref Guid riid, out IntPtr ppvObject)
static unsafe int RegisterClassForTypeInternal(ComActivationContextInternal *pCxtInt)
static readonly Dictionary< string, AssemblyLoadContext > s_assemblyLoadContexts
static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInternal *pCxtInt)
static unsafe int UnregisterClassForTypeInternal(ComActivationContextInternal *pCxtInt)
static AssemblyLoadContext GetALC(string assemblyPath)
static Type FindClassType(Guid clsid, string assemblyPath, string assemblyName, string typeName)
static void ClassRegistrationScenarioForType(ComActivationContext cxt, bool register)
static object GetClassFactoryForType(ComActivationContext cxt)
void GetLicInfo(Type type, out bool runtimeKeyAvail, out bool licVerified)
object AllocateAndValidateLicense([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type, string key, bool isDesignTime)
static ? object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
Definition Activator.cs:17
static bool IsPathRooted([NotNullWhen(true)] string? path)
Definition Path.cs:985
static IntPtr GetComInterfaceForObject(object o, Type T)
Definition Marshal.cs:257
static unsafe int Release(IntPtr pUnk)
Definition Marshal.cs:766
static object GetObjectForIUnknown(IntPtr pUnk)
Definition Marshal.cs:295
static IntPtr GetIUnknownForObject(object o)
Definition Marshal.cs:231
static IntPtr CreateAggregatedObject(IntPtr pOuter, object o)
Definition Marshal.cs:325
static void WriteIntPtr(IntPtr ptr, int ofs, IntPtr val)
Definition Marshal.cs:1096
static string NotSupported_COM
Definition SR.cs:2190
static string InvalidOperation_MultipleComUnRegFunctions
Definition SR.cs:2128
static string InvalidOperation_NonStaticComUnRegFunction
Definition SR.cs:2120
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string InvalidOperation_InvalidComUnRegFunctionSig
Definition SR.cs:2124
Definition SR.cs:7
static StringComparer InvariantCultureIgnoreCase
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
static unsafe ComActivationContext Create(ref ComActivationContextInternal cxtInt)
static readonly Guid Empty
Definition Guid.cs:86
static readonly IntPtr Zero
Definition IntPtr.cs:18