This sample is located in \Samples\Com\IPersist.
Note To use this sample, it is recommended that you have Microsoft® Visual C++® version 5.0 or higher installed.
Description
Using the Sample
Key Project Files
Technologies Demonstrated
This sample shows how to use the default storage interfaces that are automatically implemented by Java/COM objects that implement java.io.Serializable.
By default, every Java/COM object will have the interfaces shown in the following table.
IConnectionPointContainer | IDispatch |
IDispatchEx | IExternalConnection |
IMarshall | IProvideClassInfo |
IProvideClassInfo2 | ISupportErrorInfo |
IUnknown |
A Java/COM object that implements java.io.Serializable will also have the interfaces shown in the following table.
IPersist | IPersistStreamInit |
IPersistStorage |
This sample includes the following:
This is a very simple class that will be used as a COM object to illustrate the default implementation of IPersist, IPersistStreamInit, and IPersistStorage when the Java-implemented COM object implements the java.io.Serializable interface. The same behavior is expected with the java.io.Externalizable interface.
The COM client creates an instance of a Java/COM object that implements the java.io.Serializable interface and will, by default, have the COM interfaces IPersist, IPersistStreamInit, and IPersistStorage. This application saves the state of the COM object using these COM interfaces.
The IPersistStreamInit interface saves the state of the COM object to an IStream in memory. The contents of the memory will then be printed to standard output as characters.
The IPersistStorage interface saves the contents of the COM object in a newly-created structured storage file, Jcomsave.doc, that can be viewed using the Dfview.exe tool included with Visual C++. This .doc file contains one entry that has exactly the same bytes as those printed to the screen.
To compile the sample
Use Nmake.exe to compile the makefile in the base directory \Samples\Com\IPersist. Type the following command:
Nmake
The makefile does the following:
To run the sample
Run Jcomsave.exe, which does the following:
Make sure that the sample is run from its root directory, or add the Java class to the class path.
This is the C application that uses the Java/COM object’s exposed IPersist interface to display the IStream data and to write the Java/COM object into a structured storage file.
JavaCOMObject.javaThis simple Java object implements java.io.Serializable and contains some initialized private variables of all primitive Java types.