/// <summary> /// Default constructor /// </summary> private COMRegistry(COMRegistryMode mode, Sid user, IProgress <Tuple <string, int> > progress) : this(mode) { using (RegistryKey classes_key = OpenClassesKey(mode, user)) { const int total_count = 9; LoadDefaultSecurity(); ActivationContext actctx = null; if (mode == COMRegistryMode.Merged) { actctx = ActivationContext.FromProcess(); } Report(progress, "CLSIDs", 1, total_count); LoadCLSIDs(classes_key, actctx); Report(progress, "AppIDs", 2, total_count); LoadAppIDs(classes_key); Report(progress, "ProgIDs", 3, total_count); LoadProgIDs(classes_key, actctx); Report(progress, "Interfaces", 4, total_count); LoadInterfaces(classes_key, actctx, mode == COMRegistryMode.Merged || mode == COMRegistryMode.MachineOnly); Report(progress, "MIME Types", 5, total_count); LoadMimeTypes(classes_key); Report(progress, "PreApproved", 6, total_count); LoadPreApproved(mode, user); Report(progress, "LowRights", 7, total_count); LoadLowRights(mode, user); Report(progress, "TypeLibs", 8, total_count); LoadTypelibs(classes_key, actctx); Report(progress, "Runtime Classes", 9, total_count); LoadWindowsRuntime(classes_key, mode); } try { CreatedUser = user.Name; } catch { CreatedUser = user.ToString(); } }
private void GetInterfacesInternal() { IntPtr punk = IntPtr.Zero; IntPtr pfactory = IntPtr.Zero; Guid IID_IUnknown = COMInterfaceEntry.IID_IUnknown; int hr = 0; if (_winrt_component) { hr = COMUtilities.RoGetActivationFactory(_activatable_classid, ref IID_IUnknown, out pfactory); } else { hr = COMUtilities.CoGetClassObject(ref _clsid, _clsctx, null, ref IID_IUnknown, out pfactory); } // If we can't get class object, no chance we'll get object. if (hr != 0) { throw new Win32Exception(hr); } if (_winrt_component) { hr = COMUtilities.RoActivateInstance(_activatable_classid, out punk); } else { hr = COMUtilities.CoCreateInstance(ref _clsid, IntPtr.Zero, _clsctx, ref IID_IUnknown, out punk); } if (hr != 0) { punk = IntPtr.Zero; } try { Dictionary <IntPtr, string> module_names = new Dictionary <IntPtr, string>(); QueryInterface(punk, COMInterfaceEntry.IID_IMarshal, module_names, _interfaces); QueryInterface(pfactory, COMInterfaceEntry.IID_IMarshal, module_names, _factory_interfaces); QueryInterface(punk, COMInterfaceEntry.IID_IPSFactoryBuffer, module_names, _interfaces); QueryInterface(pfactory, COMInterfaceEntry.IID_IPSFactoryBuffer, module_names, _factory_interfaces); var actctx = ActivationContext.FromProcess(); if (actctx != null) { foreach (var intf in actctx.ComInterfaces) { QueryInterface(punk, intf.Iid, module_names, _interfaces); QueryInterface(pfactory, intf.Iid, module_names, _factory_interfaces); } } using (RegistryKey interface_key = Registry.ClassesRoot.OpenSubKey("Interface")) { foreach (string iid_string in interface_key.GetSubKeyNames()) { Guid iid; if (Guid.TryParse(iid_string, out iid)) { QueryInterface(punk, iid, module_names, _interfaces); QueryInterface(pfactory, iid, module_names, _factory_interfaces); } } } QueryInspectableInterfaces(punk, module_names, _interfaces); QueryInspectableInterfaces(pfactory, module_names, _factory_interfaces); } finally { if (pfactory != IntPtr.Zero) { Marshal.Release(pfactory); } if (punk != IntPtr.Zero) { Marshal.Release(punk); } } }