Basics of accessing COM from Java using EZ-JComIn accessing COM via EZ JCom, there are two important COM concepts -- COM-objects and COM-interfaces. COM-objects are the one's that are instantiated. Then they are queried for a COM-interface, and the interface is used to perform operations.
Thus the first order of business in using COM from Java is to look for the COM-objects, and instantiate one or more COM-object classes. Each COM-object's class has one or more "get<Interface>" methods that return the interfaces that are being implemented.
Once the COM-interface has been retrieved using "get<Interface>", its methods may be called to perform the various operations.
For instance, suppose there is a COM-interface named IAccount, and a COM-object named BankAccount, where BankAccount implements IAccount.
Then the Java code first needs to instantiate BankAccount.
BankAccount myBankAccount = new BankAccount();Then the IAccount interface needs to be retrieved.
IAccount iAccount = myBankAccount.getIAccount();Now the iAccount may be used to perform all necessary operations, e.g.
iAccount.add( 4000 );OUT and IN/OUT parameters: In COM, variables can be passed by reference, as OUT or IN/OUT parameters. Because in Java variables cannot be passed by reference, EZ JCom passes OUT and IN/OUT parameters using arrays of size 1. For instance, for an OUT parameter "myArg" of type String, the method signature might be:
public String MyMethod( String myArg );In this case, when passing the argument "myArg", you are required to pass a string array of size 1. Upon return from the method invocation, the result returned by the COM method for "myArg" will be placed in "myArg". For OUT parameters, it is not necessary to initialize the element 0 of the array. For IN/OUT parameters, the element 0 must be properly initialized before the method invocation. E.g.
// For OUT parameter