Example 2 - Setup - Kishore J Doshi
Download All files Associated with this example in three ZIP files
All Java Source Code
MFC Pusher Application Visual Studio Project
COM Server Visual Studio Project
Section Links
Back to Example 2 Description
Screenshots for Example 2
Back to Section Introduction
The user must download the Microsoft SDK for Java 3.1 including the new Microsoft VM to do this example, get them here. You download an active setup program which will present you download and install options, choose Download and Install from Internet. The active setup program sets the install path to c:\SDK-Java.31
Make sure you select the options to download the update to the Virtual Machine and the SDK documentation when the setup program asks you what components you want to download
Once the setup is complete, put the SDK Bin directory on your PATH(c:\SDK-Java.31), this way you can call the tools on the command line, from any working directory
Creating the COM Server:
The user does not need to create the server project from scratch. I provied the the files for the Visual Studio project in the zip file here.
The user only needs to download the project files and compile the project in VC++ 5.0. The compiler will register the server for you. You can change the GUID's if you wish
The user should build the Debug version, but can build the release version if they wish.
Creating the MFC Pusher Application:
The user does not need to create the pusher project from scratch. I provied the the files for the Visual Studio project in the zip file here.
The user only needs to download the project files and compile the project in VC++ 5.0. The compiler will register the server for you. You can change the GUID's if you wish
The user should build the Debug version, but can build the release version if they wish.
Creating the Java Client:
Any classes we create for COM objects must be on the Trusted ClassPath of the VM to load. I suggest doing the following: (Note:If you have done this for Example 1, Ignore this portion about the registry)
Create a directory on the root level of your drive called compackages, let's assume it's c:\compackages
Assuming you have installed the Microsoft Virtual Machine, we must modify the registry settings
Start regedit(registry editor) and goto HKEY_LOCAL_MACHINE/Software/Microsoft/Java VM
Look at the key named TrustedClasspath, edit this and add the compackages directory. So if you put the compackages directory on the C drive root, you put c:\compackages as the value of the TrustedClasspath key.
Run JActiveX on the file TheServer.tbl. The syntax is: jactivex /javatlb /d c:/compackages TheServer.tbl Remember that your working directory must contain the file TheServer.tbl, which is in the TheServer.zip file you downloaded in the section above.
The JActiveX tool creates a subdirectory in c:/compackages called theserver. It takes the name of the .tbl file. In there you will find it created five files (Note: You can also just create the directory and retrieve the files listed below from the zip file containing the source code):
TheServerComObject.java
ITheServerComObject.java
ITheServerComObjectDefault.java
IMySinkID.java
IMySinkIDDefault.java
Download the client driver source code to the directory ClientMT (or retrieve it from the zip file with the Java code): TheControlMultiThread.java
Now were ready to compile the java files. Set you current working directory to be ClientMT and call the Java compiler with this syntax: jvc /x- TheClientMultiThread.java c:\compackages\theserver\*.java. The /x- tells the compiler to use the extensions. This is necessary to use the @com extensions in the server java files. We also specify the directory with the Java files for the COM Server Object(c:\compackages\theserver) as they need to be compiled also.
Running the Java Client
This is the easiest part, assuming you have compiled successfully, you have the following class files in the ClientMT directory
TheControlMultiThread.class
TheSink.class
WindowHandler.class
ComObjectThread.class
TheServerComObject.class
ITheServerComObject.class
ITheServerComObjectDefault.class
IMySinkID.class
IMySinkIDDefault.class
Make sure the CLASSPATH environment variable contains the ClientMT directory.
Start the Pusher Application, this will also start an instance of TheServer, you can check this in the Task Manager
Start the Java client, set the working directory to the ClientMT directory and type jview TheControlMultiThread
Bugs!
There is one pesky bug that I have identified, please submit more here, if you find them.
Bug 1 - The client frame does not update automatically when a new value is pushed from the server. What happens? Start with the MFC program as the active process, you select the value to push and hit the button. The value is sent, but the Java client does not appear to update. You then click on the window to make it the active process, and it updates.Reasons - I believe there are two reasons for this. Either there is a bug in the VM implementation of IConnectionPointContainer, or I have to overwrite IConnectionPointContainer and provide the methods for updating when you are not in focus. This will require further research.