Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JACOB : out parameters / refs in JNI

843829Mar 2 2009
Hi Guys,

First time posting, pretty stuck with a problem for the last few days. Here an approach to call a function from a dll using the JACOB extension to java.
it takes 13 params , the last 6 are out params, which are changed within the COM object. Apologies if any of it is unclear.
Current approach :  
 
outcome= new Variant(new String()); 
sessionID= new Variant(new String()); 
error= new Variant(new String()); 
loginID= new Variant(new String()); 
version= new Variant(new String()); 
productName= new Variant(new String()); 
cDB= new Variant(new String()); 
 
 
Dispatch testDispatch = new Dispatch("EM_PACC.PatientAccess"); 
mainIP = new com.jacobgen.empacc.IPatientAccess(testDispatch); 
 
mainIP.initializeWithID(1, "ipaddress", "m", "j", "dbtest", "00E54B79-39EF-4D5B-8929-BAE634018DC9", cDB, productName, version, loginID, error, outcome, sessionID); 
This utilises the generated java classes made using jacobgen. The underlying call made is :
Dispatch.callN(this, "InitializeWithID", new Object[] { new Variant(applicationType), address, uci, volumeGroup, databaseName, supplierID, cDB, productName, version, loginID, error, outcome, sessionID}); 
RESULT : params are not changed on return from method.


Another solution proposed was to pass params as refs. i.e. new Variant(new String(),true) , which calls constructor
                public Variant(Object pValueObject, boolean fByRef)
                {
		init();
		VariantUtilities.populateVariant(this, pValueObject, fByRef);
	}
where init() is a native method returning void. You can then use
Dispatch.invokev(testDispatch, "InitializeWithID", Dispatch.Method | Dispatch.Get,
	new Variant[] { a,b,c,d,e, f,cDB[0], productName[0], version[0], loginID[0], error[0], outcome[0], sessionID[0]},
						new int[13]);
Where the last 6 params are out params. invokev is a wrapper class around native invokev method.
public static native Variant invokev(Dispatch dispatchTarget, String name,
			int dispID, int lcid, int wFlags, Variant[] vArg, int[] uArgErr);
the result of this is :
com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: InitializeWithID
Description: Invalid callee.

        at com.jacob.com.Dispatch.invokev(Native Method)
        at com.jacob.com.Dispatch.invokev(Dispatch.java:858)
        at net.db.EmisHelperJacob.<init>(EmisHelperJacob.java:66)
        at JacobTest.main(JacobTest.java:9)
 
If anyone could describe why passing by ref is causing this exception, or propose another method of performing this task, help would be much appreciated.

Regards

M.P

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 30 2009
Added on Mar 2 2009
0 comments
929 views