Microsoft SDK for Java

Hosting a Bean in an ActiveX Container

In JavaBeans architecture, a Bean is a reusable Java component, which is usually meant to be used in the context of other Beans or components in some container. The Microsoft VM provides the bridge necessary to host a Bean in an ActiveX container. The ActiveX container cannot differentiate the Bean from an ActiveX control; it treats it like any other ActiveX control. So, for example, Microsoft® Visual Basic® 5.0 can use the Bean exactly as it would use a control.

Hosting a Bean in an ActiveX container is essentially a two-step process:

  1. Write the Bean.

  2. Run a tool called javareg.

The following example shows a typical javareg command line registering a Bean called JChart:

javareg /register /control /class:JChart /codebase:.
/clsid:{177cf4a0-e7e0-11d0-b8e7-0000f81ecce7} /typelib:JChart.tlb

The javareg tool introspects the JavaBeans component to gather information about its properties, events, and methods, then outputs this information in the form of a type library. A type library is the file that an ActiveX container uses to find information about an ActiveX control. The tool also registers the Bean, which allows an ActiveX container to find the Bean as it would any other ActiveX control.

For more information about the javareg tool, see the javareg section of the Tools Reference. The Microsoft SDK for Java also provides samples of this technique in %SDKDIR%\Samples\Activex. For more information, see the ActiveX Samples Overview. For information about other samples in this SDK, see the Samples Overview.

After running javareg, the Bean can be hosted in any ActiveX container, appearing there as an ActiveX control. When the JavaBeans component is invoked as an ActiveX control, the Microsoft VM is loaded and makes the appropriate mapping between the methods, properties, and events of the JavaBeans and the interfaces, methods, properties, and events of the ActiveX control. Examples of some popular ActiveX containers include Visual Basic, Microsoft® Office, Borland Delphi, and Corel WordPerfect, among others.

Microsoft® Internet Explorer is itself an ActiveX container, and when a JavaBeans component is wrapped as an ActiveX control by the VM in Internet Explorer, the component exposes the same COM interfaces as any ActiveX control in the browser. To enable this mode of use, however, you must use the OBJECT tag to load your Java applet. When you use the OBJECT tag, you do not need to run javareg. See Using the HTML 4.0 OBJECT Tag for more information on using this tag.

© 1999 Microsoft Corporation. All rights reserved. Terms of use.