/// <summary> /// Internal entry point for unmanaged COM activation API from native code /// </summary> /// <param name="cxtInt">Reference to a <see cref="ComActivationContextInternal"/> instance</param> public static int GetClassFactoryForTypeInternal(ref ComActivationContextInternal cxtInt) { if (IsLoggingEnabled()) { Log( $@"{nameof(GetClassFactoryForTypeInternal)} arguments: {cxtInt.ClassId} {cxtInt.InterfaceId} 0x{cxtInt.AssemblyNameBuffer.ToInt64():x} 0x{cxtInt.TypeNameBuffer.ToInt64():x} 0x{cxtInt.ClassFactoryDest.ToInt64():x}"); } try { var cxt = new ComActivationContext() { ClassId = cxtInt.ClassId, InterfaceId = cxtInt.InterfaceId, AssemblyName = Marshal.PtrToStringUTF8(cxtInt.AssemblyNameBuffer), TypeName = Marshal.PtrToStringUTF8(cxtInt.TypeNameBuffer) }; object cf = GetClassFactoryForType(cxt); IntPtr nativeIUnknown = Marshal.GetIUnknownForObject(cf); Marshal.WriteIntPtr(cxtInt.ClassFactoryDest, nativeIUnknown); } catch (Exception e) { return(e.HResult); } return(0); }
/// <summary> /// Entry point for unmanaged COM activation API from managed code /// </summary> /// <param name="cxt">Reference to a <see cref="ComActivationContext"/> instance</param> public static object GetClassFactoryForType(ComActivationContext cxt) { if (cxt.InterfaceId != typeof(IClassFactory).GUID && cxt.InterfaceId != typeof(IClassFactory2).GUID) { throw new NotSupportedException(); } Type classType = FindClassType(cxt.ClassId, cxt.AssemblyName, cxt.TypeName); return(new BasicClassFactory(cxt.ClassId, classType)); }