0

I am trying to create a single Pointer object using the JNA library and set it to "point" to an object of a custom data type defined.

Can someone please explain how to do this?

CustomType ctype = new CustomType();
Pointer pointer = new Pointer(ctype);

This does not work. I have tried searching and googling but none of the questions I found have shown what I need.

3
  • How do you expect your native code to use the pointer you give it? Commented Mar 12, 2015 at 3:05
  • It should write something into the custom data type. A set of numbers which can be translated to status codes. Commented Mar 12, 2015 at 7:57
  • This might be answering my own question but it seems I should define the custom data type as a sublase of structure. Commented Mar 12, 2015 at 8:26

2 Answers 2

1

Use a subclass of com.sun.jna.Structure and pass that object directly to your mapped method. JNA will automatically take care of synchronizing the native data and pass a pointer to that data to the native method.

Refer to JNA's documentation on how to use Structures and the FAQ.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm trying but I can't instantiate an object of this new class for some reason. I made a separate question here if you have any thoughts: stackoverflow.com/questions/29010272/…
0

Okay, so as I stated in the comment, the sollution was to make the custom data type a subclass of JNA structure which has a getPointer() method.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.