Visual Basic Concepts

Licensing Issues for Controls

Licensing for controls is a sensitive issue. After you've spent hundreds of hours developing a control, what if somebody else puts an instance of it on a UserControl, exposes all the properties, methods, and events, adds one or two trivial properties, then compiles and sells it as a new control?

Visual Basic's licensing support protects your investment. When you add licensing support to your control component, a license key is compiled into it. This key covers all the controls in the component.

Running your Setup program transfers the license key to another computer's registry, allowing your controls to be used for development. Simply copying your .ocx file to another computer and registering it does not transfer the license key, so the controls cannot be used.

To add licensing support to your control project

  • On the Project menu, click <MyProject> Properties to open the Project Properties dialog box. Select the General tab, check Require License Key, then click OK.

When you make the .ocx file, Visual Basic will create a .vbl file containing the registry key for licensing your control component. When you use the Package and Deployment wizard to create a setup for your .ocx, the .vbl file is automatically included in the setup procedure.

How Licensing Works

When a developer purchases your control component and runs your Setup program, the license key is added to the registry on her computer.

Thereafter, whenever the developer puts an instance of your control on a form, Visual Basic (or any other developer's tool) tells the control to create itself using the registry key.

If a developer has obtained a copy of your control component, but not the registry key, the control cannot create instances of itself in the development environment.

When a Developer Distributes Applications

When the developer compiles a program that uses one of your controls, the license key for your component is compiled in. When she creates a Setup for the program, your .ocx is included. Users can then purchase the compiled program and run Setup. Your control is installed on each user's machine — but your license key is not added to the registry.

Each time a user runs the program, the Visual Basic run-time DLL asks your control to create a run-time instance of itself, and passes it the key that was compiled into the program. Your control doesn't have to check the registry, because Visual Basic passed it the key.

Thus the user can run a compiled application without having to have the control component's license key in the registry.

Licensing and the User

Suppose the user later obtains a copy of Visual Basic. Noticing that your control component is installed on his computer, he adds your .ocx file to a project.

The first time he tries to put an instance of one of your controls on a form, Visual Basic tells the control to create itself using the registry key. The key is not there, so the control component can't be used in the development environment.

Licensing and General-Purpose User Applications

When desktop applications such as Microsoft Word and Microsoft Excel create control instances on documents or user forms, they tell the control to create an instance of itself using the license key in the registry. This means that a licensed control cannot be used by an end user unless the user has purchased your control component and installed it.

User documents cannot have the license key compiled into them. Suppose the user of a desktop application gives a coworker a copy of your control component along with a document that contains one of your controls. When the document is opened, the control will be asked to create its run-time instance — using the registry key.

In other words, the coworker must also have purchased and installed your control component. Otherwise, when the document is opened, the control instance cannot be created.

Corporate developers who author ActiveX controls for use by end users within their companies may find it more convenient to omit licensing support. This will make it easier for end users to distribute documents containing controls.

Licensing and the Control Author

Now suppose that someone who purchased your control component decides to use one of your controls to author a new control of her own. As with any other program, when she compiles her control component, your license key is compiled in. SetupWizard creates a license key for the new component, but does not add your license key to the setup program.

When a developer installs this new code component, its license key is placed in the registry. The developer then runs Visual Basic, and attempts to put an instance of the control on a form.

The control is asked to create itself using the registry key. In turn, it asks its constituent controls to create themselves using their registry keys. Your control doesn't find its license key in the registry, so control creation fails.

Distributing Controls That Use Licensed Controls

If the control author wishes to distribute a new control that uses a control you authored, she must inform purchasers that in order to use her control, they must have your control component installed on their computers.

Alternatively, the control author might negotiate with you for the right to distribute your license key along with her own, in the setup program for her control.

In either case, both license keys will be installed on a developer's machine, so the developer can create design-time instances of the second author's controls. When those controls are compiled into an executable program, both license keys are compiled in.

When the program is subsequently installed by a user and run, the second author's control is asked to create itself. Its constituent controls are also asked to create themselves, and passed their license keys. (And so on, if your control uses constituent controls with license keys.)

Note   Of the ActiveX controls included with the Professional Edition of Visual Basic, only the DBGrid control requires a license key on a developer's computer. For example, if you use the TreeView control as a constituent control, anyone who is licensed to use your control is licensed to use TreeView as part of your control. However, remember that your Microsoft License Agreement requires that you add significant and primary functionality to any redistributable, such as TreeView, in order to legally distribute it as part of software you develop.

For More Information   Licensing and distribution of constituent controls, including those supplied with the Professional Edition of Visual Basic, is discussed in "Controls You Can Use As Constituent Controls," earlier in this chapter.

Licensing and the Internet

Licensed controls can be used on World Wide Web pages, in conjunction with browsers that support control licensing. Both the control component and the license key must be available to be downloaded to the computer of the person accessing a Web page.

The downloaded license key is not added to the registry. Instead, browser asks the control to create a run-time instance of itself, and passes it the downloaded license key.

The owner of the Web server that uses your control must have purchased and installed your control, just as a developer would, in order to supply both control and license.

If the license is not available, control creation will fail, and the browser will receive a standard control creation error. Whether the browser passes this message along to the person accessing the Web page, or simply ignores it, depends on the person who developed the browser.

Note   Of the ActiveX controls included with the Professional Edition of Visual Basic, only the DBGrid control requires a license key on a Web server. For example, if you use the TreeView control as a constituent control, anyone who is licensed to use your control is licensed to use TreeView as part of your control. However, remember that your Microsoft License Agreement requires that you add significant and primary functionality to any redistributable, such as TreeView, in order to legally distribute it as part of software you develop.

For More Information   See "Controls You Can Use As Constituent Controls," earlier in this chapter.