Programming in the Extensibility Model

See Also

Once you have a framework in place for your add-in, you can begin to attach code to manipulate and/or extend Visual Basic. As mentioned in Chapter 2, "Extensibility Model Objects and Structure," the extensibility model can be broken down into a number of functional groups, each affecting a major portion of Visual Basic.

Note   Many of the example code fragments below are included to demonstrate how the various collections and objects, and their properties, methods, and events, are used in a real-world program. As such, they may contain references to variables, controls, and such that aren't fully explained in this text. For example, many of the samples reference a variable named "vbi", which is a variable to reference the current instance of Visual Basic. (For more information on this, see "Visual Basic Instance Variable" in "Add-In Essentials".) The important thing to realize is that these examples should act as a basis for your own exploration of the extensibility model, not as complete, free-standing programs. To gain a good feel for the entire feature set, we recommend that you examine the VBIDE library in the Object Browser. We also urge you to examine the TabOrder (which is listed in the Samples directory) for more examples of programming add-ins.

The following topics cover most functional groups of objects in the extensibility model, and provide suggestions for using each group to achieve your goals:

Note   When using C++ to develop add-ins, whenever you get a pointer from Visual Basic using Automation, you must call "release" when you are finished using it. Visual Basic follows the standard reference counting rules. For example, when you get a pointer out of Visual Basic by calling _NewEnum, you must call release through that pointer. Also, when you use pDispatch = m_ourMenuItems.Item(pszCaption), you must also use pDispatch->Release().