220 likes | 1.37k Views
Automating Visual C++ IDE using Add-ins and Macros Ranga Narasimhan Microsoft Developer Support Microsoft Corporation Scope of the Presentation Brief introduction to automation Overview of Microsoft ® VC++ ® IDE automation Various methods of automating VC++ IDE
E N D
Automating Visual C++ IDE using Add-ins and MacrosRanga NarasimhanMicrosoft Developer SupportMicrosoft Corporation
Scope of the Presentation • Brief introduction to automation • Overview of Microsoft® VC++ ® IDE automation • Various methods of automating VC++ IDE • Overview of add-ins and macros • Debugging add-ins and macros • Customizing the VC++ IDE
Overview: Automation • Automation is based on COM • Automation makes it possible for one application to manipulate objects implemented in another application, or to "expose" objects so they can be manipulated • Automation can be performed by a program written using COM-aware language, for example, VC++, Microsoft® Visual Basic® (VB), and so on
Overview: VC++ Automation • VC++ is an automation server • VC++ automation can be used to extend the capabilities of VC++ • You can automate VC++ using any language that supports COM. Developers normally use VBScript, VC++, and VB
VC++ Automation History • Automation was first introduced with VC++ 5.0 IDE • VC++ 6.0 fixed some major bugs and introduced some new methods (BuildProject.AddFile) • VC++ 6.0 also introduced the “Quick Macro” feature • See “Microsoft Visual C++ 6.0 Migration Guide” topic on MSDN for more information on the new VC++ 6.0 features
Object Model Overview • Provides 17 objects • Objects provide methods and properties • The Application and Debugger objects provide events
VC++ Automation Support • VBScript macro • Add-ins (DLL) written using VC++, VB, or any other language that supports COM • Automation clients (EXE or DLL) written using VC++, VB, or any other language that supports COM • Remote automation through DCOM
Add-ins Macros • Written in VC++, VB, and so on • Can access local computer resources besides object model • Access Win32® API • Early bound • Can control another EXE • Written in VBScript • Can access the object model and some other COM objects • Cannot access Win32 API • Late bound • Cannot control another EXE
Creating a Macro File • In VC++ IDE, on the File menu, click New. • Click the Files tab. • Select “Macro File” and give it a name. • This will create an empty macro (DSM) file where you can start typing code: Sub Test() MsgBox “Hello World” End Sub
Recording a Macro • Another method of creating a macro is by recording. • On the Tools menu, click Macro, and then click Record. • You will have to give it a macro name (description is optional). • The recording starts immediately and the actions that you perform are recorded. • On the Tools menu, click “Stop Recording” to stop recording the macro.
Creating Add-ins • To create a VC++ add-in use the “DevStudio Add-in Wizard.” You have an option to include toolbars and event handling in Step 1 of 1. • To create a VB add-in, use the VB 5.0 add-in sample shipped with the MSDN Library. • You can definitely write an add-in using a language that supports COM.
How Are Add-ins Implemented ? • Implement the IDSAddin interface. This will connect and disconnect the add-in with VC++ • Implement an ICommand interface that DevStudio will use to call your add-in methods • Provide implementation for IApplicationEvents and IDebuggerEvents for event handling (optional) • You are not limited to VC++ and VB for add-in implementation
Installing Add-ins and Macros • On the Tools menu, click Customize. • Click the “Add-ins and Macro files” tab. • Click the Browse button and locate the DSM (Macro) or DLL (Add-in) file. • If it is installed properly, you’ll see a check mark against the macro/add-in. • Click the Close button.
Calling Add-in and Macro Commands • If you have one or more command buttons associated with your macro and/or add-in commands, click those buttons. • You can also start them from the command line: Msdev.exe -ex command name • Call them from another add-in and/or macro using the Application.ExecuteCommand method
Debugging • To debug macros, you should use the PrintToOutputWindow or MsgBox method • To debug add-ins, you will have to specify Msdev.exe as the executable for the debug session because it’s a DLL
Customizing the VC++ IDE • On the Tools menu, click Customize. • Click the Commands tab. • Under Category, click Add-ins or Macros. • Drag the icon listed in the Buttons group to the location you want.
Some Limitations and Known Problems • Macro names cannot have an underscore. It is reserved for event procedures. • You cannot pass arguments to add-in and macro commands. • You cannot start multiple add-in and macro commands. • You can add a project, but cannot remove a project. • You cannot change the output filename for static library project.
Useful Articles • Q247035 “HOWTO: Automate Visual C++” • Q231636 “HOWTO: Controlling the Visual C++ IDE Source Code Editor Window” • Q237870 “HOWTO: Increment Version Information After Each Build in VC++” • Q248130 “FILE: AutoSave.exe Provides AutoSave for Visual C++”
References • “Extend Developer Studio 97 with Your Own Add-ins, Macros, and Wizards,” Steve Zimmerman (MSJ, 9/97) • “Extending Developer Studio with Add-ins,” Richard Grimes (MSDN Library) • Automated Builds in DevStudio, or the Night Build Scenario • “Enhancing the Visual C++ 5.0 Workplace with VBScript Macros” by Mark Davis • “VBScript Language Reference” topic in the MSDN Library