Ejemplo n.º 1
0
        public int RegisterObject(object obj, string stringId)
        {
            int regId = -1;

            System.Runtime.InteropServices.ComTypes.IRunningObjectTable pROT     = null;
            System.Runtime.InteropServices.ComTypes.IMoniker            pMoniker = null;

            int hr;

            if ((hr = NativeMethods.GetRunningObjectTable((uint)0, out pROT)) != 0)
            {
                return(hr);
            }

            // File Moniker has to be used because in VBS GetObject only works with file monikers in the ROT
            if ((hr = NativeMethods.CreateFileMoniker(stringId, out pMoniker)) != 0)
            {
                return(hr);
            }


            regId = pROT.Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, obj, pMoniker);

            _RegisteredObjects.Add(new ObjectInRot(obj, regId));

            return(0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This allows us to register an object in the Running Object Table
        /// </summary>
        /// <param name="obj">A Com interface pointer owned by the object</param>
        /// <param name="stringId">A display name for the object</param>
        /// <returns>Returns two integers as an array, the first is the HRESULT of system calls and if successful the second is the registration id (regid).  You'll need the regid to revoke from the ROT when tidying up.</returns>
        public int[] RegisterObject(object obj, string stringId)
        {
            int[] retval = new int[] { 0, 0 };
            int   regId  = -1;

            System.Runtime.InteropServices.ComTypes.IRunningObjectTable pROT     = null;
            System.Runtime.InteropServices.ComTypes.IMoniker            pMoniker = null;
            int hr;

            if ((hr = RotNativeMethods.GetRunningObjectTable((int)0, out pROT)) != 0)
            {
                retval[0] = hr;
                return(retval);    //(hr);
            }
            // File Moniker has to be used because in VBS GetObject only works with file monikers in the ROT
            if ((hr = RotNativeMethods.CreateFileMoniker(stringId, out pMoniker)) != 0)
            {
                retval[0] = hr;
                return(retval);    //(hr);
            }
            int ROTFLAGS_REGISTRATIONKEEPSALIVE = 1;

            regId     = pROT.Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, obj, pMoniker);
            retval[0] = 0;
            retval[1] = regId;
            return(retval);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Erzeugt eine neue Anmeldung.
        /// </summary>
        /// <param name="comObject">Ein beliebiges Objekt.</param>
        /// <exception cref="ArgumentNullException">Es wurde kein Objekt angegeben.</exception>
        public ROTRegister(object comObject)
        {
            // Validate
            if (comObject == null)
            {
                throw new ArgumentNullException("comObject");
            }

            // Attach to ROT
            if (GetRunningObjectTable(0, out m_ROT) < 0)
            {
                return;
            }

            // Attach to COM interface
            IntPtr unk = Marshal.GetIUnknownForObject(comObject);

            try
            {
                // Create the name
                string moniker = string.Format("FilterGraph {0:x8} pid {1:x8}", unk.ToInt32(), Process.GetCurrentProcess().Id);

                // Create the item moniker for the format
                comTypes.IMoniker mon;
                if (CreateItemMoniker("!", moniker, out mon) >= 0)
                {
                    try
                    {
                        // Register
                        m_Register = m_ROT.Register(1, comObject, mon);
                    }
                    finally
                    {
                        // Back to COM
                        BDAEnvironment.Release(ref mon);
                    }
                }
            }
            finally
            {
                // Back to COM
                BDAEnvironment.Release(ref unk);
            }
        }