import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;
/** Simple example of native library declaration and usage. */
public class HelloWorld {
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) {
int b = simpleDLL.INSTANCE.giveIntGetInt(2);
System.out.println("Hello, World\n");
System.out.println(String.format("Argument %d", b));
}
}
这是C dll方法:
int simpleDLL::giveIntGetInt(int a)
{
return 2*a;
}
例如,这是我用64位dll:
Hello, World
Argument 181140
32位dll:
Hello, World
Argument 4