jnr / jnr-ffi

Java Abstracted Foreign Function Layer
Other
1.26k stars 157 forks source link

How to use GBK encoding #277

Open seacdr opened 3 years ago

seacdr commented 3 years ago

The return string of my dynamic library is GBK coded jna use System.setProperty("jna.encoding", "GBK"). success! how can I read the correct return string? thanks!

jnr code:

SSCardDriver_API libcSI = LibraryLoader.create(SSCardDriver_API.class).load("SSCardDriver");
StringBuffer pOutInfo = new StringBuffer(1024);
int nCode = libcSI.iReadCardBas(3, pOutInfo);
log.debug("{}=iReadCardBas({},{})", nCode, 3, pOutInfo.toString());

-11=iReadCardBas(3,���������Ӵ�)

jna code:

System.setProperty("jna.encoding", "GBK");
Pointer pOutInfo = new Memory(1024);
int nCode = SSCardDriver_Library.INSTANCE.iReadCardBas(3, pOutInfo);
log.debug("{}=iReadCardBas({},{})", nCode, 3, pOutInfo.getString(0));

-11=iReadCardBas(3,读卡器连接错)
headius commented 3 years ago

Short term you will probably have to read raw bytes and decode them as GBK, but this should be fixed/improved.

Could you please provide an example piece of code that does not depend on this library?