1

私は、ユーザーに表示し、(オプションで)自分自身に電子メールで送信される未処理の例外をキャプチャするための優れた方法を持っています。それらは一般的に次のようになります。

Uncaught exception encountered in MyApp (Version 1.1.0)!

Exception:
   Object reference not set to an instance of an object.
Exception type:
   System.NullReferenceException
Source:
   MyApp
Stack trace:
   at SomeLibrary.DoMoreStuff() in c:\projects\myapp\somelibrary.h:line 509
   at SomeAlgothim.DoStuff() in c:\projects\myapp\somealgorithm.h:line 519
   at MyApp.MainForm.ItemCheckedEventHandler(Object sender, ItemCheckedEventArgs e) in c:\projects\myapp\mainform.cpp:line 106
   at System.Windows.Forms.ListView.OnItemChecked(ItemCheckedEventArgs e)
   at System.Windows.Forms.ListView.WmReflectNotify(Message& m)
   at System.Windows.Forms.ListView.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Visual Studioを起動c:\projects\myapp\somelibrary.hして、問題のあるラインで開くことは可能ですか?その場合、どのように行いますか?

可能であれば、生成した(html)メールからもこれを実行したいですか?

4

2 に答える 2

4

たとえば、VBScriptを使用して、VisualStudioを自動化できます。

filename = Wscript.Arguments(0)
lineNo = Wscript.Arguments(1)

' Creates an instance of the Visual Studio IDE.
Set dte = CreateObject("VisualStudio.DTE")

' Make it visible and keep it open after we finish this script.
dte.MainWindow.Visible = True
dte.UserControl = True

' Open file and move to specified line.
dte.ItemOperations.OpenFile(filename)
dte.ActiveDocument.Selection.GotoLine (lineNo)

これをsayとして保存してdebugger.vbs実行し、ファイル名と行番号をコマンドライン引数として渡します。

debugger.vbs c:\dev\my_file.cpp 42
于 2010-06-25T08:03:32.387 に答える
1

質問にはC++のタグが付いているので、これを実現するためのその言語のコードを次に示します。基本的にジョンの答えと同じ原則ですが、より多くのテキストがあります。

bool OpenFileInVisualStudio( const char* psFile, const unsigned nLine )
{
  CLSID clsid;
  if( FAILED( ::CLSIDFromProgID( L"VisualStudio.DTE", &clsid ) ) )
    return false;

  CComPtr<IUnknown> punk;
  if( FAILED( ::GetActiveObject( clsid, NULL, &punk ) ) )
    return false;

  CComPtr<EnvDTE::_DTE> DTE = punk;
  CComPtr<EnvDTE::ItemOperations> item_ops;
  if( FAILED( DTE->get_ItemOperations( &item_ops ) ) )
    return false;

  CComBSTR bstrFileName( psFile );
  CComBSTR bstrKind( EnvDTE::vsViewKindTextView );
  CComPtr<EnvDTE::Window> window;
  if( FAILED( item_ops->OpenFile( bstrFileName, bstrKind, &window ) ) )
    return false;

  CComPtr<EnvDTE::Document> doc;
  if( FAILED( DTE->get_ActiveDocument( &doc ) ) )
    return false;

  CComPtr<IDispatch> selection_dispatch;
  if( FAILED( doc->get_Selection( &selection_dispatch ) ) )
    return false;

  CComPtr<EnvDTE::TextSelection> selection;
  if( FAILED( selection_dispatch->QueryInterface( &selection ) ) )
    return false;

  return !FAILED( selection->GotoLine( Line, TRUE ) ) );
}
于 2010-06-25T09:13:39.783 に答える