Using the component model of the Windows Foundation Classes for Java (WFC), you can create ActiveX controls that can be used in WFC applications or in other development environments that support ActiveX. To create an ActiveX control from a WFC control, you register the WFC control's class as a COM class. Once the control's class has been registered as a COM class, you can package the class file for the control into a COM DLL and register it as an ActiveX control in the registry. Once the control is registered as an ActiveX control, it can be accessed from an ActiveX client.
In this scenario, you use the WFC control documented in Creating a Control. If you have not created it, build the control documented in the topic, and continue with the procedures in this topic. You will learn:
Note The following procedure assumes that you have an existing WFC component project opened in Visual J++.
To access your control from other ActiveX clients, you define your control as a COM object. So that a class can be exposed as a COM object, it needs to have an @com.register comment tag placed above the class definition. Visual J++ provides an automated way to generate @com.register comment tags for your classes.
Note If your control’s project was created using the Control template, the control already contains a comment tag to register it as a COM object. Remove the forward slashes (//) to enable the comment tag.
To define a WFC component as a COM object
Visual J++ adds a comment tag at the top of your control’s class definition that registers the class as a COM object.
Note If you do not need to define multiple classes as COM classes, you can define a COM class in the Class Properties dialog box. To display the Class Properties dialog box, in Class Outline, right-click the name of the class, and then click Class Properties. In the Class Properties dialog box, select the COM Class check box.
After you have defined your WFC control as a COM object, you package the control's class files into a COM DLL file. Your control must be packaged in a COM DLL file to be available as an ActiveX control. The COM DLL provides the interface that is used by ActiveX clients to access your control and its members.
Note To distribute your ActiveX controls over the Internet, you can package your control in a CAB file instead of a COM DLL.
To build a control as a COM DLL
The other controls on the tab should now be enabled.
After you have configured the packaging options for the project, you need to build the project. Visual J++ then adds a type library to your project that defines the COM interface for your control. The type library also contains information that the registry uses to register the COM class as a control. When the type library has been generated, Visual J++ registers the COM classes in your project in the registry using the type library file that was created. After the control's classes have been registered, Visual J++ packages the project's class files and the type library into a COM DLL.
To build the project
Once you have registered your WFC control's classes as COM classes and packaged them in a COM DLL, you register the COM DLL in the system registry. To do this, you use the Regsvr32.exe program. Because the project's type library flags the WFC control's COM classes as a control, Regsvr32 registers the COM DLL as an ActiveX control. When the COM DLL has been registered, other applications can see your WFC control in the list of ActiveX controls that are registered on the system.
To register the COM DLL
Regsvr32.exe <DLL path and filename>
where <DLL path and filename> is the path and file name of your control’s DLL. For this scenario, type:
Regsvr32 C:\Project1\Project1.dll
If you receive a message that the registration failed, ensure that the path to the control's DLL is correct and that the file exists.
To test your ActiveX control, you add the control to a programming tool or application that supports ActiveX. For this scenario, you can use Microsoft Visual Basic version 5.0 or later to add the control and test its features.
To add a WFC based ActiveX control to a Visual Basic form
For this scenario, select the Project1 control.
The control is added in the center of the form.
The form is displayed with your control.
If you are working with the control that is documented in Creating a Control, you can scroll the horizontal scroll bar. The text in the control changes to reflect the position of the scroll bar.
For information on importing an ActiveX control into a WFC application, see Importing ActiveX Controls.