Registering a Control

Controls must be registered on the computer where they will run. The control must include information that the registration process can read that identifies the control, and that is then placed in the Windows registry of the computer where the control will run. By reading the registration information, applications can find and load the control.

Note   If you are using the control on the computer where you built the control project, you do not need to register the control; the build process registers the control automatically. If you are using the control in Visual J++, you do not need to explicitly include registration information.

The host application also requires a type library (.tlb file) for your control, which includes information about the control's members. The application reads the information in the type library to know what properties, events, and methods your control supports. Visual J++ can automatically generate a type library for your control during the build process.

In this topic you can find information about the following:

Specifying Registration and Type Library Information

Registration requires the following information:

If you have used the WFC Component Builder to create your control, class IDs are generated for you automatically. You can also have Visual J++ create class IDs for you automatically during the build process by specifying that your control is a COM DLL. You can select this option in the COM Classes tab of the project's Properties window. For details about building a DLL, see Building COM Objects.

Finally, you can create and include class IDs for your control manually. You might do this if you want to guarantee that the class ID remains the same for your control, or if you have to know the classID for some other purpose and do not want to let Visual J++ generate it for you. You can generate a GUID with a program such as Uuidgen.exe, a utility freely available on the Microsoft Web site. You must provide two class IDs in all — one for the control and a second one for its type library.

To make the manual registration information visible to the registration program, you include it in a directive embedded comment in your control's .java file. The format is:

/*
* @com.register ( clsid=guid, typelib=guid )
*/

For example, a registration block might look like the following (the example wraps because the class IDs are long, but should not wrap in your file):

/*
* @com.register ( clsid=d0702fa0-fb3b-11d1-8f88-00aa00600a54, typelib=d3108a20-fb3b-11d1-8f88-00aa00600a54 )
*/

When you build the project for your control, the build process looks for this block. If it is found, the build process generates a type library for the control. It also then registers the control and the type library on your computer.

Creating a ProgID

The registration process automatically builds a progID for your control using the following format:

ProjectName.ControlName

For example, your control project might be MyProject and the control's .java file might be MyControl.java. After registration, the control's progID would be MyProject.MyControl.

Running the Registration Process

If you intend to use the control on the computer where you built it, you do not need to register it — the build process automatically registers it for you. However, if you are distributing the control to another computer, you must register it there.

If you have built your control as a COM DLL, you can register it as you do any control, using the Windows Regsvr32.exe program. In a Command window use the following syntax:

Regsvr32.exe path/controlName

If your control is simply compiled as a .class file, you use a command-line utility called Vjreg.exe that is included with Visual J++. (You cannot use Regsvr32.exe to register your control because that utility is not designed to register .class files.) Register your control in a Command window using the following syntax:

Vjreg path/controlName

When you run this command, it registers the Msjaval.dll as the control's server, with the name and path of your control as a parameter.