--------------------------------------------Java Call Win32 API-----------------------------------------
下载地址:http://www.jinvoke.com/calling-the-win32-api-from-java
简单的例子:
import com.jinvoke.JInvoke;
import com.jinvoke.NativeImport;
public class HelloWindows {
@NativeImport(library="User32",function="MessageBox")
public static native int showMessage(int hwnd,String text,String caption,int type);
public static void main(String[] args){
JInvoke.initialize();
showMessage(0,"Hello welcome","hello-world",0);
}
}
注解方式有三种:
1 @NativeImport 连接上本地DLL,调用DLL内的方法
2 @NativeStruct represent a native structure (a C struct) as a Java class.
3 @Embedded define fixed-size strings and arrays in structs.
--------------------------------@NativeStruct例子--------------------------------------------------
Struct C :
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME;
java.class:
@NativeStruct
public class SYSTEMTIME {
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
-------------------------------------@Embedded例子------------------------------------------------------
Struct C:
typedef struct _SHFILEINFO {
HICON hIcon;
int iIcon;
DWORD dwAttributes;
TCHAR szDisplayName[MAX_PATH];
TCHAR szTypeName[80];
} SHFILEINFO;
java.class
@NativeStruct
public class ShFileInfo {
public int hIcon;
public int iIcon;
public int dwAttributes;
@Embedded(length=260)
public StringBuffer szDisplayName = new StringBuffer(260);
@Embedded(length=80)
public StringBuffer szTypeName = new StringBuffer(80);
}