Jump to content
Excelsior Forums

Problem dereferencing a Pointer

Recommended Posts


i have a problem passing a structure from Java to a C-DLL and vice versa.

The structure looks like this:

typedef struct Userdata


     char* username;

     char pw[sLC_MD5_DIGESTSIZE];

     int pwlen;

     char* completename;

} TUserData;

The called functions header looks like:

__declspec(dllexport) int __stdcall createUser (TUserData* userdata);

The DLL will be called from java with

     f = new xFunction(dllName,

                 "int " + funcName + "(" + ccdefPackage +


     Pointer arg1 = null;

     arg1 = Pointer.createPointerTo(accountdata);

     errVal = ( (Integer) f.invoke(arg1)).intValue();

     accountData = (UserAccountStruct) arg1.deref();

After dereferencing the argument 1, the char- array has lost the last two charactes. The starting size is 16, after dereferencing the size of the array is 14.

Have anybody seen this before? How can i solve the problem?

Best regards


Share this post

Link to post
Share on other sites

The UserAccountStruct is defined like this:

public class UserAccountStruct

   extends Structure

   implements UseraccountIf


 public static final int SLC_MD5_DIGESTSIZE = 16;

 String username = "";

 char[] pw = new char[sLC_MD5_DIGESTSIZE];

 int pwlen = 0;

 String completeName = "";

public String defineLayout()


   String str =

     "CSTRING username, " +

     "char[" + Integer.toString(SLC_MD5_DIGESTSIZE - 2) + "] pw, " +

     "int pwlen, " +

     "CSTRING completeName";

      return str;





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