Platform SDK: COM

Translating to Visual Basic

You can add a COM object to your Visual Basic project either as a reference or a component. Once the object is added to your project, your application can access its classes and interfaces. You can then use the Visual Basic Object Browser to view the object's type library information in Visual Basic syntax.

Typically, controls are added to a project as a components and noncontrols are added as references. When a COM object is added as a component, it appears in the Visual Basic toolbox. New instances of that object are created by dragging the object icon from the toolbox onto a Visual Basic form or other type of container. New instances of COM objects added as references are created using the new keyword.

The distinction between using a class as a reference versus a component is subtle but important. When you add an object as a reference, you can use only the type library that the control provides, or the "raw" type library.

If you add a control as a component, Visual Basic merges the extender properties and methods of the form in which the control is embedded with the control's type library, thus providing a wrapped, extended version of the type library. With this version of the type library, you can use extender properties such as Top and Left as if they were part of the control, instead of the control's container.

Note  Visual Basic does not currently support multiple type libraries built into a single .dll file. If you run into a DLL that incorporates multiple type libraries, you should get stand-alone copies of the type libraries from the source that supplied the object in order to use the object with Visual Basic.

The following topics describe issues you should consider when translating a COM object's syntax to Visual Basic from C++ or Java:

For guidelines on how to develop COM objects that are fully compatible with Visual Basic, see the "Building COM Components That Take Full Advantage of Visual Basic and Scripting" article. This document can be located on the MSDN™ developer library CD, or on the MSDN web site at http://msdn.microsoft.com/library/.