Since the first attempt to use Java encapsulation to call C's DLL in early May, it has gone through 3 small projects.
At the end of last month was the most recent project, the task came in a very short time, but also after working overtime to complete the task, and the second non-implementation of the implementation of the function (C's SDK to get the picture after the Java from memory to save to local).
Time has passed nearly 1 months, now the original "conquer" the small problems to record.
Now speaking of the state, the C SDK is the camera's SDK, using the account password to log in to the camera, and register a callback, when the camera has a snapshot will trigger a callback function, and then Java to remove the data from the SDK to save.
What I haven't done before is java. The picture pointer returned by the SDK takes the picture out of memory, and this time the small project has been well researched.
Implementing the key code is as follows:
1. First structure that returns data in the SDK
typedef struct TAGPHOTOHANDLER{CHAR *apcdata[pic_num];//A pointer array of picture data ulong auldatalen[pic_num];//data length per picture ...}
2. Then the Java package for this struct
public static class Tagphotohandler extends Structure{public static class Byreference extends Mystructur implements Struct Ure. Byreference{}public bytebyreference[] Apcdata = new Bytebyreference[pic_num];p ublic int[] Auldatalen = new Int[PIC_NUM];. ..}
3, Java through the pointer to the memory to fetch data
Tagphotohandler.byreference tumph = new Tagphotohandler.byreference (); bytebyreference[] Picdata = tumph.apcdata; Pointer p = picdata[i].getpointer (); byte[] image = P.getbytearray (0,tumph.auldatalen[i]);
4, some other more practical things
Pointer pconfig = new Memory (length);//pointer to struct public static <t extends structure> T pointer2structure (Pointer pparam ,class<t> res) {T Param; Param = Res.newinstance (); Pointer facepointer = Param.getpointer () facepointer.write (0,pparam.getbytearray (0,param.size ()), 0,Param.size ()); Param.read (); return Param;}
Java-jna User Experience 2