JNA calls windows APIs

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.