Ejemplo n.º 1
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();
            }

            if (!Path.IsPathRooted(cxt.AssemblyPath))
            {
                throw new ArgumentException();
            }

            Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);

            return(new BasicClassFactory(cxt.ClassId, classType));
        }
Ejemplo n.º 2
0
        public unsafe static int GetClassFactoryForTypeInternal(ref ComActivationContextInternal cxtInt)
        {
            if (IsLoggingEnabled())
            {
                Log(
                    $@"{nameof(GetClassFactoryForTypeInternal)} arguments:
    {cxtInt.ClassId}
    {cxtInt.InterfaceId}
    0x{(ulong)cxtInt.AssemblyPathBuffer:x}
    0x{(ulong)cxtInt.AssemblyNameBuffer:x}
    0x{(ulong)cxtInt.TypeNameBuffer:x}
    0x{cxtInt.ClassFactoryDest.ToInt64():x}");
            }

            try
            {
                var cxt = new ComActivationContext()
                {
                    ClassId      = cxtInt.ClassId,
                    InterfaceId  = cxtInt.InterfaceId,
                    AssemblyPath = Marshal.PtrToStringUni(new IntPtr(cxtInt.AssemblyPathBuffer)),
                    AssemblyName = Marshal.PtrToStringUni(new IntPtr(cxtInt.AssemblyNameBuffer)),
                    TypeName     = Marshal.PtrToStringUni(new IntPtr(cxtInt.TypeNameBuffer))
                };

                object cf             = GetClassFactoryForType(cxt);
                IntPtr nativeIUnknown = Marshal.GetIUnknownForObject(cf);
                Marshal.WriteIntPtr(cxtInt.ClassFactoryDest, nativeIUnknown);
            }
            catch (Exception e)
            {
                return(e.HResult);
            }

            return(0);
        }
 // Exists here to allow tests to build on any platform.
 public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bool register)
 => throw new PlatformNotSupportedException();
 // Exists here to allow tests to build on any platform.
 public static object GetClassFactoryForType(ComActivationContext cxt)
 => throw new PlatformNotSupportedException();