Automating Tasks from Other Applications

With Automation, you can control the Visual C++ environment from other applications such as Word, Excel, or Visual Basic. You can start Visual C++, automate tasks, and then stop Visual C++ when the tasks are finished.

Starting Developer Studio (the Visual C++ Environment)

To start Developer Studio from another application, create an instance of the Developer Studio Application object. For example, to start Developer Studio from Visual Basic or Visual Basic for Applications, use the following code:

Dim app as Application
Set app = CreateObject("MSDev.Application")

When Developer Studio starts, it will be invisible, unless you make it visible by using the Visible property of the Application object:

Dim app as Application
Set app = CreateObject("MSDev.Application")
app.Visible = True

If Developer Studio is already running, you can use that instance of it instead of creating another one. For example, to use the current instance of Developer Studio from Visual Basic or Visual Basic for Applications, use the following code:

Dim app as Application
Set app = GetObject(,"MSDev.Application")

Automating Tasks in Developer Studio

After starting Developer Studio, you can automate tasks in it by using the appropriate code. For example, in the following code, the comment indicates where to insert code for automating tasks:

Dim app as Application
Set app = CreateObject("MSDev.Application")
app.Visible = True
' Insert code for automating tasks here.

Stopping Developer Studio

After completing your Developer Studio tasks, you can stop Developer Studio by quitting the application and releasing all references to the Application object.

Note   If you use Visual Basic to automate Developer Studio, Visual Basic automatically releases all references to the Application object.

To quit Developer Studio, use the Exit command on the File menu or the Quit method of the Application object. If you use the Quit method, however, you must use it before you release its reference to the Application object.

For example, the following code shows how to use the Quit method.

Dim app as Application
Set app = CreateObject("MSDev.Application")
app.Visible = True
' Insert code for automating tasks here.
app.Quit

Note   If the user tries to stop Developer Studio while your program is controlling it, Developer Studio will remain in memory but the user interface will become invisible. Subsequently, if you try to access Developer Studio objects, Developer Studio will return errors. If this happens, release all references to the Application object so that Developer Studio can quit.