2 ms·
JNI is a bit different - you have to write code in C or C++ that wraps native APIs you want to call, in a certain very specific way that then makes it possible
by int_19h 6y ago
JNI is a bit different - you have to write code in C or C++ that wraps native APIs you want to call, in a certain very specific way that then makes it possible to call it via methods declared as "native" in Java.
P/Invoke does not require such a layer - you simply declare enums, structs, and functions from the native API directly in your C# code, and then you can call them.
For those familiar with Python, the Java way is more like writing a Python extension module in C, and the C# way is more like using ctypes (but way faster).
Java has some third party libraries that are basically P/Invoke equivalent; JNA is probably the most used one.