/// <summary> /// This function is the callback used to execute a command when the a menu item is clicked. /// See the Initialize method to see how the menu item is associated to this function using /// the OleMenuCommandService service and the MenuCommand class. /// </summary> private void MenuItemCallback(object sender, EventArgs e) { // Show a Message Box to prove we were here EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); Guid clsid = Guid.Empty; IntPtr parentHwnd = IntPtr.Zero; uiShell.GetDialogOwnerHwnd(out parentHwnd); NativeWindow parentShim = new NativeWindow(); parentShim.AssignHandle(parentHwnd); AttachDialog dialog = new AttachDialog(); DialogResult result = dialog.ShowDialog(parentShim); if (result == DialogResult.OK) { foreach (int selected_id in dialog.SelectedItems) { foreach (EnvDTE90a.Process4 p in dte.Debugger.LocalProcesses) { System.Diagnostics.Debug.WriteLine("Found process {0}", p.ProcessID); if (p.ProcessID != selected_id) { continue; } p.Attach(); System.Diagnostics.Debug.WriteLine("Attaching to process successful."); break; } } } }
/// <summary> /// This function is the callback used to execute a command when the a menu item is clicked. /// See the Initialize method to see how the menu item is associated to this function using /// the OleMenuCommandService service and the MenuCommand class. /// </summary> private void MenuItemCallback(object sender, EventArgs e) { // Show a Message Box to prove we were here EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); Guid clsid = Guid.Empty; IntPtr parentHwnd = IntPtr.Zero; uiShell.GetDialogOwnerHwnd(out parentHwnd); NativeWindow parentShim = new NativeWindow(); parentShim.AssignHandle(parentHwnd); AttachDialog dialog = new AttachDialog(); DialogResult result = dialog.ShowDialog(parentShim); if (result == DialogResult.OK) { foreach (int selected_id in dialog.SelectedItems) { foreach (EnvDTE90a.Process4 p in dte.Debugger.LocalProcesses) { System.Diagnostics.Debug.WriteLine("Found process {0}", p.ProcessID); if (p.ProcessID != selected_id) continue; p.Attach(); System.Diagnostics.Debug.WriteLine("Attaching to process successful."); break; } } } }