ActiveX Control Licensing


When you install an ActiveX control onto your system for use in developing Visual Basic applications, you are given a single-user development license for that control by the control developer. This is an implicit act, even if the control does not enforce licensing. If the control does use licensing, then the control license key is automatically installed into your system registry database by the control install utility.

When you are using the control in the Visual Basic development environment, every time you place the control on a Visual Basic form, or run an application, the control is created using the ActiveX IClassFactory2 interface. This interface creates a copy of the control object each time Visual Basic requests a new copy of the control. Before the control copy is created, the IClassFactory2 interface checks to see if the control requires a license key. If the control requires a license key, the key is retrieved from the registry database. If the IClassFactory2 interface retrieves a valid license key from the registry, the control is created and a pointer to the copy is returned to Visual Basic, as illustrated in figure 4.21.

figs/ch04/efig21.gif">Figure 4.21

In the Visual Basic development environment, the control license key is retrieved from the registry database before the control is created.

When you compile a Visual Basic application, a runtime license for the control is included in the application executable. The Setup utility that you build for your application by using the Setup Wizard does not place the license key for these controls into the user’s system registry. As a result, when your application tries to create a copy of the control, the IClassFactory2 interface does not find a valid license key in the registry. At this point, the IClassFactory2 interface turns to the application and requests that the application supply the license key. Because Visual Basic placed a copy of the control license key inside the application when it was compiled, the application is able to supply the requested license key, and the control can be created, as seen in Figure 4.22.

Figure 4.22

When Visual Basic compiles an application, it includes the license key of any controls that require it, so the application is able to supply the license to use the control.