示例#1
0
        /// <summary>
        /// ROTからオブジェクトを削除する。
        /// </summary>
        public void Revoke()
        {
            if (register != null)
            {
                int hresult;
                System.Runtime.InteropServices.ComTypes.IRunningObjectTable rot = null;

                try
                {
                    hresult = GetRunningObjectTable(0, out rot);
                    if (hresult < 0)
                    {
                        throw new COMException("GetRunningObjectTable failed.", hresult);
                    }
                    rot.Revoke((int)register);
                    register = null;
                }
                finally
                {
                    if (rot != null)
                    {
                        Marshal.ReleaseComObject(rot);
                    }
                }
            }
        }
示例#2
0
        private void RegisterCommandDispatcherinROT()
        {
            int hResult;

            System.Runtime.InteropServices.ComTypes.IBindCtx bc;
            hResult = NativeMethods.CreateBindCtx(0, out bc);

            if (hResult == NativeMethods.S_OK && bc != null)
            {
                System.Runtime.InteropServices.ComTypes.IRunningObjectTable rot = GetRunningObjectTable();
                Validate.IsNotNull(rot, "rot");

                string delim  = "!";
                string progID = GetProgID(typeof(SUIHostCommandDispatcher));

                System.Runtime.InteropServices.ComTypes.IMoniker moniker;
                hResult = NativeMethods.CreateItemMoniker(delim, progID, out moniker);
                Validate.IsNotNull(moniker, "moniker");

                if (hResult == NativeMethods.S_OK)
                {
                    var serviceProvider = ServiceProvider.GlobalProvider;

                    var suiHost = serviceProvider.GetService(typeof(SUIHostCommandDispatcher));
                    hResult = rot.Register(NativeMethods.ROTFLAGS_REGISTRATIONKEEPSALIVE, suiHost, moniker);
                }
            }
        }
示例#3
0
        private object GetObjectFromRot(System.Runtime.InteropServices.ComTypes.IRunningObjectTable rot, System.Runtime.InteropServices.ComTypes.IMoniker moniker)
        {
            object objectFromRot;
            int    hr = rot.GetObject(moniker, out objectFromRot);

            if (ErrorHandler.Failed(hr))
            {
                ErrorHandler.ThrowOnFailure(hr, null);
            }

            return(objectFromRot);
        }
示例#4
0
        /// <summary>
        /// ROTにオブジェクトを登録する。
        /// </summary>
        /// <param name="iUnknownObject">オブジェクト</param>
        /// <param name="name">名前</param>
        public RunningObjectTableEntry(object iUnknownObject, string name)
        {
            int       hresult;
            const int ROTFLAGS_REGISTRATIONKEEPSALIVE = 1;

            System.Runtime.InteropServices.ComTypes.IRunningObjectTable rot     = null;
            System.Runtime.InteropServices.ComTypes.IMoniker            moniker = null;

            try
            {
                hresult = GetRunningObjectTable(0, out rot);
                if (hresult < 0)
                {
                    throw new COMException("GetRunningObjectTable failed.", hresult);
                }

                string wsz = string.Format("{0} {1:x16} pid {2:x8}",
                                           name,
                                           Marshal.GetIUnknownForObject(iUnknownObject).ToInt64(),
                                           System.Diagnostics.Process.GetCurrentProcess().Id);

                hresult = CreateItemMoniker("!", wsz, out moniker);
                if (hresult < 0)
                {
                    throw new COMException("CreateItemMoniker failed.", hresult);
                }

                int register = rot.Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, iUnknownObject, moniker);
                this.register = register;
            }
            finally
            {
                if (moniker != null)
                {
                    Marshal.ReleaseComObject(moniker);
                }
                if (rot != null)
                {
                    Marshal.ReleaseComObject(rot);
                }
            }
        }
        /// <summary>
        /// Permet de retirer notre instance de la ROT et donc de ne plus être notifié des Autoplay
        /// </summary>
        /// <remarks></remarks>
        public void UnregisterAutoplayMonitor()
        {
            //si on n'est pas dans la ROT, on ne fait rien
            if (!this.IsRunning)
            {
                return;
            }

            //on récupère l'interface d'accès à la Running Object Table
            System.Runtime.InteropServices.ComTypes.IRunningObjectTable rot = null;
            int ret = GetRunningObjectTable(0, rot);

            if (ret != 0)
            {
                Marshal.ThrowExceptionForHR(ret);
            }

            //retirer notre instance
            rot.Revoke(m_RegisterNumber);
            this.m_IsRunning = false;
        }
示例#6
0
 static extern int GetRunningObjectTable(uint reserved,
                                         out System.Runtime.InteropServices.ComTypes.IRunningObjectTable pprot);
 private static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot);
 private static extern void GetRunningObjectTable(int reserved,
                                                  out System.Runtime.InteropServices.ComTypes.IRunningObjectTable prot);