/// <summary> /// PreMessageLoop is responsible for registering the COM class /// factories for the COM classes to be exposed from the server, and /// initializing the key member variables of the COM server. /// </summary> private void Register() { // // Register the COM class factories. // var clsidSimpleObj = new Guid(SimpleObjectId.ClassId); // Register the SimpleObject class object var factory = new SimpleObjectClassFactory(); factory.NoReferenceEvent += _reference_NoReferenceEvent; int hResult = NativeMethods.CoRegisterClassObject( ref clsidSimpleObj, // CLSID to be registered factory, CLSCTX.LOCAL_SERVER, // Context to run REGCLS.MULTIPLEUSE | REGCLS.SUSPENDED, out _cookieSimpleObj); if (hResult != 0) { throw new ApplicationException( "CoRegisterClassObject failed w/err 0x" + hResult.ToString("X")); } // Register other class objects // ... // Inform the SCM about all the registered classes, and begins // letting activation requests into the server process. hResult = NativeMethods.CoResumeClassObjects(); if (hResult != 0) { // Revoke the registration of SimpleObject on failure if (_cookieSimpleObj != 0) { NativeMethods.CoRevokeClassObject(_cookieSimpleObj); } // Revoke the registration of other classes // ... throw new ApplicationException( "CoResumeClassObjects failed w/err 0x" + hResult.ToString("X")); } }
/// <summary> /// PreMessageLoop is responsible for registering the COM class /// factories for the COM classes to be exposed from the server, and /// initializing the key member variables of the COM server. /// </summary> private void Register() { // // Register the COM class factories. // var clsidSimpleObj = new Guid(SimpleObjectId.ClassId); // Register the SimpleObject class object var factory = new SimpleObjectClassFactory(); factory.NoReferenceEvent += _reference_NoReferenceEvent; int hResult = NativeMethods.CoRegisterClassObject( ref clsidSimpleObj, // CLSID to be registered factory, CLSCTX.LOCAL_SERVER, // Context to run REGCLS.MULTIPLEUSE | REGCLS.SUSPENDED, out _cookieSimpleObj); if (hResult != 0) { throw new ApplicationException( "CoRegisterClassObject failed w/err 0x" + hResult.ToString("X")); } // Register other class objects // ... // Inform the SCM about all the registered classes, and begins // letting activation requests into the server process. hResult = NativeMethods.CoResumeClassObjects(); if (hResult != 0) { // Revoke the registration of SimpleObject on failure if (_cookieSimpleObj != 0) { NativeMethods.CoRevokeClassObject(_cookieSimpleObj); } // Revoke the registration of other classes // ... throw new ApplicationException( "CoResumeClassObjects failed w/err 0x" + hResult.ToString("X")); } }