Application Verifier has a set of programmable hooks through the Development Tools Extensibility (DTE) model. The purpose of this model is to help you extend and automate tasks within Visual Studio 2005. The main interop assembly that exposes Application Verifier's automation model is Microsoft.VisualC.ApplicationVerifier.dll.
Using DTE, you can perform a variety of tasks, including programmatically creating tools and toolbars, responding to events, and launching commands. In many cases, when there is output to be displayed on the screen, it is shown in the Command window. You can access this window by clicking View Other Windows Command Window (or CTRL+ALT+A).
In this section, you'll create a Visual Studio 2005 macro that automatically launches Application Verifier. Here are the steps to build your project:
Select Tools Macros New Macro Project from the main toolbar.
This will open the New Macro Project dialog box (shown in Figure 10-11).
Select a name for your macro and click the Add button
The Macro Explorer window will appear (as shown in Figure 10-12).
Double-clicking on Module1 will launch the Visual Studio Macros IDE (as shown in Figure 10-13). It should be split between the Project Explorer window and the Code window. To access the Project Explorer, click View Project Explorer.
Enter the following code and click the Save icon.
Imports System Imports EnvDTE Imports EnvDTE80 Imports System.Diagnostics Public Module Module1 Sub AppVerifMacro() DTE.ExecuteCommand("Debug.StartWithApplicationVerifier") End Sub End Module
When you open the Macro IDE, you'll notice that the EnvDTE, EnvDTE80, and System.Diagnostic namespaces are already in place for you. All you have to add is the System namespace. On Line 8 of the application, we execute Debug.StartWithApplicationVerifier using the automation model. Note that Debug.StartWithApplicationVerifier is an alias for the actual UI command. You can also launch this command using the Command window by typing the following:
Two major command aliases are available through the Application Verifier automation model. The latter command will open the tool window. This is very useful if you want Application Verifier to output the results of the debug session:
For more information about event handling and programming Application Verifier, you have two primary sources. You can go spelunking into Microsoft.VisualC.ApplicationVerifier.dll (using Lutz Roeder's Reflector available at http://www.aisto.com/roeder/dotnet/) to do some trial-and-error exploration (one of the best ways to learn). Alternately, you can refer to the MSDN Library available alongside Visual Studio 2005.