Overview of the sample
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.
About the server
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 method is Play, which plays a system
sound. It uses the Win32™ function MessageBeep.
There are several system sounds MessageBeep can play.
- The properties are Sound and SoundName.
- The Sound property selects the sound that Play will
access. It uses the same numeric value as MessageBeep.
- To make it easier to use, comserver also creates a
set of numeric constants which represent the available
system sounds. These constants are in the enumeration type
BeeperConstants. This is represented in Java as an
interface with static final members.
- To facilitate working with these sound values,
comserver also has a read-only property, SoundName.
SoundName is a string description of the current value
of the Sound property.
About the sample
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.
About security
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.