Jeff Webb, Mike McKelvy, Ronald Martinsen, Taylor Maxwell, Michael Regelski September 1995 Special Edition Using Visual Basic 4 - Chapter 12 1-56529-998-1 Computer Programming computer programming Visual Basic OLE database applications ODBC VB VBA API This book is an all-in-one reference that provides extensive coverage of every topic and technique for creating optimized and customized applications with Visual Basic.

Chapter 12

Creating OLE Containers


You create OLE container applications by using OLE custom controls, linked and embedded objects, and object applications. This chapter tells you how to use Visual Basic's tools to assemble these OLE building blocks.

In this chapter, you learn how to do the following:

A New Type of Custom Control

Visual Basic 4.0 introduces a whole new type of control: the OLE custom control. OLE custom controls (.OCX) look and work the same as old-style custom controls (.VBX). In fact, Microsoft provides tools to third-party developers to help them convert their .VBXs to .OCXs.

Why the Change?

The standards on which .VBXs were built were written specifically and (at the time) exclusively for Visual Basic. Since then, other development tools, such as Microsoft Visual C++ and Borland C++, have added support for .VBXs. The differences between these development environments and Visual Basic are significant, so the .VBX standard no longer suffices for all custom controls.

Additionally, Visual Basic is now available on several different operating systems—Windows 3.1, Windows NT, and Windows 95 (Chicago). Soon, Visual Basic might also be available on the Macintosh and other platforms. The .VBX standard was written for Windows 3.x and took advantage of features that change under the new versions of Windows. Rather than invest a lot of effort in maintaining the .VBX standard on all platforms, Microsoft (wisely) decided to leverage the work that was already being done by its OLE developers.

The OLE standard is much broader than the original .VBX standard. This broader scope enables such applications as Microsoft Access and Excel to incorporate custom controls. In all, the .VBX to .OCX evolution is an inevitable step in the onward march of computer technology.

.OCX versus .VBX

The advantages of OLE custom controls over .VBXs might not be immediately obvious. For example, OLE custom controls are not faster than .VBXs, nor do they require less memory. Instead, OLE custom controls promise these future advantages:

Although none of these advantages provides an immediate, tangible benefit today, they are almost certain to provide a return on your investment in the near future.

For instance, it is easy to imagine tools that might run in the background maintaining the associations between the system registry and the custom controls that you've installed. If you move a file to a new directory, the tool might update REG.DAT automatically. Such a tool might be included with Windows 95 or be developed by some enterprising reader looking to make it big.

Using OLE Custom Controls

OLE custom controls appear and behave nearly identically to old-style .VBX controls. However, Visual Basic 4.0 incorporates several new features that change the way that you work with custom controls:

The following sections describe these tasks in greater detail.

Drawing a Custom Control on a Form

To draw a custom control on a form, follow these steps:

  1. Click on the toolbar button for the control to draw.
  2. Click on the form and drag the control until it is the size that you want, then release the mouse button (see fig. 12.1).

Fig. 12.1

Drawing a custom control on a form is the same as drawing any other control—you simply click and drag.

Adding an OLE Custom Control to the Toolbox

To add an OLE custom control (.OCX) to the Toolbox, follow these steps:

  1. Choose Tools, Custom Controls. Visual Basic displays the Custom Controls dialog box (see fig. 12.2).

Fig. 12.2

The Custom Controls dialog box.

  1. Select the check box next to the name of the control that you want to add to the Toolbox. Visual Basic adds the control to the toolbar (see fig. 12.3).

Fig. 12.3

Visual Basic adds custom controls to the Toolbox.

If You're Having Trouble

If a custom control appears on the Available Controls list of the Add Custom Control dialog box but does not appear on the Toolbox when you select the control, check whether the file that contains the control (.OCX) is still available in your Windows system directory (usually \WINDOWS\SYSTEM). The file might have been moved or deleted. The locations of custom controls are maintained in the system registry and if files have been moved or deleted, the path recorded in the system registry might not agree with the actual path on your hard disk.

