Menu

OUT parameter values

techhunt
2011-06-14
2013-09-18
  • techhunt

    techhunt - 2011-06-14

    Topic on how to specify out parameters for method calls and get values from out parameters.

     
  • techhunt

    techhunt - 2011-06-14

    I am trying to execute GetOwner Method of Win32_Process class.

    Syntax of the method:
    uint32 GetOwner(
        string User,
        string Domain
    );

    Code implementation:

    Object methodParams = new Object {
    new JIVariant("User"),
    new JIVariant("Domain")
    };

    JIVariant result = super.objectDispatcher.callMethodA("GetOwner", methodParams);

    this is not giving any exception. but result array is not having any values for user and domain values.

    How to pass OUT parameters for method calling and how to retrieve values from out parameters.

     
  • Anonymous

    Anonymous - 2011-06-15

    use the constructor:

    new JIVariant(XXX, true)

    …for your out params.

     
  • techhunt

    techhunt - 2011-06-15

    Thanks for the reply.

    I am finding difficulty in passing array of integers as an argument

    class __PARAMETERS
    {
    uint16 PasswordLen;
    uint8 Password;
    };

                             int scancodes = {30,46,18,19,0,0,0,0};
                             JIArray codes = new JIArray(scancodes);

    inParams.getObjectDispatcher().put("PasswordLen", new JIVariant(4));
    inParams.getObjectDispatcher().put("Password", new JIVariant(codes));

    How to set password for  inParam?

     
  • techhunt

    techhunt - 2011-06-22

    new JIVariant(XXX, true) is working fine if the out parameters type is string.

    How to specify the out parameter whose type is uint32?

     
  • Vikram Roopchand

    Hi,
         Please look at the JIVariant Javadocs "OutParamForType" (I think).

    best regards,
    Vikram

     
  • danilop

    danilop - 2011-06-22

    Hi,
    I tried -

    JIVariant processId = JIVariant.OUTPARAMforType(JIUnsignedInteger.class, false);

    JIVariant results = wbemObjectSet_dispatch.callMethodA("Create", new Object{ new JIString("calc"), JIVariant.OPTIONAL_PARAM(), processId});

    System.out.println(results.getObjectAsInt());
    System.out.println(processId);

    But getting a null for my processId. FYI… The result is 0 which I see that the calc.exe is successfully started.

    Thanks in advance for any help.

     
  • Vikram Roopchand

    Hi,
         The out params are returned from index 1 in the results and I think in the reverse order (if more than one, but you need to verify this last part).

    thanks,
    best regards,
    Vikram

     
  • danilop

    danilop - 2011-06-23

    Hi Vikram,

    Thank you for the quick response. My results only has index 0 when I tried
    JIVariant processId = JIVariant.OUTPARAMforType(JIUnsignedInteger.class, false);

    but when I tried
    JIVariant processId = JIVariant.OUTPARAMforType(Object.class, false);
    I get 2 items in my results where the second return value is [[[]]]

    I even tried JIVariant processId = JIVariant.OUTPARAMforType(JIUnsignedInteger.class, false);
    but I still get a null value back.

    It seems though we are not able to get unsigned int 32 bits. Any work around or suggestions?

    Thanks again.

     
  • Vikram Roopchand

    Hi,
         Could you try this  "JIVariant(IJIUnsigned, boolean)" ctor (pass "true" for the boolean param and "0" in the JIUnsignedFactory for IJIUnsigned but of the right type). Pass the created JIVariant as the  param.

    thanks,
    best regards,
    Vikram

     
  • techhunt

    techhunt - 2011-06-24

    I have a situation where i am looping callMethodA and getting the output parameters from output parameter dispatcher  for 4 times.

    I am getting proper response until looping for 2 times. when the loop is executed for 3rd time the following error code is returned. "The object invoked has disconnected from its clients. -2147417848"

    It seems it is caused from  RPC_E_DISCONNECTED  -2147417848 error.

    Any suggestions on how to avoid this?
    Do i have to increase any default time set to hold the connection?

    -Thanks

     
  • danilop

    danilop - 2011-06-24

    Hi,

    I tried your suggestions with the following code but then I get the below error:
    // Create the out parameter for the uint32 processId
    IJIUnsigned myUINT32 = JIUnsignedFactory.getUnsigned(new Long(0), JIFlags.FLAG_REPRESENTATION_UNSIGNED_INT);
    JIVariant processId = new JIVariant(myUINT32, true);

    results = wbemObjectSet_dispatch.callMethodA("Create", new Object{ new JIString("calc"), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), processId});

    org.jinterop.dcom.impls.automation.JIAutomationException: Exception occurred. 
    at org.jinterop.dcom.impls.automation.JIDispatchImpl.invoke(JIDispatchImpl.java:333)
    at org.jinterop.dcom.impls.automation.JIDispatchImpl.callMethodA(JIDispatchImpl.java:520)
    at org.jinterop.dcom.impls.automation.JIDispatchImpl.callMethodA(JIDispatchImpl.java:526)
    at org.jinterop.dcom.impls.automation.JIDispatchImpl.callMethodA(JIDispatchImpl.java:477)
    at org.jinterop.dcom.test.CallPgmRemotely.performOp(CallPgmRemotely.java:68)
    at org.jinterop.dcom.test.CallPgmRemotely.main(CallPgmRemotely.java:123)
    Caused by: org.jinterop.dcom.common.JIRuntimeException: Exception occurred. 
    at org.jinterop.dcom.core.JICallBuilder.readResult(JICallBuilder.java:1079)
    at org.jinterop.dcom.core.JICallBuilder.read(JICallBuilder.java:957)
    at ndr.NdrObject.decode(NdrObject.java:36)
    at rpc.ConnectionOrientedEndpoint.call(ConnectionOrientedEndpoint.java:137)
    at rpc.Stub.call(Stub.java:113)
    at org.jinterop.dcom.core.JIComServer.call(JIComServer.java:901)
    at org.jinterop.dcom.core.JIComServer.call(JIComServer.java:856)
    at org.jinterop.dcom.core.JIComObjectImpl.call(JIComObjectImpl.java:266)
    at org.jinterop.dcom.core.JIComObjectImpl.call(JIComObjectImpl.java:153)
    at org.jinterop.dcom.impls.automation.JIDispatchImpl.invoke(JIDispatchImpl.java:315)
    … 5 more

    My code for the test program is below:

    import java.net.UnknownHostException;
    import java.util.logging.Level;

    import org.jinterop.dcom.common.JIException;
    import org.jinterop.dcom.common.JISystem;
    import org.jinterop.dcom.core.IJIComObject;
    import org.jinterop.dcom.core.IJIUnsigned;
    import org.jinterop.dcom.core.JIComServer;
    import org.jinterop.dcom.core.JIFlags;
    import org.jinterop.dcom.core.JIProgId;
    import org.jinterop.dcom.core.JISession;
    import org.jinterop.dcom.core.JIString;
    import org.jinterop.dcom.core.JIUnsignedFactory;
    import org.jinterop.dcom.core.JIVariant;
    import org.jinterop.dcom.impls.JIObjectFactory;
    import org.jinterop.dcom.impls.automation.IJIDispatch;

    public class CallPgmRemotely2 {

    private JIComServer comStub = null;
    private IJIComObject comObject = null;
    private IJIDispatch dispatch = null;
    private String address = null;
    private JISession session = null;
    public CallPgmRemotely2(String address, String args) throws JIException, UnknownHostException
    {
    this.address = address;
    session = JISession.createSession(args,args,args);
    session.useSessionSecurity(true);
    session.setGlobalSocketTimeout(5000);
    comStub = new JIComServer(JIProgId.valueOf("WbemScripting.SWbemLocator"),address,session);
    IJIComObject unknown = comStub.createInstance();
    comObject = (IJIComObject)unknown.queryInterface("76A6415B-CB41-11d1-8B02-00600806D9B6");
    dispatch = (IJIDispatch)JIObjectFactory.narrowObject(comObject.queryInterface(IJIDispatch.IID));
    }

    public void performOp() throws JIException, InterruptedException
    {
    JIVariant results = dispatch.callMethodA("ConnectServer",new Object{new JIString(address),JIVariant.OPTIONAL_PARAM(),
    JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM() ,JIVariant.OPTIONAL_PARAM(),JIVariant.OPTIONAL_PARAM(),
    new Integer(0),JIVariant.OPTIONAL_PARAM()});

    IJIDispatch wbemServices_dispatch = (IJIDispatch)JIObjectFactory.narrowObject((results).getObjectAsComObject());

    // Get the Win32_Process handle
    results = wbemServices_dispatch.callMethodA("Get", new Object{ new JIString("Win32_Process"), new Integer(0), JIVariant.OPTIONAL_PARAM()});

    // Get its dispatch
    IJIDispatch wbemObjectSet_dispatch = (IJIDispatch)JIObjectFactory.narrowObject((results).getObjectAsComObject());

    // Create the out parameter for the uint32 processId
    IJIUnsigned myUINT32 = JIUnsignedFactory.getUnsigned(new Long(0), JIFlags.FLAG_REPRESENTATION_UNSIGNED_INT);
    JIVariant processId = new JIVariant(myUINT32, true);

    results = wbemObjectSet_dispatch.callMethodA("Create", new Object{ new JIString("calc"), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), processId});
    //System.out.println(results.getObjectAsInt());
    System.out.println(results);
    System.out.println(processId);

    }

    private void killme() throws JIException
    {
    JISession.destroySession(session);
    }

    public static void main(String args) {

    try {
    if (args.length < 4)
        {
        System.out.println("Please provide address domain username password");
        return;
        }

    JISystem.getLogger().setLevel(Level.OFF);
    JISystem.setInBuiltLogHandler(false);
    JISystem.setAutoRegisteration(true);
    CallPgmRemotely2 test = new CallPgmRemotely2(args,args);
    test.performOp();
    test.killme();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    }

    I tried JIUnsignedFactory of all three unsigned types but am still getting the error.  Thanks so much for your help.

     
  • danilop

    danilop - 2011-06-24

    BTW… I did see that the "Create" gets called correctly by checking for the calc.exe is in the Windows Task Manager but I think we are still having an issue of getting the out parm (ProcessId - uint32) back.

     
  • Vikram Roopchand

    Hi,
       Can you check the getEXcepInfo method of JIAutomationException and let me know the detailed message ?

    thanks,
    best regards,
    Vikram

     
  • Vikram Roopchand

    @Techhunt

    Hi,
         This should not happen. Which version of j-Interop are you on ? Can you post a wireshark capture to the professional support address ?

    thanks,
    best regards,
    Vikram

     
  • danilop

    danilop - 2011-07-06

    Hi,

    I'm getting the following errors :  [0, 0, [Type: 1 , ], [Type: 1 , ], [Type: 1 , ], 0, , , -2147352571]

     
  • Vikram Roopchand

    Hi,
         Can you also try with a regular long (not unsigned) ? Type mismatch issues are hard to debug.

    thanks,
    best regards,
    Vikram

     
  • danilop

    danilop - 2011-07-07

    Thanks!
    I tried long and it didn't work. But when I tried int it did. It returned the value in the result array.

    Thanks again for your help.

     
    • beyonddc

      beyonddc - 2013-09-18

      Just to add some additional information to this post in case someone hits similar problem.

      What Vikram meant to try a different type is as follow, described in below code. The processID will then be available in the results array.

              JIVariant processID = new JIVariant(0, true);
      
              Object[] paramsToExecute =
                  new Object[] {
                      new JIString(cmd),
                      JIVariant.OPTIONAL_PARAM(),
                      JIVariant.OPTIONAL_PARAM(),
                      processID,
                  };
      
              JIVariant[] results =
                  wbemObject.callMethodA(
                          "Create",
                          paramsToExecute);
      
       
  • Anonymous

    Anonymous - 2011-10-17

    Hi

    I am trying to call getowner method of Win32_Process and my code looks like following

    params = new Object { new JIString("Select * from Win32_Process"), JIVariant.OPTIONAL_PARAM(),
            new JIVariant(new Integer(RETURN_IMMEDIATE)) };
    JIVariant servicesSet = wbemServices.callMethodA("ExecQuery", params);
    IJIDispatch wbemObjectSet = (IJIDispatch) narrowObject(servicesSet.getObjectAsComObject());

    JIVariant newEnumvariant = wbemObjectSet.get("_NewEnum");
    IJIComObject enumComObject = newEnumvariant.getObjectAsComObject();
    IJIEnumVariant enumVariant = (IJIEnumVariant) narrowObject(enumComObject.queryInterface(IJIEnumVariant.IID));
    JIVariant countVariant = wbemObjectSet.get("Count");
    int numberOfProcess = countVariant.getObjectAsInt();
    Object elements = enumVariant.next(numberOfServices);
    JIArray aJIArray = (JIArray) elements;
    JIVariant array = (JIVariant) aJIArray.getArrayInstance();
    for (JIVariant variant : array) {
        IJIDispatch wbemObjectDispatch = (IJIDispatch) narrowObject(variant.getObjectAsComObject());
        JIVariant v1 = wbemObjectDispatch.callMethodA("GetObjectText_", new Object { 1 });
        Object methodParams = new Object {
    new JIVariant("User", true),
    new JIVariant("Domain", true),
    };

    JIVariant result = wbemObjectDispatch.callMethodA("GetOwner", methodParams);
    System.out.println(((JIVariant)methodParams).getObjectAsString2());
    System.out.println(((JIVariant)methodParams).getObjectAsString2());
    }

    But I am getting string "User" and "Domain" as output not the value of user and domain

     

Log in to post a comment.