1

I am working on a project where I have some sensors and I want them to connect to a PC via USB. now they write there is a windows lib written in c and all functions are using the cdecl call convention of c and I have to be sure that if I programm in an other language (java!) that the call convention is given.

So I researched a bit and found a few tutorials to bind dlls in java and or use JNA. but this are all new things for me and I want to be sure, that it is possible (and maybe an example) - the device isn't that cheap and I want to know that before I buy it.

aircraft
  • 25,146
  • 28
  • 91
  • 166
white91wolf
  • 400
  • 4
  • 18

1 Answers1

0

You can call C code from Java - there are no issues here.

Then, if you have something very specific in your C routines, you can always go via wrapper.

Take a look here.

http://jnicookbook.owsiak.org/recipe-No-018/

In this sample, you are calling C code that - in turn - calls another library.

You can also do it by linking your JNI code with some other library. Like here:

https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo023

There are plenty of options. When it comes to JNI vs. JNA. Make sure that JNA will be efficient enough. In general, JNA tends to be slower. Take a look here:

https://github.com/mkopsnc/keplerhacks/tree/master/jnijna

Hope this helps.

I don't post codes here - all the samples in JNI Cookbook are available from github.

Oo.oO
  • 12,464
  • 3
  • 23
  • 45
  • thanks for the answer! i ask the seller of the device and hope they can help me a bit further. the aspekt with the effictient is a good point. when i have 2-3 sensors and all of them have a frequency of 40-50khz there will be a LOT of calls - or maybe they open a stream or something like that – white91wolf Apr 07 '17 at 06:47