To fix this problem, copy the custom control file to the Windows system directory.

The Insertable Objects and Controls check boxes on the Custom Controls dialog box (see fig. 12.2) enable you show or hide either type of OLE object in the Available Controls list box. If you have many applications installed on your system but don't often use objects from those applications, you might want to select only Custom Controls. This choice makes it a little easier to find the custom control that you want.

Adding a Custom Control to the List of Available Controls

Normally, Visual Basic adds a custom control to its list of available controls when you install the control. If you do not properly install a control, it might not appear in the Available Controls list on the Add Custom Control dialog box.

To add a control to Visual Basic's list of available controls, follow these steps:

  1. Choose Tools, Custom Controls. Visual Basic displays the Custom Controls dialog box (see fig. 12.2).
  2. Choose Browse. Visual Basic displays the Add Custom Control dialog box (see fig. 12.4).

Fig. 12.4

Choose Browse in the Custom Controls dialog box to display the Add Custom Control dialog box, in which you can add a custom control to the list of available custom controls.

  1. Select a custom control file to add, then choose OK. Visual Basic adds the control to the Toolbox and to the list of available controls.

Viewing OLE Custom Control Methods and Properties

One of the advantages that OLE custom controls have over .VBX controls is that you can view control methods and procedures by using the new OLE Object Browser.

To view the methods and properties for a OLE custom control, follow these steps:

  1. Add the custom control to your form. The Object Browser lists only those custom controls that you have already used somewhere in the current project.
  2. Choose View, Object Browser. Visual Basic displays the Object Browser dialog box (see fig. 12.5). You can also display the Object Browser by pressing F2 or by clicking the Object Browser toolbar button.

Fig. 12.5

The Object Browser displays the methods and properties of any OLE custom control, object, or library of objects.

  1. From the Libraries/Projects drop-down list, select the custom control to view. The Object Browser displays the classes and modules for that control. Most controls have one class for the control itself, but others might have more than one.
  2. Select the class and the method or property to view. The Object Browser displays the syntax for the method or property and a brief description, as shown in figure 12.6.

Fig. 12.6

The Object Browser lists the syntax and a brief description of the properties and methods of all OLE objects.

The Object Browser does not list the events an object supports. To add event procedures for a custom control, use the Object and Proc list boxes on the Visual Basic Code window (see fig. 12.7).

Fig. 12.7

Use the Code window to view the events that an OLE custom control supports.

Upgrading .VBXs to .OCXs

Visual Basic 4.0 ships OLE custom controls that replace all the .VBX controls included in Visual Basic 3.0 Professional Edition. The version 3.0 controls still work with Visual Basic 4.0, but if you want to run your applications on 32-bit operating systems, such as Windows NT or Windows 95, you should upgrade those projects to use the new OLE custom controls.

Many other custom control vendors also provide OLE custom controls to replace their older .VBX controls. You might want to contact your custom control provider before you begin upgrading your projects—it is easier to perform the upgrade for all controls once instead of upgrading a project in a piecemeal fashion.

To upgrade a project containing .VBX controls to use new OLE custom controls, follow these steps:

  1. Make a copy of the project in a new directory. After upgrading your controls, you cannot undo the operation. You should always keep a copy of the old project in case you have a problem running the upgraded version.
  2. Install all the new OLE custom controls on your system. These new controls register their equivalent .VBX file in the VB.INI file. Visual Basic automatically uses this information for the upgrade.
  3. Open the project to upgrade by using Visual Basic 4.0. Visual Basic displays the Custom Control Upgrade dialog box (see fig. 12.8). Choose Yes to proceed with the upgrade.

Fig. 12.8

The Custom Control Upgrade dialog box appears before Visual Basic converts .VBX controls to .OCX controls in a project.

  1. If you are upgrading the project from Visual Basic 3.0, Visual Basic displays a warning that it will save the files in a new format for Visual Basic 4.0 (see fig. 12.9). Click OK For All to proceed with the upgrade.

