예제 #1
0
        public IntPtr CreateInstance(CLSCTX dwContext, string server)
        {
            IntPtr pInterface = IntPtr.Zero;

            if (dwContext == CLSCTX.ALL)
            {
                if (DefaultServerType == COMServerType.InProcServer32)
                {
                    dwContext = CLSCTX.INPROC_SERVER;
                }
                else if (DefaultServerType == COMServerType.LocalServer32)
                {
                    dwContext = CLSCTX.LOCAL_SERVER;
                }
                else if (DefaultServerType == COMServerType.InProcHandler32)
                {
                    dwContext = CLSCTX.INPROC_HANDLER;
                }
                else
                {
                    dwContext = CLSCTX.SERVER;
                }
            }

            Guid iid = COMInterfaceEntry.CreateKnownInterface(m_registry, COMInterfaceEntry.KnownInterfaces.IUnknown).Iid;

            return(COMUtilities.CreateInstance(Clsid, iid, dwContext, server));
        }
예제 #2
0
        private void LoadInterfaces(RegistryKey rootKey, ActivationContext actctx, bool load_runtime_intfs)
        {
            Dictionary <Guid, COMInterfaceEntry> interfaces = new Dictionary <Guid, COMInterfaceEntry>();

            foreach (COMInterfaceEntry.KnownInterfaces known_infs in Enum.GetValues(typeof(COMInterfaceEntry.KnownInterfaces)))
            {
                COMInterfaceEntry unk = COMInterfaceEntry.CreateKnownInterface(this, known_infs);
                interfaces.Add(unk.Iid, unk);
            }

            if (actctx != null)
            {
                foreach (var intf in actctx.ComInterfaces)
                {
                    interfaces[intf.Iid] = new COMInterfaceEntry(this, intf);
                }
            }

            using (RegistryKey iidKey = rootKey.OpenSubKey("Interface"))
            {
                if (iidKey != null)
                {
                    string[] subkeys = iidKey.GetSubKeyNames();
                    foreach (string key in subkeys)
                    {
                        if (Guid.TryParse(key, out Guid iid))
                        {
                            if (!interfaces.ContainsKey(iid))
                            {
                                using (RegistryKey regKey = iidKey.OpenSubKey(key))
                                {
                                    if (regKey != null)
                                    {
                                        COMInterfaceEntry ent = new COMInterfaceEntry(this, iid, regKey);
                                        interfaces.Add(iid, ent);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (load_runtime_intfs)
            {
                foreach (var pair in COMUtilities.RuntimeInterfaceMetadata)
                {
                    if (!interfaces.ContainsKey(pair.Key))
                    {
                        interfaces.Add(pair.Key, new COMInterfaceEntry(this, pair.Value));
                    }
                    else
                    {
                        interfaces[pair.Key].RuntimeInterface = true;
                    }
                }
            }

            m_interfaces = new SortedDictionary <Guid, COMInterfaceEntry>(interfaces);
        }
예제 #3
0
        /// <summary>
        /// Load interface list from registry
        /// </summary>
        /// <param name="rootKey">Root key of registry</param>
        private void LoadInterfaces(RegistryKey rootKey)
        {
            Dictionary <Guid, COMInterfaceEntry> interfaces = new Dictionary <Guid, COMInterfaceEntry>();
            COMInterfaceEntry unk = COMInterfaceEntry.CreateKnownInterface(COMInterfaceEntry.KnownInterfaces.IUnknown);

            interfaces.Add(unk.Iid, unk);
            unk = COMInterfaceEntry.CreateKnownInterface(COMInterfaceEntry.KnownInterfaces.IMarshal);
            interfaces.Add(unk.Iid, unk);
            using (RegistryKey iidKey = rootKey.OpenSubKey("Interface"))
            {
                if (iidKey != null)
                {
                    string[] subkeys = iidKey.GetSubKeyNames();
                    foreach (string key in subkeys)
                    {
                        Guid iid;

                        if (Guid.TryParse(key, out iid))
                        {
                            if (!interfaces.ContainsKey(iid))
                            {
                                using (RegistryKey regKey = iidKey.OpenSubKey(key))
                                {
                                    if (regKey != null)
                                    {
                                        COMInterfaceEntry ent = new COMInterfaceEntry(iid, regKey);
                                        interfaces.Add(iid, ent);
                                        if (ent.ProxyClsid != Guid.Empty)
                                        {
                                            if (m_clsids.ContainsKey(ent.ProxyClsid))
                                            {
                                                m_clsids[ent.ProxyClsid].AddProxy(ent);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            int pos = 0;

            m_interfacebyname = new COMInterfaceEntry[interfaces.Count];
            foreach (COMInterfaceEntry ent in interfaces.Values)
            {
                m_interfacebyname[pos++] = ent;
            }
            Array.Sort(m_interfacebyname);

            m_interfaces = new SortedDictionary <Guid, COMInterfaceEntry>(interfaces);
        }
예제 #4
0
        /// <summary>
        /// Load interface list from registry
        /// </summary>
        /// <param name="rootKey">Root key of registry</param>
        private void LoadInterfaces(RegistryKey rootKey)
        {
            Dictionary <Guid, COMInterfaceEntry> interfaces = new Dictionary <Guid, COMInterfaceEntry>();

            foreach (COMInterfaceEntry.KnownInterfaces known_infs in Enum.GetValues(typeof(COMInterfaceEntry.KnownInterfaces)))
            {
                COMInterfaceEntry unk = COMInterfaceEntry.CreateKnownInterface(known_infs);
                interfaces.Add(unk.Iid, unk);
            }
            using (RegistryKey iidKey = rootKey.OpenSubKey("Interface"))
            {
                if (iidKey != null)
                {
                    string[] subkeys = iidKey.GetSubKeyNames();
                    foreach (string key in subkeys)
                    {
                        Guid iid;

                        if (Guid.TryParse(key, out iid))
                        {
                            if (!interfaces.ContainsKey(iid))
                            {
                                using (RegistryKey regKey = iidKey.OpenSubKey(key))
                                {
                                    if (regKey != null)
                                    {
                                        COMInterfaceEntry ent = new COMInterfaceEntry(iid, regKey);
                                        interfaces.Add(iid, ent);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            foreach (var pair in COMUtilities.RuntimeInterfaceMetadata)
            {
                if (!interfaces.ContainsKey(pair.Key))
                {
                    interfaces.Add(pair.Key, new COMInterfaceEntry(pair.Value));
                }
            }

            m_interfaces = new SortedDictionary <Guid, COMInterfaceEntry>(interfaces);
        }
예제 #5
0
        public IntPtr CreateInstance(CLSCTX dwContext)
        {
            IntPtr pInterface = IntPtr.Zero;
            bool   blValid    = false;

            if (dwContext == CLSCTX.CLSCTX_ALL)
            {
                if (ServerType == COMServerType.InProcServer32)
                {
                    dwContext = CLSCTX.CLSCTX_INPROC_SERVER;
                    blValid   = true;
                }
                else if (ServerType == COMServerType.LocalServer32)
                {
                    dwContext = CLSCTX.CLSCTX_LOCAL_SERVER;
                    blValid   = true;
                }
            }
            else
            {
                blValid = true;
            }

            if (blValid)
            {
                Guid iid    = COMInterfaceEntry.CreateKnownInterface(COMInterfaceEntry.KnownInterfaces.IUnknown).Iid;
                Guid clsid  = Clsid;
                int  iError = COMUtilities.CoCreateInstance(ref clsid, IntPtr.Zero, dwContext, ref iid, out pInterface);

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

            return(pInterface);
        }
예제 #6
0
        public IntPtr CreateInstance(CLSCTX dwContext, string server)
        {
            IntPtr pInterface = IntPtr.Zero;

            if (dwContext == CLSCTX.ALL)
            {
                if (DefaultServerType == COMServerType.InProcServer32)
                {
                    dwContext = CLSCTX.INPROC_SERVER;
                }
                else if (DefaultServerType == COMServerType.LocalServer32)
                {
                    dwContext = CLSCTX.LOCAL_SERVER;
                }
                else if (DefaultServerType == COMServerType.InProcHandler32)
                {
                    dwContext = CLSCTX.INPROC_HANDLER;
                }
                else
                {
                    dwContext = CLSCTX.SERVER;
                }
            }

            Guid iid   = COMInterfaceEntry.CreateKnownInterface(COMInterfaceEntry.KnownInterfaces.IUnknown).Iid;
            Guid clsid = Clsid;

            int hr = 0;

            if (server != null)
            {
                MULTI_QI[] qis = new MULTI_QI[1];
                qis[0] = new MULTI_QI(iid);
                COSERVERINFO server_info = new COSERVERINFO(server);
                try
                {
                    hr = COMUtilities.CoCreateInstanceEx(ref clsid, IntPtr.Zero, dwContext, server_info, 1, qis);
                    if (hr == 0)
                    {
                        hr = qis[0].HResult();
                        if (hr == 0)
                        {
                            pInterface = qis[0].GetObjectPointer();
                        }
                    }
                }
                finally
                {
                    ((IDisposable)qis[0]).Dispose();
                }
            }
            else
            {
                hr = COMUtilities.CoCreateInstance(ref clsid, IntPtr.Zero, dwContext, ref iid, out pInterface);
            }

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

            return(pInterface);
        }