Inheritance: ComAPI.IClassFactory
        public ClassFactoryRegistration(Type type, CLSID clsId)
        {
            ClassFactory factory = new ClassFactory(type);
            IntPtr pFactory = Marshal.GetIUnknownForObject(factory);
            HRESULT result = ComAPI.CoRegisterClassObject(ref clsId, pFactory,
                                CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, out _classRegister);

            if (result != ComAPI.S_OK)
            {
                throw new InvalidOperationException("CoRegisterClassObject failed.");
            }
        }
Esempio n. 2
0
 internal static HRESULT DllGetClassObject(CLSID clsid, IID iid, out IntPtr ppunk)
 {
     if (iid != ComAPI.guidIClassFactory)
     {
         ppunk = IntPtr.Zero;
         return ComAPI.E_INVALIDARG;
     }
     foreach (ExcelComClassType comClass in registeredComClassTypes)
     {
        if (comClass.ClsId == clsid)
        {
            ClassFactory factory = new ClassFactory(comClass);
            IntPtr punkFactory = Marshal.GetIUnknownForObject(factory);
            HRESULT hrQI = Marshal.QueryInterface(punkFactory, ref iid, out ppunk);
            Marshal.Release(punkFactory);
            if (hrQI == ComAPI.S_OK)
            {
                return ComAPI.S_OK;
            }
            else
            {
                return ComAPI.E_UNEXPECTED;
            }
        }
     }
     ppunk = IntPtr.Zero;
     return ComAPI.CLASS_E_CLASSNOTAVAILABLE;
 }
Esempio n. 3
0
 static bool TryGetComClassType(CLSID clsId, out ComAPI.IClassFactory factory)
 {
     // Check among the persistently registered classes
     foreach (ExcelComClassType comClass in registeredComClassTypes)
     {
         if (comClass.ClsId == clsId)
         {
             factory = new ClassFactory(comClass);
             return true;
         }
     }
     factory = null;
     return false;
 }