Fig. 12.9

Visual Basic 4.0 files are not backwardly compatible with earlier versions.

Fig. 12.10

If you ask it to, Visual Basic will add a reference to the Microsoft Data Object Library.

  1. Visual Basic replaces your .VBX custom controls with the equivalent OLE custom controls installed on your system. This process can take a little while, depending on the complexity and size of your project.

Visual Basic doesn't upgrade .VBX controls that lack equivalent OLE custom controls installed on your system. The setup program written by the custom control provider handles the installing and registering of the mapping between .VBX controls and OLE custom controls. If you have problems upgrading a control, you might want to contact the custom control provider to see whether it knows of the problem and offers special procedures to use when upgrading their custom controls.

Not all .VBX controls have .OCX equivalents. Before planning any migration to Windows 95 or Windows NT 3.51, check with your custom control vendor to make sure updated controls are available.

A New Way to Insert Embedded Objects

In Visual Basic 3.0, you had to use the OLE 2.0 custom control (MSOLE2.VBX) to add linked or embedded objects to a form. In Visual Basic 4.0, you can add embedded objects directly to the Toolbox and then draw them on the form, just as you would any other control (see fig. 12.11).

Fig. 12.11

Add insertable OLE objects to the Toolbox, then draw them directly on a form.

Visual Basic refers to these embedded OLE objects as insertable objects throughout its documentation.

Adding an Embedded Object to the Toolbox

The Setup program doesn't install embedded objects in the Toolbox because they are provided by OLE applications, such as Microsoft Word and Excel, that don't ship with Visual Basic.

To add an embedded object to the Toolbox, follow these steps:

  1. Choose Tools, Custom Controls. Visual Basic displays the Custom Controls dialog box (see fig. 12.12).

Fig. 12.12

The Custom Controls dialog box lists the insertable OLE objects as well as available custom controls.

  1. Select the check box next to the name of the embedded object that you want to add to the Toolbox. Visual Basic adds the control to the toolbar (see fig. 12.13).

Fig. 12.13

An Excel worksheet embedded on a form.

The Insertable Objects and Controls check boxes on the Custom Controls dialog box (see fig. 12.12) enable you to show or hide either type of OLE object in the Available Controls list box. You might want to select only Insertable Objects if you are not adding custom controls to your Toolbox. This makes it a little easier to find the object that you want.

Drawing Embedded Objects on a Form

To draw an embedded object on a form, follow these steps:

  1. Click on the Toolbox button for the object to draw.
  2. Click on the form and drag the control until it is the size that you want, then release the mouse button (see fig. 12.14).

Fig. 12.14

Drawing an embedded object on a form is the same as drawing a control—simply click and drag.

Emdedded Objects and In-Place Editing

Embedded objects need not support in-place editing. If an object supports in-place editing, Visual Basic starts the application that provides the object and displays the object's toolbar or menu on the form, as shown in figure 12.15.

Fig. 12.15

The Microsoft Excel Chart object supports in-place editing, so it displays the charting menu right on the form.

If an object does not support in-place editing, the application that provides the object starts up when you release the mouse button.

Table 12.1 lists widely installed applications, their embedded objects, and whether they support in-place editing.

Table 12.1 Many Applications Now Provide Embedded Objects, but Only Some Support In-Place Editing

Application Version Object Supports In-Place Editing (Y/N)
Microsoft Access 7.0 Database Y
Microsoft Excel 7.0 Worksheet Y
Chart Y
Graph Y
Microsoft Excel 5.0 Worksheet Y
Chart Y
Graph Y
Microsoft Equation 2.0 Equation Y
Microsoft Graph 3.0 Graph N
Microsoft PowerPoint 7.0 Presentation Y
Slide Y
Microsoft Windows 3.1 Package N
Paintbrush Picture N
Sound N
Microsoft Windows 95 Package N
Sound Y
Paintbrush Picture Y
Video clip Y
WordPad Document Y
Shapeware Visio 3.0 Drawing Y
Shapeware Visio 2.0 Drawing N
Microsoft Word 2.0 Document N
Microsoft Word 6.0 Document Y
Picture Y
Microsoft Word 7.0 Document Y
Picture Y
Microsoft WordArt 2.0 WordArt Y

Adding Data to Embedded Objects

When you draw an embedded object on a form, the object appears without data. You can enter new data directly in the object at that time. If you select another control on the form, the embedded object is closed. To reopen an embedded object for editing, follow these steps:

  1. Right-click on the embedded object. The object displays its pop-up menu (see fig. 12.16).

Fig. 12.16

An embedded Excel worksheet object displaying its pop-up menu.

  1. Choose Edit to edit the object in place. Choose Open to open the object in its application (not in place).
  2. If you finish editing the object in place, simply click another control on the form to close the object. If you are editing the object in its application, choose File, Close from the application's menus to close the object.

Creating Embedded Objects from Files

Drawing embedded objects on forms using the Toolbox button for the object works great for new objects that don't yet contain data. However, moving the contents of an existing file into one of these embedded objects is awkward; you must open the object in its application, then cut and paste the data into the file.

It is easier to create an embedded object from a file by using the OLE 2.0 control. To create an embedded object from a file, follow these steps:

  1. Click the OLE 2.0 control button in the Visual Basic Toolbox.
  2. Click on the form and drag the control until it is the size that you want, then release the mouse button. Visual Basic displays the Insert Object dialog box (see fig. 12.17).

Fig. 12.17

Use the Insert Object dialog box to create an embedded object from a file.

  1. On the Insert Object dialog box, click Create from File. Visual Basic changes the Insert Object dialog box to enable you to select a file (see fig. 12.18).

Fig. 12.18

Type the file name or choose Browse to specify a file to use.

  1. On the Insert Object dialog box, type the name and path of the file to link or choose Browse to select a file in the Browse dialog box.
  2. Click OK. Visual Basic makes a copy of the data in the file and inserts the object on the form.

An embedded object created in this way is a copy of the data in the file—it is stored and updated separately from the original file. To ensure that an object is updated and kept in sync with its source file, use a linked object rather than an embedded one.

Inserting Linked Objects with the OLE 2.0 Control

In Visual Basic 3.0, linking and embedding was provided through the OLE 2.0 custom control (MSOLE2.VBX). In Visual Basic 4.0, the OLE 2.0 control is built in. The OLE 2.0 control works the same way that it did in Visual Basic 3.0—you can still use it to add linked or embedded objects to forms.

When adding embedded objects, it is easier use the Toolbox. For more information, see "A New Way to Insert Embedded Objects," earlier in this chapter.

Drawing Linked Objects on a Form

To draw a linked object on a form, follow these steps:

  1. Click the OLE 2.0 control button in the Visual Basic Toolbox.
  2. Click on the form and drag the control until it is the size that you want, then release the mouse button. Visual Basic displays the Insert Object dialog box (see fig. 12.19).

Fig. 12.19

Use the Insert Object dialog box to add linked objects to a form.

  1. On the Insert Object dialog box, click Create from File. Visual Basic changes the Insert Object dialog box to enable you to select a file (see fig. 12.20).

Fig. 12.20

Type the file name or click Browse to specify a file to use.

  1. On the Insert Object dialog box, type the name and path of the file to link, or choose Browse to select a file in the Browse dialog box.
  2. Select Link to link the object on the form to the file, then click OK. Visual Basic inserts the object on the form and displays the data from the file in the object.

Editing Linked Objects

Unlike embedded objects, linked objects never support in-place editing. When you edit a linked object, the object's application always starts up in another window and loads the linked file.

To edit a linked object on a form, follow these steps:

  1. Right-click on the object. The object displays its pop-up menu (see fig. 12.21).

Fig. 12.21

An Excel worksheet object displaying its pop-up menu.

  1. From the pop-up menu, choose Open or Edit. The object's application starts and loads the linked file (see fig. 12.22).

