private void menuROTBindToObject_Click(object sender, EventArgs e) { if (listViewROT.SelectedItems.Count != 0) { MonikerInfo info = (MonikerInfo)(listViewROT.SelectedItems[0].Tag); Dictionary <string, string> props = new Dictionary <string, string>(); props.Add("Display Name", info.strDisplayName); props.Add("CLSID", info.clsid.FormatGuid()); try { IBindCtx bindCtx = COMUtilities.CreateBindCtx(0); Guid unk = COMInterfaceEntry.IID_IUnknown; object comObj; Type dispType; info.moniker.BindToObject(bindCtx, null, ref unk, out comObj); dispType = COMUtilities.GetDispatchTypeInfo(this, comObj); ObjectInformation view = new ObjectInformation(m_registry, null, info.strDisplayName, comObj, props, m_registry.GetInterfacesForObject(comObj)); Program.GetMainForm(m_registry).HostControl(view); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private object CreateDefaultType(Type t) { object ret = null; try { if (t.GetElementType() != null) { t = t.GetElementType(); } if (t == typeof(string)) { ret = String.Empty; } else if (t == typeof(IBindCtx)) { ret = COMUtilities.CreateBindCtx(0); } else { /* Try the default activation route */ ret = System.Activator.CreateInstance(t); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } return(ret); }
private void btnOK_Click(object sender, EventArgs e) { try { IBindCtx bind_context = COMUtilities.CreateBindCtx(0); if (checkBoxParseComposite.Checked) { foreach (string m in textBoxMoniker.Text.Split('!')) { IMoniker moniker = ParseMoniker(bind_context, m); if (Moniker != null) { Moniker.ComposeWith(moniker, false, out moniker); } Moniker = moniker; } } else { Moniker = ParseMoniker(bind_context, textBoxMoniker.Text); } MonikerString = textBoxMoniker.Text; BindContext = bind_context; DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { Program.ShowError(this, ex); } }
void LoadROT() { IBindCtx bindCtx; listViewROT.Items.Clear(); try { bindCtx = COMUtilities.CreateBindCtx(0); IRunningObjectTable rot; IEnumMoniker enumMoniker; IMoniker[] moniker = new IMoniker[1]; bindCtx.GetRunningObjectTable(out rot); rot.EnumRunning(out enumMoniker); while (enumMoniker.Next(1, moniker, IntPtr.Zero) == 0) { string strDisplayName; Guid clsid; moniker[0].GetDisplayName(bindCtx, null, out strDisplayName); moniker[0].GetClassID(out clsid); ListViewItem item = listViewROT.Items.Add(strDisplayName); item.Tag = new MonikerInfo(strDisplayName, clsid, moniker[0]); if (m_registry.Clsids.ContainsKey(clsid)) { item.SubItems.Add(m_registry.Clsids[clsid].Name); } else { item.SubItems.Add(clsid.FormatGuid()); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); } listViewROT.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); }
void LoadROT(bool trusted_only) { IBindCtx bindCtx; listViewROT.Items.Clear(); try { bindCtx = COMUtilities.CreateBindCtx(trusted_only ? 1U : 0U); IRunningObjectTable rot; IEnumMoniker enumMoniker; IMoniker[] moniker = new IMoniker[1]; bindCtx.GetRunningObjectTable(out rot); rot.EnumRunning(out enumMoniker); while (enumMoniker.Next(1, moniker, IntPtr.Zero) == 0) { string strDisplayName; moniker[0].GetDisplayName(bindCtx, null, out strDisplayName); Guid clsid = COMUtilities.GetObjectClass(moniker[0]); ListViewItem item = listViewROT.Items.Add(strDisplayName); item.Tag = new MonikerInfo(strDisplayName, clsid, moniker[0]); if (m_registry.Clsids.ContainsKey(clsid)) { item.SubItems.Add(m_registry.Clsids[clsid].Name); } else { item.SubItems.Add(clsid.FormatGuid()); } } } catch (Exception e) { EntryPoint.ShowError(this, e); } listViewROT.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); }