示例#1
0
 private void RevokeRegistrations()
 {
     // Revoke the registration of the COM classes.
     _registrationCookies.TryForEach(cookie =>
     {
         ActiveXNative.CoRevokeClassObject(cookie);
     });
 }
示例#2
0
        private bool PreMessageLoop()
        {
            int hResult = 0;

            _comServers.GetServers().TryForEach(comServer =>
            {
                uint comRegCookie;

                Guid clsidSimpleObj = comServer.ClassID;

                // Register the SimpleObject class object
                hResult = ActiveXNative.CoRegisterClassObject(
                    ref clsidSimpleObj,                                // CLSID to be registered
                    new DefaultActiveXFactory(comServer, _comServers), // Class factory
                    CLSCTX.LOCAL_SERVER,                               // Context to run
                    REGCLS.MULTIPLEUSE | REGCLS.SUSPENDED,
                    out comRegCookie);

                if (hResult != 0)
                {
                    throw new ApplicationException("CoRegisterClassObject failed w/err 0x" + hResult.ToString("X"));
                }
                else
                {
                    _registrationCookies.Add(comRegCookie);
                }
            });

            // Inform the SCM about all the registered classes, and begins
            // letting activation requests into the server process.
            hResult = ActiveXNative.CoResumeClassObjects();
            if (hResult != 0)
            {
                RevokeRegistrations();
                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;

            // Start the GC timer to trigger GC every 5 seconds.
            _gcTimer = new System.Threading.Timer(new TimerCallback(GarbageCollect), null, 5000, 5000);
            return(false);
        }