Before I came into contact with JNA, I always thought that JNI or SWT must be used to call the local linked library function. I did not see JNA in one day and found that JNA can also implement such calls, so I tried it well based on the example on the website, so I had a little bit of interest, so I wrote two more questions.
Getlogicaldrivestringsa [obtain the logical drive letter of the local system]
Getsystemdirectorya [obtain the system directory]
Public interface Kernel32 extends library {
Kernel32 instance = (Kernel32) Native. loadlibrary ("Kernel32", kernel32.class );
Int getlogicaldrivestringsa (INT length, byte [] buffer );
Int getsystemdirectorya (byte [] buffer, int size );
}
The call method is as follows:
Public class maindemo ...{
Public static void main (string [] ARGs )...{
Kernel32 Lib = kernel32.instance;
Byte [] buffer2 = new byte [1, 100];
Lib. getlogicaldrivestringsa (buffer2.length/2, buffer2 );
For (byte BT: buffer2)
...{
System. Out. Print (char) BT );
}
System. Out. println ();
Byte [] buffer = new byte [50];
Lib. getsystemdirectorya (buffer, 50 );
For (byte BT: buffer)
...{
System. Out. Print (char) BT );
}
}
}
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/zhangjianying/archive/2008/01/25/2064911.aspx