Fig. 12.22

Editing a linked worksheet file with Excel.

  1. Edit the file for the linked object, then save the file and exit. Visual Basic updates the linked object.

An OLE object might look different in design mode or run mode, as shown in figure 12.23.

Fig. 12.23a

In design mode, Visual Basic updates the linked object as the file changes. In run mode, the object is grayed until the file is closed.

Fig. 12.23b

In Run mode.

A New Type of OLE Object: Object Applications

Linked and embedded objects are no longer the only type of OLE objects that you can use in Visual Basic. Object applications differ from linked and embedded objects in that you can't place them on a form. Instead, object applications can display their own dialog boxes and forms to perform services, such as access to databases or retrieving a password from a user. Figure 12.24 shows the differences between linked and embedded objects and object applications.

Fig. 12.24

Linked and embedded objects appear on a form. Object applications might display their own forms or run invisibly in the background.

Building the Sample Object Application

You can create object applications in Visual Basic or Visual C++. Part III, "Creating OLE Objects," teaches you how to create your own object applications using Visual Basic. This chapter is concerned only with using those applications after they exist.

However, to show you how to use an object application, you must have one installed on your system. The easiest way around this catch-22 is to go ahead and build one of the sample applications that ships with Visual Basic: GRAVITY.VBP.

To build GRAVITY.VBP, follow these steps:

  1. Load the project GRAVITY.VBP in Visual Basic. You can find the GRAVITY.VBP project in the Visual Basic \SAMPLES\OLESERV directory.
  2. Choose File, Make EXE File. Visual Basic displays the Make EXE File dialog box (see fig. 12.25).

Fig. 12.25

Compile the GRAVITY.VBP sample file to see how to use an object application.

  1. Click OK. Visual Basic compiles the project into GRAVITY.EXE and adds an entry in your system's registry for the application.

Viewing an Object Application's Objects, Methods, and Properties

You use the Object Browser to view the objects, properties, and methods that an object application contains. However, before you can browse an application object, you must first establish a reference to that application. It's not absolutely necessary to establish a reference before using an object application, but doing so does enable the Object Browser and provides syntax checking for properties and methods.

To view GRAVITY.EXE's objects, methods, and properties, follow these steps:

  1. Create a new project or open an existing one (other than GRAVITY.VBP). References to object applications are saved with each project.
  2. Choose Tools, References. Visual Basic displays the References dialog box (see fig. 12.26). A reference enables your project to use objects, methods, and properties included in other applications or libraries.

Fig. 12.26

The References dialog box establishes a reference between the open project and object applications or object libraries.

  1. In the Available References list box, select the check box next to the words "What goes up..." This is the reference for GRAVITY.EXE.
  2. Click OK. Visual Basic closes the References dialog box.
  3. Choose View, Object Browser or press F2. Visual Basic displays the Object Browser dialog box (see fig. 12.27).

Fig. 12.27

GRAVITY.EXE contains one object and three methods or properties.

  1. From the Libraries/Projects drop-down list, select Gravity. The Object Browser displays the objects, methods, and properties contained in GRAVITY.EXE.

You can use the objects, methods, and properties listed for GRAVITY anywhere in code. Unlike other types of objects, however, object applications do not provide events that you can use in Visual Basic.

If You're Having Trouble...

If you are having trouble establishing a reference to an object application, run the object application and then try again. Object applications check their system registry entries every time that they start up. Often this fixes the problems in the system registry.

Running an Object Application

Use the CreateObject and GetObject functions to run an object application. CreateObject and GetObject use this syntax:

Set objVariable = CreateObject(programmaticID)
Set objVariable = GetObject([objectname], programmaticID)

The placeholder objVariable is an object variable that contains the object that CreateObject and GetObject return. This is the variable used throughout your code to refer to the object application.

The placeholder programmaticID is the name of the object application as it is entered in the system registry. This name has the form ApplicationName.ObjectName. For example, excel.application or gravity.ball.

