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!