Java – JNA pointer retrieval value

I am using JNA to access a DLL, everything is normal... I am debugging!

The problem is that I run my java code in non - debug mode

The purpose of DLL is to fill char pointer with result by passing Somme parameter in string

So to retrieve the results in Java, I'm using the pointerbyreference object When I was debugging, there was no problem. I got the correct results, but only one feature of my results was the standard running process

This is my java call:

PointerByReference EXMES = new PointerByReference();
PointerByReference SCHAINE = new PointerByReference();
DoubleByReference dateDujour = new DoubleByReference(DATEJOUR);

log.debug(String.format("Appel avec les arguments : ECHAINE=[%s]; DATEJOUR=[%s]",echaine,sdf.format(dateEngagement)));

Map<String,Object> options = new HashMap<String,Object>();
options.put(Library.OPTION_TYPE_MAPPER,W32APITypeMapper.ASCII);

log.error(String.format("Default Charset : [%s]",Charset.defaultCharset().displayName()));
Native.setProtected(true);
MyNativeLibrary library = (MyNativeLibrary) Native.loadLibrary("myLib",MyNativeLibrary.class,options);
library = (MyNativeLibrary) Native.synchronizedLibrary(library);

String chaineAscii = new String("DATE_NAISSANCE\n19780102\nMEDIA\n4\n".getBytes(Charset.forName("US-ASCII")));

log.error(String.format("ECHAINE [%s]",chaineAscii));

library.SATINTS(chaineAscii,SCHAINE,dateDujour,EXMES);

String chaineSortie = new String(SCHAINE.getPointer().getString(0,false).getBytes(Charset.forName("US-ASCII")));
String chaineExmes = new String(EXMES.getPointer().getString(0,false).getBytes(Charset.forName("US-ASCII")));

log.debug(String.format("Retour taille Prexis : SCHAINE=[%d]; EXMES=[%d]",chaineSortie.length(),chaineExmes.length()));
log.debug(String.format("Retour Prexis : SCHAINE=[%s]; EXMES=[%s]",chaineSortie,chaineExmes));

This is an excerpt from my c function:

#define PRX_ALPHA char
#define EALPHA PRX_ALPHA *
#define SALPHA PRX_ALPHA *

EALPHA CHAINE;
SALPHA SCHAINE;
EDATE DATEJOUR;
SALPHA EXMES;

int winapi myFunction(
CHAINE,DATEJOUR,EXMES
) {


// Do something with the CHAINE and DATEJOUR then fill SCHAINE and EXMES with an answer
to my call

For every help in advance, I was trapped

Solution

Pointerbyreference is equivalent to void * * in C This does not match your native function prototype

String is equivalent to const char * Any changes made by your native code to the memory pointed to by this parameter will be ignored If you want to provide native code for populating the buffer, use byte [] or memory

You can then use memory GetString (0) or native ToString (byte []) constructs a Java string from the result instead of using a rather lengthy string constructor

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>