1 Replies Last post: Feb 28, 2006 6:39 PM by Alexei Razoryonov  
JNI Cavanaugh   1 posts since
Apr 24, 2006
Currently Being Moderated

Feb 24, 2006 5:00 PM

COM to Java

My application is written in Java. I need to expose some of the API as a COM object. The methods we are exposing involve strings and java byte arrays as arguments and return types. I'm evaluating ComfyJ as an alternative to writing my own JNI, which I've done and would rather not do again.

 

I've played with the sample programs (ComToJava) to write a method that returns a byte array - something like :

   byte[] getBytes();

 

and its corresponding set:

   void setBytes(byte[] b);

 

What are the proper result and parameter return types as defined in the java code? Can you give me a simple example of populating this type? I've tried PrimitiveArray and SafeArray, which didn't return anything, but of course, I may be doing it wrong. When I call this method (with either type) from C++, the result says VT_EMPTY, which I assume means nothing was returned.

 

I'm hoping I don't have to become a COM expert to get this to work

 

Thanks

Alexei Razoryonov   45 posts since
Apr 24, 2006
Currently Being Moderated
1. Feb 28, 2006 6:39 PM in response to: JNI Cavanaugh
Re: COM to Java

Hello,

 

Thank you for your interest in our product.

First of all, the return values and attributes of the methods should be of JNIWrapper types. So your idea about returning SafeArray was correct.

But there was a bug in the ComfyJ core classes with returning arrays from COM to Java servers, which is fixed in the JAR file.You can download it here: http://www.teamdev.com/downloads/updates/comfyj-2.1.jar  Use it instead of your copy of ComfyJ.

As regards your question about a simple example, here it is:

 

     public SafeArray getSafeArray()

         {

        String aStrings[] = {"The First Element", "The Second Element", "The Third Element"};

        SafeArray result = new SafeArray(new

                SafeArrayBound(aStrings.length, 0), BStr.class);

        for (int nIdx = 0; nIdx < aStrings.length; nIdx++)

        {

            result.set(nIdx, new BStr(aStrings[nIdx]));

        }

        result.setAutoDelete(false);

 

        return result;

        }

 

Please contact us if you have any further questions.

 

________________________

 

Sincerely,

Alexey Razoryonov,

Software Developer

TeamDev Ltd.

 

http://www.teamdev.com

 

More Like This

  • Retrieving data ...