Dale Rogerson
Microsoft Developer Network Technology Group
Created: July 29, 1994
OLE Controls are reusable software components designed to work in containers that support OLE 2.0. OLE Controls are more powerful and more flexible than the VBX custom controls they will replace. Unlike VBXes, OLE Controls support both 16-bit and 32-bit environments and are not limited to Microsoft® Visual Basic®. OLE Controls are also easier to develop than VBXes. This article provides an overview of the current state of OLE Controls.
VBX custom controls are currently one of the most popular forms of reusable software. Basically, a VBX is a dynamic-link library (DLL) that follows a specification, allowing it to work with Visual Basic and other programming systems. For example, the Microsoft® Visual Basic® and Visual C++™ development systems understand the interface exported by a VBX, and they can utilize a VBX by calling its interface.
OLE Controls are more powerful than VBXes. They are not a superset of VBXes—they have a completely different architecture. Instead of extending a hardware-specific architecture (VBX) to support multiple platforms (especially 32-bit environments), the OLE Control architecture was developed for both 32-bit and 16-bit platforms. In contrast, VBXes are limited to 16 bits.
Additionally, OLE Controls are not limited to Visual Basic. Rather than developing a Visual Basic–specific VBX replacement, Microsoft chose to bring the benefits of VBXes to a wider audience and to incorporate OLE, a major component of future Microsoft operating systems. OLE Controls are designed to work in any container that supports OLE 2.0. This includes not only the next version of Visual Basic, but also OLE-enabled container applications such as Microsoft Office. Additionally, OLE Controls will work in third-party OLE-enabled applications and development tools.
OLE Controls are easier to develop than VBXes. These controls are developed using the Control Development Kit (CDK), which will ship with the soon-to-be-released Visual C++ version 2.0. The CDK contains new classes from the Microsoft Foundation Class Library (MFC) that simplify OLE Control development, and ControlWizard, which will automatically generate an OLE Control skeleton.
OLE Controls, which will be supported by the next version of Visual Basic, will replace VBXes. If you are a control developer, you may want to consider developing OLE Controls, because they are likely to have the largest market of any type of custom control.
Before we get started, let's review the history of custom controls. In the beginning, we only had DLLs. In fact, Microsoft Windows® consists of a number of DLLs working together.
Custom controls were first defined in Microsoft Windows version 3.0. A custom control was a DLL that exported a defined set of functions. These controls were available from third-party developers. Custom controls were neat, but most C developers preferred to write their own. Moreover, the custom control architecture didn't support the Visual Basic development environment because it didn't allow Visual Basic to query the control for information on properties and methods. A new custom control architecture, called the VBX, was defined specifically to support Visual Basic.
The VBX has become incredibly popular. Thousands of VBXes, from simple buttons to complicated networking controls, are available for a wide range of uses. VBXes are written in C/C++, so they can automate tasks that are too difficult, time-consuming, or simply impossible in Visual Basic.
The popularity of VBXes increased the demand for reusable components in other programming environments. For example, Visual Basic programmers needed custom controls for the 32-bit platform; Visual Basic for Applications users wanted controls for Microsoft Access®, Microsoft Excel, and Word; and C/C++ users wanted controls for MIPS® and Alpha® as well as Intel® processors. Unfortunately, VBXes are restricted to the 16-bit Visual Basic environment, so it was impossible to extend VBXes to answer these needs.
OLE, on the other hand, provides the perfect environment for building powerful, flexible, and reusable software components. The new OLE Controls will replace VBXes in the next version of Visual Basic as well as answering the need for visual, reusable code libraries in other 16-bit and 32-bit environments.
An OLE Control is an OLE InProc object (an OLE object that loads into the address space of its container) with some extended functionality. All OLE 2.0–compliant containers can already hold OLE Controls. The controls, however, can only get events in containers that support OLE Control events.
This doesn't matter for some controls. Consider the case of a calendar control that lets you click to change the month. If you only need to display the month, you could insert the control and click to the month you want.
The purpose of most controls, however, is to send event notifications to their parent. Most existing OLE containers, such as those generated by AppWizard in Visual C++, don't know how to handle these event notifications. For instance, if you drop an OLE Control push button into a container that doesn't support OLE Controls, you can push the button as much as you want, but the container doesn't know to respond.
In a container that supports OLE Controls, this button control would send events to the container, which would then respond appropriately. For example, you could insert an OLE graph control into a future control-enabled version of Microsoft Word, and the graph control would display the temperature. If the temperature were higher than the record temperature, the control would fire an event to Word. The Word document would have a Visual Basic for Applications function to handle this event. This function would then insert the string "Record temperature reached today" into the document.
The CDK includes Test Container, a sample application that can examine and change the properties of an OLE Control, invoke its methods, and watch it generate events. This is a valuable tool, not only for developing and debugging new controls but also for learning about existing controls.
However, Test Container is limited to being an interactive tool that cannot be programmed. You can manipulate a control only with the mouse. You can't write functions to see how the control works, and you can't actually develop code to direct and respond to the control, so you can't tell whether it is easy or difficult to write a handler for the control you're developing.
Currently, the only released control container that supports OLE Controls (including events) is Microsoft Access version 2.0. The large installed base of Microsoft Access provides an immediate potential market for OLE Controls. However, because the current version of Microsoft Access was released before the OLE Control specification was finalized, Microsoft Access is a poor control container.
The next version of Visual Basic will be a full-blown OLE Control container that will support OLE Controls similarly to the way Visual Basic currently supports VBXes. You'll be able to simply drop an OLE Control on a form and set its properties. Visual Basic users will become the premier customers for OLE Controls.
Version 3.0 of MFC, which will ship with Visual C++ 2.0, will not directly support OLE containers. In a future version of MFC, however, you will be able to place your control in a dialog box or form, just as you can today with VBXes.
If you are currently using 16-bit Visual Basic, you will want to upgrade to the 32-bit version when it is released. When you buy a new control, make sure you know whether it is an OLE Control. You do not need to replace your older VBXes with OLE Controls, because future versions of Visual Basic will support both OLE Controls and VBXes. This will allow you to change controls on a case-by-case basis.
To take advantage of 32-bit environments, including Windows NT™ and the next version of the Microsoft Windows operating system (called Windows 95), you'll want to consider moving to OLE Controls. The added benefit is that the OLE Controls can be used in multiple development environments, greatly enhancing their value over 16-bit VBXes.
For developers who have existing VBX controls, the CDK provides a way to convert these controls to the OLE Control format using the VBX Template Tool. This tool, found in ControlWizard, uses model information in the .VBX file and creates a Visual C++ project file and source code files for creating the OLE Control. These files can be compiled and linked to produce a working skeleton for the OLE Control.
Once this skeleton is built and tested, you can take code from VBX source files and place it in the appropriate areas of the generated OLE source files. The transplanted code will probably require some modification to work in the new source code files.
If you are a C++ developer, you will have to wait a little longer before OLE Control container support is built into MFC. Because MFC does not yet support the construction of OLE containers, you won't be able to use OLE Controls in your C++ applications for a while unless you write your own container. In a release to follow Visual C++ 2.0, Visual C++ and MFC will provide integrated support for making your C++ programs into full-blown OLE Control containers.
Whatever course you decide on now, remember that OLE Controls are the future of custom controls.
Several articles in the MSDN Library and Library Archive provide an excellent overview of OLE Controls.
Introductory information:
Contains an introduction and overview of OLE Controls. Also provides implementation details and describes the organization of MFC. The CDK documentation derives some of its content from this article.
Provides information on converting VBXes to OLE Controls.
See the Q&A section at the end for useful information.
High-level strategy document.
In the MSDN Library, search for "OLE Custom Control" or "OLE Control" (using the quotation marks in your queries) for additional articles on this subject.
Development information:
See the Control Development Kit (CDK) in the upcoming Visual C++ 2.0 documentation set for information on developing OLE Controls.
My second article, "OLE Controls: Top Tips", in this two-part series provides guidelines for building OLE Controls, based on my own experiences.
Usage information:
I expect that the Visual Basic 4.0 Professional Edition, when it becomes available, will also be a good source of information on using OLE Controls. Look for more information on using OLE Controls with Visual Basic in future issues of the MSDN Library.