Here i am calling giveIntGetInt(int a) function from JAVA .
C++ DLL
int simpleDLL::giveIntGetInt(int a)
{
int result = a *2;
return result;
}
JAVA Method to call C++ function using JNA
public class Main {
public interface simpleDLL extends Library {
simpleDLL INSTANCE = (simpleDLL) Native.loadLibrary(
(Platform.isWindows() ? "simpleDLL" : "simpleDLLLinuxPort"), simpleDLL.class);
int giveIntGetInt(int a); // int giveIntGetInt(int a);
}
public static void main(String[] args) {
System.loadLibrary("simpleDLL");
simpleDLL sdll = simpleDLL.INSTANCE;
int a = 3;
int result1 = sdll.giveIntGetInt(a);
System.out.println("giveIntGetInt("+a+"): " + result1);
}
}
Output
giveIntGetInt(3): 181972
Whhy am i getting a Garbage value when the result should be 6 ? Am i correctly mapping to the Java type to Native type ? What am i missing here ?
Thank You