CreateObject and GetObject both return an object from the application, as shown in the following table:

Use To Example
CreateObject Start a new copy of the object application Set objBall = CreateObject ("gravity.ball")
GetObject (first argument null) Get a running instance of the object application Set objBall = GetObject (" ","gravity.ball")
GetObject (first argument provided) Get a specific object from the object application Set xlsExcel = _GetObject ("c:\excel\stock.xls","excel.sheet")

To run the GRAVITY object application, follow these steps:

  1. Create a new project.
  2. Open the Code window for Form1 in the project and add the following lines of code:

    Option Explicit
    ' Declare an object variable for the object application.
    Dim mobjBall As Object

    The variable mobjBall is declared at the form level, so other procedures in the form can use it. This ensures that the object variable is still available after the Form_Load event creates the object in the next step.

  3. Add the following lines to the Form_Load event:

    Private Sub Form_Load() ' Run the object application ' by calling CreateObject. ' CreateObject returns the object ' from the application. Set mobjBall = CreateObject("gravity.ball") End Sub

    The CreateObject line starts GRAVITY.EXE, returns the Ball object, and assigns it to the object variable mobjBall. You must use Set when assigning object variables.

  4. Run the new project. When Form1 loads, Visual Basic starts GRAVITY.EXE. GRAVITY.EXE doesn't display any forms or dialog boxes, but you can see it if you view the Windows Task List.

Finding Programmatic IDs

One of the hardest parts about using CreateObject and GetObject is finding the right programmatic ID for the object application that you want to start. Table 12.2 lists some commonly installed applications and the programmatic IDs for their objects.

Table 12.2 Many Applications Provide Objects, but Their Programmatic Ids Are Often Hard to Find

Application Object Programmatic ID
Microsoft Excel Application
Worksheet
Chart
excel.application
excel.sheet
excel.chart
Shapeware Visio Application visio.application
Microsoft Word Basic word.basic

The programmatic ID of an object application created in Visual Basic consists of the application name and the object name, as in gravity.ball or calc.application.

The application name is the name entered in the Project Name text box of the Project tab of the Options properties pages. The object name is the name of the class (see fig. 12.28).

Fig. 12.28

For object applications created in Visual Basic, the programmatic ID consists of the application name and the class name of the object.

Using Object Application Methods and Properties

After starting an object application as described in the previous section, you can use the object's methods and properties just as you would with any other Visual Basic object or control.

To see how this works with the GRAVITY.EXE object application, follow these steps:

  1. Create a module-level variable to contain the reference to the Ball object and write code in the Form Load event to initialize the Ball object:

    Dim mobjBall
    Private Sub Form_Load()
    Set mobjBall = CreateObject("Gravity.Ball")
    End Sub

  2. Draw an option button on Form1 of the project that you created in the previous section. Add the following lines to the option button's click event:

    Private Sub Option1_Click()
    ' Call the Throw method for the Ball object.
    mobjBall.Throw dblHorizontalVelocity:=1000, _
    dblVerticalVelocity:=1000
    Timer1.Enabled = Option1.Value
    Timer1.Interval = 1000
    End Sub

    The Ball object's Throw method starts GRAVITY.EXE tracking the trajectory of a hypothetical ball influenced by the earth's gravity.

  3. Draw a timer control on Form1 and add the following lines to the timer event:

    Private Sub Timer1_Timer()
    ' Call the Distance and Height properties
    ' for the Ball object.
    Form1.Print "Distance: " _
    & mobjBall.Distance(dblCurrentTime:=Now) _
    & " Height: " _
    & mobjBall.Height(dblCurrentTime:=Now)
    End Sub

    The Ball object's Distance and Height properties return the coordinates of the hypothetical ball that was thrown in step 1.

  4. Run the project. When you click the option button, Form1 displays the coordinates of the ball's trajectory (see fig. 12.29).

Fig. 12.29

The application that you create in these steps demonstrates how to use the Throw method and Height and Distance properties of the Ball object provided by GRAVITY.EXE.

