Beispiel #1
0
        /// <summary>
        ///     UnRegisterComClasses is called to revoke the registration of the COM
        ///     classes exposed from the server, and perform the cleanups.
        /// </summary>
        public void UnRegisterComClasses()
        {
            /////////////////////////////////////////////////////////////////
            // Revoke the registration of the COM classes.
            //

            // Revoke the registration of AppInstance
            if (_cookieComAccessProvider != 0)
            {
                ComNative.CoRevokeClassObject(_cookieComAccessProvider);
            }
            // Revoke the registration of other classes
            // ...
        }
Beispiel #2
0
        /// <summary>
        ///     RegisterComClasses 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 (e.g. _nLockCnt).
        /// </summary>
        public void RegisterComClasses()
        {
            //
            // Register the COM class factories.
            //

            var clsidComAccessProvider = ComIds.CLSID_ComAccessProvider;
            var hResult = ComNative.CoRegisterClassObject(
                ref clsidComAccessProvider,          // CLSID to be registered
                new ComAccessProviderClassFactory(), // Class factory
                CLSCTX.LOCAL_SERVER,                 // Context to run
                REGCLS.MULTIPLEUSE | REGCLS.SUSPENDED,
                out _cookieComAccessProvider);

            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 = ComNative.CoResumeClassObjects();
            if (hResult != 0)
            {
                if (_cookieComAccessProvider != 0)
                {
                    ComNative.CoRevokeClassObject(_cookieComAccessProvider);
                }

                // Revoke the registration of other classes
                // ...

                throw new ApplicationException("CoResumeClassObjects failed w/err 0x" + hResult.ToString("X"));
            }

            // Records the count of the active COM objects in the server.
            // When _nLockCnt drops to zero, the server can be shut down.
            _nLockCnt = 0;
        }