当前位置: 技术问答>java相关
在java中如何调用API!!!!!
来源: 互联网 发布时间:2015-08-17
本文导语: 急!!!!!!! | 如果你用vj那是很容易的事情. Menu View-->Other Windows-->J/Direct Call Builder 然后选择你要调用的api,选择target为你当前的类,按Copy to target按钮 将在你的类中插入如下的内容 /**...
急!!!!!!!
|
如果你用vj那是很容易的事情.
Menu View-->Other Windows-->J/Direct Call Builder
然后选择你要调用的api,选择target为你当前的类,按Copy to target按钮
将在你的类中插入如下的内容
/**
* @dll.import("USER32", auto)
*/
public static native int MessageBox(int hWnd, String lpText, String lpCaption, int uType);
然后你就可以使用该api,以下是我以MessageBox为例的Console程序.
/**
* This class can take a variable number of parameters on the command
* line. Program execution begins with the main() method. The class
* constructor is not invoked unless an object of type 'Class1'
* created in the main() method.
*/
public class Class1
{
/**
* The main entry point for the application.
*
* @param args Array of parameters passed to the application
* via the command line.
*/
public static void main (String[] args)
{
// TODO: Add initialization code here
MessageBox(0,"Hello","HelloBox",0);
}
/**
* @dll.import("USER32", auto)
*/
public static native int MessageBox(int hWnd, String lpText, String lpCaption, int uType);
}
Menu View-->Other Windows-->J/Direct Call Builder
然后选择你要调用的api,选择target为你当前的类,按Copy to target按钮
将在你的类中插入如下的内容
/**
* @dll.import("USER32", auto)
*/
public static native int MessageBox(int hWnd, String lpText, String lpCaption, int uType);
然后你就可以使用该api,以下是我以MessageBox为例的Console程序.
/**
* This class can take a variable number of parameters on the command
* line. Program execution begins with the main() method. The class
* constructor is not invoked unless an object of type 'Class1'
* created in the main() method.
*/
public class Class1
{
/**
* The main entry point for the application.
*
* @param args Array of parameters passed to the application
* via the command line.
*/
public static void main (String[] args)
{
// TODO: Add initialization code here
MessageBox(0,"Hello","HelloBox",0);
}
/**
* @dll.import("USER32", auto)
*/
public static native int MessageBox(int hWnd, String lpText, String lpCaption, int uType);
}
|
拜托,就别提VJ了,楼主肯定不是用VJ
用JNI调用VC的DLL
用JNI调用VC的DLL