The application shown in this section isn't terribly exciting. You can improve on the application by moving the option button to follow the ball's trajectory on the form. See the sample GRAVTEST.VBP in the \SAMPLES\OLESERV directory for more ideas.

Closing an Object Application

After you start an application by using CreateObject or GetObject, it continues running as long as one or more object variables refer to an object in the application. This principle is fundamental to OLE.

OLE keeps track of the number of references to an application. If the application is not visible and the count goes to zero, OLE closes the application. If the application is visible and the count goes to zero, OLE leaves the application running.

To see how this works with the GRAVITY.EXE object application, follow these steps:

  1. In the project created in the previous two sections, add this code to the form's unload event:

    Private Sub Form_UnLoad(Cancel As Integer)
    ' Set the object variable to Nothing
    ' to close the object application.
    Set mobjBall = Nothing
    End Sub

    Setting the object variable mobjBall to Nothing changes the reference count of GRAVITY.EXE to zero. Because GRAVITY does not have a visual interface, OLE closes the application.

  2. Run the project. When you close Form1, GRAVITY.EXE shuts down and is removed from the Windows Task List.

Applications that have a visual interface usually provide a Quit or Exit method to close. For example, these lines start Microsoft Excel, then close that application:

Sub Main()
Dim appExcel As Object
Set appExcel = CreateObject("excel.application")
appExcel.Visible = True
' Excel starts invisibly, so make it visible.
appExcel.Quit ' Close Excel
End Sub

Not all applications follow the OLE standard, however. Most notably, Microsoft Word closes when no longer referenced, even if it is visible. These lines start Microsoft Word 6.0, then close the application:

Sub Main()
Dim appWord As Object
Set appWord = CreateObject("word.basic")
' Start Microsoft Word.
appWord.Insert "Add some text" ' Insert some text in a document.
Set appWord = Nothing ' Closes Word without saving!
End Sub

In this regard, Word is not a "well-behaved" OLE application. In all cases, it is important to experiment with object applications to determine how well they follow the OLE standards.

Exploring the System Registry

Each OLE object installed on your system has one or more entries in the system registry. One of the best tools for exploring the OLE objects on your system is the Registry Editor (REGEDIT.EXE). This tool ships with Windows and comes installed in the Windows directory.

To explore your system's registry, follow these steps:

  1. Run the command line regedit /v. (You might want to add an item with this command line to your Visual Basic program group.) The Registry Editor appears as shown in figure 12.30.

Fig. 12.30

The Registry Editor lets you view the entries in your system's registry.

  1. Choose Edit, Find. The Registry Editor displays the Find dialog box (see fig. 12.31).

Fig. 12.31

Use the Find dialog box to search for insertable objects, programmatic IDs, or applications by name.

  1. Enter the name of a key for which to search and click Find Next. For example, you might want to search on progid to see programmatic IDs or word to locate the entries for Microsoft Word.
  2. Press F3 to find the next entry that matches the entered key.

The listing that appears in the Registry Editor is confusing at best. Table 12.3 describes what some of the items mean.

Table 12.3 The Meanings of Some of the Keys in the System Registry

Key Item Meaning
CLSID The item's class ID, a number that identifies the object to OLE, and that is used by the OLE .DLLs when referring to the object.
insertable An indicator that this object supports in-place editing for embedded objects.
notinsertable An indicator that this object does not support in-place editing for embedded objects.
progid The programmatic identifier used to start the application as an application object. You cannot use all objects with programmatic identifiers CreateObject or GetObject, however. You can't readily tell which objects are creatable by looking at the system registry.
server A list of the path and file specification of the application that provides the object.
verb The menu items that this object adds to the pop-up menu when right-clicked. Typical actions are Edit and Open, but some objects may support additional verbs, such as Play.

From Here...

For more information on the following topics, see the indicated chapters:


© 1996, QUE Corporation, an imprint of Macmillan Publishing USA, a Simon and Schuster Company.