howto do [in,out] struct, without automation

Help
Erlend
2008-01-25
2013-06-05
  • Erlend

    Erlend - 2008-01-25

    Hi

    I’ve been using jinterop 1.23 for a couple of weeks now and it works quite well. However I struggle a bit with this call:

    HRESULT ReadRaw (
    [in, out] OPCHDA_TIME *htStartTime,
    [in, out] OPCHDA_TIME *htEndTime,
    [in] DWORD dwNumValues,
    [in] BOOL bBounds,
    [in] DWORD dwNumItems,
    [in, size_is(dwNumItems)] OPCHANDLE * phServer,
    [out, size_is(,dwNumItems)] OPCHDA_ITEM ** ppItemValues,
    [out, size_is(,dwNumItems)] HRESULT ** ppErrors
    );

    Where OPCHDA_TIME is defined as:
    typedef struct {
    BOOL bString;
    [string] LPWSTR szTime;
    FILETIME ftTime;
    } OPCHDA_TIME;

    And FILETIME is
    typedef struct {
    DWORD dwLowDateTime;
    DWORD dwHighDateTime;
    } FILETIME;

    It seems like there is a problem with the way I pass the OPCHDA_TIME struct to the JICallObject, the rest of the call is similar to other calls which are working fine. I have tried different approaches without success, so I would be very grateful for any help I can get.

     
    • Vikram Roopchand

      Hi ,
          Could you please put your Java code here for this call ?

      thanks,
      best regards,
      Vikram

       
    • Erlend

      Erlend - 2008-01-28

      Hi Vikram

      Thanks for the response, this is the javacode attemting to do the call :

      callReadRaw(long startSeverTime,long endpServerTime, Integer[] serverHandles) throws JIException {
          ...

          //[in, out] tagOPCHDA_TIME* htStartTime
          callObject.addInParamAsPointer(new JIPointer(start.getStruct()), JIFlags.FLAG_NULL);
          //[in, out] tagOPCHDA_TIME* htEndTime,
          callObject.addInParamAsPointer(new JIPointer(end.getStruct()), JIFlags.FLAG_NULL);
          //should it be added out as well?
          //callObject.addOutParamAsObject(new JIPointer(OPCHDATime.getEmptyStruct()), JIFlags.FLAG_NULL);
          //callObject.addOutParamAsObject(new JIPointer(OPCHDATime.getEmptyStruct()), JIFlags.FLAG_NULL);
             
          // [in] unsigned long dwNumValues
          callObject.addInParamAsInt(10, JIFlags.FLAG_NULL);
         
          // [in] long bBounds,
          callObject.addInParamAsInt(0, JIFlags.FLAG_NULL);
          // callObject.addInParamAsBoolean(false, JIFlags.FLAG_NULL);//short or bool instead?
             
          // [in] unsigned long dwNumItems,
          callObject.addInParamAsInt(serverHandles.length, JIFlags.FLAG_NULL);

          JIArray tagsInput = new JIArray(serverHandles, true);
          // [in] unsigned long* phServer
          callObject.addInParamAsArray(tagsInput, JIFlags.FLAG_NULL);
          JIArray okResult = new JIArray(OPCHDAItem.getEmptyStruct(), null, 1,true);

          // [out] tagOPCHDA_ITEM** ppItemValues
          callObject.addOutParamAsObject(new JIPointer(okResult),JIFlags.FLAG_NULL);

          // [out] HRESULT** ppErrors
          JIArray errout = new JIArray(Integer.class, null, 1, true);
          callObject.addOutParamAsObject(new JIPointer(errout), JIFlags.FLAG_NULL);

          ...

      JIStruct getStruct() throws JIException{
          JIStruct retur= new JIStruct();
          retur.addMember(new Integer((useStringbasedTime?1:0)));
          //retur.addMember(new Boolean(useStringbasedTime));//short or bool instead?
         
          String time="";
          if(useStringbasedTime){
              time=szTime;
          }
          JIString szTimeToAdd=new JIString ( time , JIFlags.FLAG_REPRESENTATION_STRING_LPWSTR );
             
          //retur.addMember(new JIPointer(szTimeToAdd));
          retur.addMember(szTimeToAdd);
          if(useStringbasedTime){
              absHigh=0;
              absLow=0;
          }
          //retur.addMember(new JIPointer(getFileTimeStruct()));
          retur.addMember(getFileTimeStruct());
          return retur;
      }

      JIStruct getFileTimeStruct() throws JIException {
          JIStruct fileTime= new JIStruct();
          fileTime.addMember(new Integer(absLow));
          fileTime.addMember(new Integer(absHigh));
          return fileTime;
      }

      Left in some commented out code (things I changed back and to trying and failing;) ). Hope you see an obvious mistake in my code, thanks again for the help.

      Best regard
      Erlend

       
    • Erlend

      Erlend - 2008-02-01

      Hi again

      Just letting you know that I found what I did wrong, basically I just had to set the isReferenceTypePtr flag to true on the pointers marked as [in, out] and add an empty struct as out object.

      Keep up the good work, best regards
      -erlend

       
      • Regis Fontes

        Regis Fontes - 2009-02-20

        Hello Erlend and Vikram,

        I'm having the same problem described in this post, but couldn't figure out what was the solution. How did your source code looked like after it was corrected? Could you please post it?

        Best regards,
        Regis.

         
      • BjoernK

        BjoernK - 2013-06-05
        Post awaiting moderation.
    • Regis Fontes

      Regis Fontes - 2009-02-26

      Follow the source code in its current form. I've tried many different ways, but always get the error that I'm passing incorrect parameters. I'm using J-interop 2.05. Are the (in, out) parameters being passed the right way?

          /*
          HRESULT ReadProcessed (
          [in, out] OPCHDA_TIME *htStartTime,
          [in, out] OPCHDA_TIME *htEndTime,
          [in] FILETIME ftResampleInterval,
          [in] DWORD dwNumItems,
          [in, size_is(dwNumItems)] OPCHANDLE * phServer,
          [in, size_is(dwNumItems)] DWORD* haAggregate,
          [out, size_is(,dwNumItems)] OPCHDA_ITEM ** ppItemValues,
          [out, size_is(,dwNumItems)] HRESULT ** ppErrors
          );
      */
          public void readProcessed(OPCHDATIME p_StartDate, OPCHDATIME p_EndDate, FILETIME p_Sample, Integer[] p_ServerHandles, Integer[] p_Aggregates) throws JIException
          {
              JICallBuilder v_BuilderObj = new JICallBuilder(true);
              v_BuilderObj.reInit();
              v_BuilderObj.setOpnum(1);

              JIArray p_ServerArray = new JIArray(p_ServerHandles, true);
              JIArray p_AggregateArray = new JIArray(p_Aggregates, true);
              JIArray v_OKResult = new JIArray(OPCHDAITEM.GetStruct(), null, 1,true);
              JIArray v_Errors = new JIArray(Integer.class, null, 1, true);

              v_BuilderObj.addInParamAsPointer(new JIPointer(p_StartDate.getStruct(), true), JIFlags.FLAG_NULL);
              v_BuilderObj.addInParamAsPointer(new JIPointer(p_EndDate.getStruct(), true), JIFlags.FLAG_NULL);
              v_BuilderObj.addOutParamAsObject(new JIPointer(OPCHDATIME.GetStruct()), JIFlags.FLAG_NULL);
              v_BuilderObj.addOutParamAsObject(new JIPointer(OPCHDATIME.GetStruct()), JIFlags.FLAG_NULL);
              v_BuilderObj.addInParamAsStruct(p_Sample.getValue(), JIFlags.FLAG_NULL);
              v_BuilderObj.addInParamAsInt(p_ServerHandles.length, JIFlags.FLAG_NULL);
              v_BuilderObj.addInParamAsArray(p_ServerArray, JIFlags.FLAG_NULL);
              v_BuilderObj.addInParamAsArray(p_AggregateArray, JIFlags.FLAG_NULL);
              v_BuilderObj.addOutParamAsObject(new JIPointer(v_OKResult),JIFlags.FLAG_NULL);
              v_BuilderObj.addOutParamAsObject(new JIPointer(v_Errors), JIFlags.FLAG_NULL);

              Object v_Result[] = getCOMObject().call(v_BuilderObj);

      //(...)

          }

       
  • BjoernK

    BjoernK - 2013-04-15

    Does anyone have a solution now?

     
  • BjoernK

    BjoernK - 2013-04-15

    I have the following error

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 116
    at ndr.NdrBuffer.dec_ndr_small(NdrBuffer.java:113)
    at ndr.NetworkDataRepresentation.readUnsignedSmall(NetworkDataRepresentation.java:58)
    at org.jinterop.dcom.core.JIMarshalUnMarshalHelper$StringImpl.deserializeData(JIMarshalUnMarshalHelper.java:1241)
    at org.jinterop.dcom.core.JIMarshalUnMarshalHelper.deSerialize(JIMarshalUnMarshalHelper.java:328)
    at org.jinterop.dcom.core.JIPointer.decode(JIPointer.java:228)
    at org.jinterop.dcom.core.JIMarshalUnMarshalHelper.deSerialize(JIMarshalUnMarshalHelper.java:281)
    at org.jinterop.dcom.core.JIString.decode(JIString.java:161)
    at org.jinterop.dcom.core.JIMarshalUnMarshalHelper.deSerialize(JIMarshalUnMarshalHelper.java:299)
    at org.jinterop.dcom.core.JIPointer.decode(JIPointer.java:228)
    at org.jinterop.dcom.core.JIMarshalUnMarshalHelper.deSerialize(JIMarshalUnMarshalHelper.java:281)
    at org.jinterop.dcom.core.JICallBuilder.readPacket(JICallBuilder.java:1016)
    at org.jinterop.dcom.core.JICallBuilder.read(JICallBuilder.java:956)
    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)

    It looks like o problem with the out parameters in my opinion

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks