1

Here is the IDispatch interface I got from the type library:

interface IMYPhoneCmd : IDispatch {
    [id(0x00000001), helpstring("method CallSet")]
    HRESULT CallSet(
                    [in] BSTR* name, 
                    [in, optional, defaultvalue(0)] VARIANT par1, 
                    [in, optional, defaultvalue(0)] VARIANT par2, 
                    [in, optional, defaultvalue(0)] VARIANT par3, 
                    [in, optional, defaultvalue(0)] VARIANT par4, 
                    [in, optional, defaultvalue(0)] VARIANT par5, 
                    [in, optional, defaultvalue(0)] VARIANT par6, 
                    [in, optional, defaultvalue(0)] VARIANT par7, 
                    [in, optional, defaultvalue(0)] VARIANT par8, 
                    [in, optional, defaultvalue(0)] VARIANT par9, 
                    [in, optional, defaultvalue(0)] VARIANT par10, 
                    [in, optional, defaultvalue(0)] VARIANT par11, 
                    [in, optional, defaultvalue(0)] VARIANT par12, 
                    [in, optional, defaultvalue(0)] VARIANT par13, 
                    [in, optional, defaultvalue(0)] VARIANT par14, 
                    [in, optional, defaultvalue(0)] VARIANT par15, 
                    [in, optional, defaultvalue(0)] VARIANT par16, 
                    [out, retval] long* retval);

Here is my java code:

    OleAutomation automation = new OleAutomation("PhoneScript.MYPhoneCmd");

    int[] ids = automation.getIDsOfNames(new String[] { "CallSet", "name" });
    int dispIdMember = ids[0];
    int[] rgdispidNamedArgs = new int[] {ids[1]};

        Variant[] rgvarg = new Variant[3];
        String name = "Call_setCallDistance";
        rgvarg[0] = new Variant(name);
        rgvarg[1] = new Variant("Newyork");
        rgvarg[2] = new Variant("2000");

        System.out.println(dispIdMember);

   // Call the method
       Variant pVarResult = automation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs );

    // Check the return value
   if (pVarResult == null ){
     System.out.println("Failed to call method ");
    }

Output is:

1
Failed to call method 

The executable file opens but it doesn't do what I want, as you can see it fails, and I assume it has to do with the name and rgdispidNamedArgs.

Here is a working Perl equivalent:

    my $Callset = "Call_setCallDistance";                   # Callset name
    my $param1 = Newyork;                                   # Callset parameter 1
    my $param2 = 2000;                                      # Callset parameter 2
    Win32::OLE::CreateObject('PhoneScript.MYPhoneCmd', $PhoneClient) || die "can't connnect to PhoneClient: $!\n";
    $Result = $PhoneClient->CallSet($Callset, $param1, $param2); # This is the exact line I need in java

I'm working first time with OleAutomation in java and dont have much experience with it also could find very few examples on the internet for it and I tried to convert the example I found for my project but the example was with BSTR not BSTR*, it seems to me this is the only difference and it doesn't work, I dont know why. CallSet method is used for various settings/invokes like 20-30 but Im specifically interested in "Call_setCallDistance". I would be glad if you can give a hand!

Anarkie
  • 657
  • 3
  • 19
  • 46

2 Answers2

0

I think that the problem is rgdispidNamedArgs , which may not be required in this case and you have it filled with 1´s. We don´t initialize it, so it would be equivalent to have it filled with zeros.

I don´t have much experience either, even less in Java. You should check how automation.invoke builds the DISPARAMS structure with its arguments.

For now, I woudl suggest just removing the rgdispidNamedArgs or filling it with zero (DISP_ID_VALUE) if that is not possible

Carlos E. Ferro
  • 930
  • 10
  • 21
  • I already tried removing `rgdispidNamedArgs` at `Variant pVarResult = automation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs );` but doesn't help. – Anarkie Jan 22 '15 at 17:28
0

Sorry, I haven't paid enough attention to the signature. It is so unusual to have a BSTR * ( [in] BSTR* name ) instead of a VT_BSTR (variant on BSTR). Did you try using directly name instead of Variant(name)? Besides, second parameter in your Ruby example is 200 (number) but you use two strings, "Newyork" and "2000", to build variants in second and third arguments.

Carlos E. Ferro
  • 930
  • 10
  • 21
  • Hey Carlos I know you are trying to help but what you are doing is just commenting not actually answering, and one doesn't reply 2 answers on Stackoverflow, you can just edit your first answer. Similar behavior on other questions, may get you many down votes. My second working example is perl and I dont really understand what you mean with trying name instead of Variant(name). – Anarkie Jan 23 '15 at 12:26
  • OK, thanks for the head-up. What I meant is that you are using Variant[] rgvarg = new Variant[3]; and rgvarg[0] = new Variant(name); You build a Variant this way, but the TypeLib says the first is a (BSTR *) and not a VARIANT. – Carlos E. Ferro Jan 23 '15 at 15:43
  • All right then I will omit the first variant but I have to somehow tell the compiler which specific "Callset" I want and that is "Call_setCallDistance", how do I that... – Anarkie Jan 23 '15 at 15:56