referencing DLL code from Java
List Four demo code reference DLL functions
public interface CLibrary extends Library {
CLibrary INSTANCE1 = (CLibrary)
Native.loadLibrary((Platform.isWindows() ? "nativecode" : "c"),
CLibrary.class);
int helloWorld(int divider);
}
public static void main(String[] args) {
CLibrary.INSTANCE1.helloWorld(77));
}
Listing four, accessing DLL functions
In list four, the Clibrary instance is created. This object allows the specified DLL to be downloaded. Next, is the loading process of the library, which needs to be marked from the library--in the case of listing four, there is only one flag, called HelloWorld ().
List five shows the program from listing four code
C:\jnacode>java HelloWorld
Value is 1
Listing five, the code for the calling DLL
In the list V there's nothing to be surprised about--the value 77 is allowed into the function. Then inside the function, the parameter (77) is removed by 77, and the answer is: 1.
When I try to solve the DLL problem and relate to the calling convention, I want to look at the process of building the DLL. Fortunately, you can achieve this through a tool called Dependency Walker, through dependency Walker you can see the DLL generation process. To achieve this, you need to download a free copy of Dependency Walker, open it, and then load the DLL inside. You can see similar content as shown in Figure one.
Figure I, DLL internal information