This article has four sections:
To see:
The JavaCallingCOM sample demonstrates Java calling COM. Like JavaBeep, it uses services from a simple Automation server. This Automation server includes properties, as well as methods. In this sample, you register the automation server COMSERVER.DLL. You also create a Java description of this server using the Java Type Library Wizard.
COMSERVER.DLL is a dual-interface in-process automation server, like BEEPER.DLL, which is used in the JavaBeep sample.
The comserver component has two properties and one method. It uses an enumeration type.
The sample class usecom uses the constants in BeeperConstants and the SoundName property to create a list of names and values. This list is used to populate the list box in the applet, and also to map the users selection in the list box to a sound for comserver to play. This code is located in the usecom.init method. The handleEvent method is the standard way for applets to respond to events from any components they contain. In this applet, in response to a change in the selection in the list, handleEvent sets the Sound property of comserver and echos the numeric value in a label component. In response to a press event from the button, handleEvent calls the comserver.Play method.
COM components can access any system resources. As such, they are both very powerful and potentially very dangerous. In the Java virtual machine (VM) in Microsoft Internet Explorer 3.0 only trusted class files can use COM components. Class files from digitally signed CAB files are trusted.
If the HTML file is run from Microsoft Developer Studio, the class files are also trusted. This can be very helpful during applet development. However, to deliver your applet to other users, you must put it in a signed CAB file.
When run as an application, the class file must already be on your machine. When run as an applet, the class file may be downloaded to your machine. There is a potential security threat running downloaded software. To run a Java applet that uses COM components, the applet code must be trusted. For more information on trusted class files, see the CabAndSign sample.
Return to the
top of this article.To run the JavaCallingCOM sample:
Return to the
top of this article.If you get the error message java.lang.VerifyError:
If you get the error message ClassNotFoundException:
If you get the error message UnsatisfiedLinkError:
Return to the
top of this article.This sample includes the following files.
Project files:
Support files:
Return to the
top of this article.