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:
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:Estimated lesson time: 15 minutes
- 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.
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.
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.
Figure 14.5 Opening an existing project in InstallShield
Figure 14.6 Creating a new file group in InstallShield
Figure 14.7 Marking a file group for self-registering component files
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.
Figure 14.8 Inserting a file into a group
An ActiveX control contains its own registry information, including:
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.