Home : Passing Java Objects by Value and Passing VB Objects By Value
Q40596 - HOWTO: Passing Java Objects by Value and Passing VB Objects By Value

Passing Java Objects by Value and Passing VB Objects by Value

 

Passing Java Objects by Value

The attachment, passbyvalue.zip, contains two examples which show how to pass Java objects by value. Here are the instructions for running the examples:

1. Unzip the attachment onto any machine with J-Integra installed.
2. Double-click run.bat. This will do all the J-Integra setup. Have a look at this file if you want to see what is going on.
3. Once the J-Integra bridge is running, you can either run the C++ client or the VB client. The C++ client is located in the cxx directory, and the VB client is located in the vb directory. They are similar in structure for comparison.

Note: Before the C++ client will run, the following line will have to be changed (in client.cpp) to reflect which directory people.tlb is located in. The client will need to be compiled after making this change...

#import "C:\\Work\\Vb2Java.PassByValue\\people.tlb" no_namespace, raw_interfaces_only, named_guids

The examples will work remotely as well:

1. Unzip the attachment onto two different machines with J-Integra installed.
2. On the server machine, double-click runserver.bat. This will do the server side setup.
3. Once the J-Integra bridge is running, copy the generated people.tlb file from the server machine to the client machine. Place it in the same directory as the batch (.bat) files.
4. On the client machine, double-click runclient.bat. This will do the client side setup.

Note: You will need to change the IP address (used by regjvmcmd) to the IP address of the server machine.

5. Run either the C++ client or the VB client on the client machine. You will see MsgBox's pop up indicating when you should unplug the network cable (if you want to be sure that no data is being passed across the network when a Java object's member data is being accessed).

Passing VB Objects by Value

Some users have asked if it is possible to pass objects by value in the opposite direction (i.e. pass Visual Basic objects by value to Java clients). Please note that in this direction, J-Integra has nothing to do with passing VB objects by value. In the above example, the java2com tool needed to do some extra work in order to create an IDL file that would allow certain Java objects to be passed by value (once it had been compiled into a typelib).

But when passing by value in the other direction, it is entirely up to the COM component to provide a typelib that enables this. Either the COM component supports this, or it doesn't - J-Integra has nothing to do with it.

To help demonstrate this, we have provided another attachment, vbtojavapassbyvalue.zip, contains an example of a VB component which passes data by value to a Java client. Here are the instructions for running this example:

1. Unzip the attachment onto any machine with J-Integra installed.
2. Edit Main.java and enter valid parameters in the AuthInfo.setDefault(..) line. You must also change new Class1(xxx.xxx.x.xx) line to contain the IP address of the machine running the VB component (Project1.exe).
3. Double-click run.bat. This will do all the J-Integra setup and run the Java client. You should see "Name", "Age", and "Population" get printed out (ignore the line that says "Unplug the network..."). Have a look at this file if you want to see what is going on.

The example will work remotely as well:

1. Unzip the attachment onto two different machines with J-Integra installed.
2. On the server machine, double-click runserver.bat. This will do the server side setup.
3. Copy the Java proxy files located in the 'person' directory over to the same directory on the client machine.
4. On the client machine, edit Main.java and enter valid parameters in the AuthInfo.setDefault(..) line. You must also change new Class1(xxx.xxx.x.xx) line to contain the IP address of the server machine.
5. On the client machine, double-click runclient.bat. This will run the Java client.
6. When the client says "Unplug the network...", unplug the network cable. You should still see "Name" and "Age" get printed out (because they were passed by value). However, "Population" will not get printed out because the client has to go across the network to retrieve the value.

Related Articles
No Related Articles Available.

Article Attachments
passbyvalue.zip
vbtojavapassbyvalue.zip

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 6/23/2006.
Last Modified on 7/12/2006.
Last Modified by No Author Name Available!.
Article has been viewed 9645 times.
Rated 4 out of 10 based on 11 votes.
Print Article
Email Article