Menu

How to pass an array

Help
2009-04-16
2016-10-05
  • Jay Walters

    Jay Walters - 2009-04-16

    Seems I accidentily posted this in open Discussion first, so now I'll go the more appropriate help topic.

    I have a C# object, interface is something like void print(string[] names) which is available via COM interop, but I am not sure how to pass the arguments from Java. I've tried many things and get core dump from the jacob JNI code, or else all sorts of type errors.  What should I be doing in the Java?  I am using Jacob-1.14.3.

    Jay Walters

     
    • Jay Walters

      Jay Walters - 2009-04-16

      This is the type of exception I'm getting. I've gotten different but similar ones depending if I try to pass a SafeArray through myself or let Jacob create one.

      Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered:
      At Invoke of: print
      Description: Type mismatch.

          at com.jacob.com.Dispatch.invokev(Native Method)
          at com.jacob.com.Dispatch.invokev(Dispatch.java:858)
          at com.jacob.com.Dispatch.callN(Dispatch.java:455)
          at com.jacob.com.Dispatch.call(Dispatch.java:544)

      Thanks for your help

       
    • Jay Walters

      Jay Walters - 2009-04-16

      Managed to get it all figured out.

      for c#

         void print(string[] names)

      the call from java is

        SafeArray sArray = new SafeArray(Variant.VariantString, 2);
        sArray.fromStringArray(new String[] { "Foo", "Bar" });
        Variant vt = new Variant();
        vt.putSafeArrayRef(sArray);
        loader.call(loader, "print", vt);

      Seems a bit cumbersome, but it works.

       
  • Adi

    Adi - 2016-10-05

    Hello, I have a propery called QuoteCode which I have to set. But this property is an array. In VB it's QuoteCode(0) = "101". But when I try with activeXComp.setProperty("QuoteCode", "101") I get a "Parameter not optional" Exception. Do you have any ideea about how to do this?

     

Log in to post a comment.