Lesson 3: Registering COM Components on the ClientComputer

During installation, a Setup program must register on a user's computer any ActiveX controls or other COM components that the application requires to run. The registry entry for an ActiveX control includes:

  • The control's class identifier GUID.
  • The location of the control's executable file.
  • Characteristics such as the component's threading model.
  • Various flags that specify how the component operates—for example, whether the control is visible or invisible, whether it can be activated inside a container's window, and so forth.

ActiveX controls are self-registering, meaning they contain their own registry information and can write it to the system registry. By taking on the task of registering themselves, ActiveX controls remove most of the burden from the Setup program. In this lesson, you will also learn how to configure an InstallShield pro-ject to correctly install ActiveX controls on a user's system.

After this lesson, you will be able to:

  • Describe the self-registration feature possessed by many COM components, including ActiveX controls.
  • Describe how exported functions write and remove COM information from the registry.
  • Add self-registering components to an InstallShield project.
Estimated lesson time: 15 minutes

Self-Registering Components

To update the user's system registry for installed COM components, a Setup program can use registry files as described in Lesson 1 of this chapter. However, ActiveX controls do not require registry files because they are self-registering.

Chapter 10 explained that an ActiveX control executes as either a stand-alone program or, much more commonly, as a DLL. The latter is known as an in-process (or in-proc) ActiveX control. An in-process ActiveX control exports a function named DllRegisterServer() that, when called, writes to the registry all the information the control requires. The only obstacle is that some other application must load the control and specifically call the DllRegisterServer() function.

This task generally falls to either a Web browser (if the ActiveX control is downloaded from a Web page) or to a Setup program. Because users generally acquire ActiveX controls only over the Internet or by installing an application, registration takes place invisibly—thus, most users never have to worry about registering an ActiveX control.

Control files acquired through other means—e-mail, for example—require manual registration to operate. Windows provides a utility named RegSvr32 that handles this task. RegSvr32 loads a requested ActiveX control or any other self-registering COM component and calls the component's DllRegisterServer() function:

regsvr32 path\MyControl.ocx

where path represents where the component is stored. The command:

regsvr32 /u path\MyControl.ocx

causes the program to call the component's DllUnregisterServer() function, which removes from the registry everything that DllRegisterServer() wrote. The /u switch included in the command stands for uninstall.

Adding Self-Registering Components to an InstallShield Project

If your application files include ActiveX controls or other self-registering components, the Setup program you create must call the components' DllRegisterServer() function during installation. Likewise, the uninstaller program must call the DllUnregisterServer() function for each component if users uninstall your application.

The Setup and Uninst programs created by InstallShield will register and unregister your application's ActiveX components. To configure your installation project to correctly handle self-registering controls, you must create a file group that contains the component files, and then specify the Self Registered property for the group.

  • To create a group of self-registering components
    1. Open the installation project in InstallShield, as shown in Figure 14.5.
    2. click to view at full size.

      Figure 14.5 Opening an existing project in InstallShield

    3. Select the File Groups tab in the project workspace and right-click anywhere inside the File Groups workspace.
    4. On the shortcut menu, click the New File Group command, as shown in Figure 14.6.
    5. click to view at full size.

      Figure 14.6 Creating a new file group in InstallShield

    6. Type Self-registering Components for the group's name and press ENTER.
    7. With the Self-registering Components group selected in the workspace, double-click the Self-Registered field in the display area to the right of the workspace.
    8. In the Properties dialog box, select Yes, all files in this group are self-registering, as shown in Figure 14.7. This choice marks the group as containing only self-registering components.
    9. click to view at full size.

      Figure 14.7 Marking a file group for self-registering component files

    10. Click OK. The value of the Self-Registered field changes to Yes.

    When the Setup program runs on a user's system, it will load each file in the group, call its DllRegisterServer() function to register the component, and unload the file. The next step is to add the component files themselves to the new file group.

  • To add files to the new Self-registering Components group
    1. In the project workspace pane, click the Links sublevel beneath the entry for Self-registering Components.
    2. Right-click anywhere in the area to the right of the workspace pane. On the shortcut menu shown in Figure 14.8, click the Insert Files command.
    3. click to view at full size.

      Figure 14.8 Inserting a file into a group

    4. In the Insert file links dialog box, browse to the first ActiveX control or other self-registering component that you want to add to the installation project and click Open.
    5. Repeat the steps for all component files you want to add to the group.

    Lesson Summary

    An ActiveX control contains its own registry information, including:

    • The control's class identifier.
    • The path to the control's executable file.
    • Run-time characteristics and preferences.
    • Miscellaneous information for containers.

    Each ActiveX control exports a function named DllRegisterServer() that, when called, writes the information to the system registry. An ActiveX control also exports a counterpart function named DllUnregisterServer() that removes the same information from the registry. These functions make ActiveX controls self-registering and self-unregistering.

    Users typically acquire ActiveX controls by viewing Web pages and by installing container applications that use the controls. In either case, registration takes place behind the scenes when the Web browser or Setup program calls the control's DllRegisterServer() function. To allow users to manually add or remove an ActiveX control, Windows provides the RegSvr32 utility.

    An InstallShield project for a container application requires two extra steps. First, a file group must be added to the project with its Self-Registering flag set to Yes. Second, all ActiveX controls and other self-registering components that the application uses must be manually added to the new file group. The second step is necessary because ActiveX controls are not listed in the container's header the way normal DLLs are, so InstallShield will not recognize them as dependencies until specifically instructed to do so. When the resulting Setup program executes, it calls the DllRegisterServer() function for each self- registering component in the project.



    Microsoft Press - Desktop Applications with Microsoft Visual C++ 6. 0. MCSD Training Kit
    Desktop Applications with Microsoft Visual C++ 6.0 MCSD Training Kit
    ISBN: 0735607958
    EAN: 2147483647
    Year: 1999
    Pages: 95

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net