troubleshooting Question

Convert C uint8_t pointer to Java representation using JNI

Avatar of cgray1223
cgray1223 asked on
5 Comments1 Solution3250 ViewsLast Modified:

I have a C function that returns a pointer to a uint8_t (1 byte unsigned integer).  I'm attempting to wrap this function using SWIG/JNI but I would like to cast the actual pointer to the uint8_t.  The JNI pointer is a long.  The below code is from the SWIG interface file.  The void2int8 method does not return the proper value, so I believe the cast is wrong.  The void2str method does work , so I added it here just for reference even though its a separate data type.

long cPtr = $jnicall;
Object oInt = void2int8(cPtr);
Object oStr = void2str(cPtr);

uint8_t void2int8(jlong v) {
  return (uint8_t)v;

const char* void2str(jlong v) {
  return (const char*)v;
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros