Using C++ library in java
c++, java, static-libraries
Solution
To use functions from a `.lib`, you have to create JNI wrapper functions for these library functions, and then link them together with your library into a `.dll`.
Example:
Assuming you have a function in your C++ library headers with this signature:
int example(int a, int b);
Create a function wrapper in C++:
JNIEXPORT jint JNICALL Java_MyClass_example (JNIEnv* env, jobject obj, jint a, jint b) {
return (jint) example(a, b);
}
Link the library and the wrapper into a DLL
Create a Java class with the native method:
public class MyClass {
public native int example(int a, int b);
}
Load the DLL using the `System.loadLibrary` function (or similar)
- Now you can call the `example` method on an object of `MyClass`
Problem
I am new to this forum, so please excuse me if i cannot put my question in a right way. I want help in using a `C++(.lib and.h)` files in `java`. I want to use methods of that `.lib` file in my java code . Prototype of function is like : ``` FunctionXYZ(BYTE *Data1, BYTE *Data2, BYTE *Data3, int Data4); ``` Environment i would be using is centOS. Thank you in advance P.S: I do not have source code for this .lib