Jump to content
Excelsior Forums
bschipke

passing pointers to byte array's

Recommended Posts

Hi,

I read previous posts in here and followed what they said, but I am still having problems passing these pointers. At first I was using String's, that caused the VM to crash. Then I changed them to byte's, but I get an xFunction exception that I can't create an Argument from a byte. So now they are char[]. Now I am getting an arrayIndexOutofBoundsException.

I read that even though the Java char is 16 bits and C is char is 8, xFunction handles that so I should still use char's. So why isn't this working? Can someone help me out?

Here's what I've got:

C STRUCTURE -

typedef struct {           /* OFFSET:   */
   char                 site                 [8];       /* 0   */
   char                 service              [8];       /* 8      */
   char                 point_id             [8];       /* 16    */
   char                 long_id              [60];      /* 24    */
   char                 point_version        [8];       /* 84   */
   char                 point_type           [2];       /* 92      */
   char                 desc                 [24];      /* 94         */
   char                 units                [8];       /* 118     */
   char                 cm_record_type       [4];    /* 126     */
   char                 L2_point_type        [8];       /* 130    */
   char                 L2_size              [6];       /* 138         */
} CM_HEADER_GROUP;                            /* Size=144   */

JAVA CLASS -

class CfgMgrApiData extends Structure implements Serializable {

private char[] siteName;
private char[] svcName;
...


public String defineLayout() {

  String layout = "char[8] siteName," + 
                                       "char[8] svcName," + 
                                       "char[8] pointId," +
                   "char[60] longId," +
                   "char[8] pointVersion," +
                   "char[2] pointType," +
                   "char[24] desc," +
                   "char[8] units," +
                   "char[4] cmRecordType," +
                   "char[8] L2PointType," +
                   "char[6] L2Size";

  return layout;
}

XFUNCTION INVOKE CODE --

CfgMgrApiData apiCMData = new CfgMgrApiData();
CfgMgrApiL2Data apiL2Data = new CfgMgrApiL2Data();

 Argument szPoint   = new Argument(pointName, Argument.CSTRING);
 Pointer  pCMHeader = Pointer.createPointerTo(apiCMData);
 Pointer  pL2A      = Pointer.createPointerTo(apiL2Data);
 Argument bForUpdate = new Argument(forUpdate);

 // define array of arguments
 Argument[] args = {szPoint, pCMHeader, Pointer.NULL, bForUpdate};

 xFunction f = new xFunction("ezdnaapi", "int ReadCMRecords( " +
       "CSTRING," +
       "com.instep.ednaapi.CallEzDnaApi.CfgMgrApiData*," +
       "com.instep.ednaapi.CallEzDnaApi.CfgMgrApiL2Data*," +
       "int" +
       ")");

 Integer retVal = (Integer) f.invoke(args);
...

C FUNCTION SIGNATURE --


int WINAPI ReadCMRecords( LPCTSTR szPoint,
                                           CM_HEADER_GROUP *pCMHeader,
                                           CM_2A_Group *pL2A,
                                           int bForUpdate );

Can anyone help me out with this?

Thanks!

Share this post


Link to post
Share on other sites

Please, check that at the using of the structure all the array fields are initialized with proper size. For example, try

    private char[] siteName = new char[8];

    private char[] svcName = new char[8];

Does it help?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×