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."); } }
public SingletonClassFactoryRegistration(object instance, CLSID clsId) { _instance = instance; SingletonClassFactory factory = new SingletonClassFactory(instance); IntPtr pFactory = Marshal.GetIUnknownForObject(factory); // In versions < 0.29 we registered as REGCLS_SINGLEUSE even though it is not supposed to work for inproc servers. // It seems to do no harm to keep the ClassObject around. HRESULT result = ComAPI.CoRegisterClassObject(ref clsId, pFactory, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, out _classRegister); if (result != ComAPI.S_OK) { throw new InvalidOperationException("CoRegisterClassObject failed."); } }