我是新手,我正在測試JNA jar庫,正好是jna-4.1.0.jar
和jna-platform-4.1.0.jar
。我想通過編寫我自己的JNI代碼來學習如何做JNA所做的工作
我使用Kernel32,User32,WinBase,WinDef,WinN和WinUser dll測試了性能。
但是,現在我不希望使用JNA(我知道是好,容易)我想用JNI(這麼難),而不是(也許我溯)!
我想擺脫依賴於外部JAR Java文件
問題:什麼對象可以更換JNA對象像用純Java對象?
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Structure;
import com.sun.jna.Pointer;
import com.sun.jna.Union;
import com.sun.jna.NativeLong;
import com.sun.jna.ptr.IntByReference;
問題:我有使用JNA測試代碼,但我需要知道如何使用純Java翻譯這種結構?
public static class SYSTEM_INFO extends Structure {
public static class ByReference extends SYSTEM_INFO
implements Structure.ByReference { }
public static class UNION extends Union {
public static class ByReference extends UNION
implements Structure.ByReference { }
public static class IntStruct extends Structure {
public static class ByValue extends IntStruct
implements Structure.ByValue {}
public short wProcessorArchitecture;
public short wReserved;
}
public int dwOemId;
public IntStruct s;
}
int dwPageSize;
Pointer lpMinimumApplicationAddress;
Pointer lpMaximumApplicationAddress;
NativeLong dwActiveProcessorMask;
int dwNumberOfProcessors;
int dwProcessorType;
int dwAllocationGranularity;
short wProcessorLevel;
short wProcessorRevision;
}
typedef struct _OSVERSIONINFOEX {
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
TCHAR szCSDVersion[128];
WORD wServicePackMajor;
WORD wServicePackMinor;
WORD wSuiteMask;
BYTE wProductType;
BYTE wReserved;
} OSVERSIONINFOEX, *POSVERSIONINFOEX, *LPOSVERSIONINFOEX;
也許這最容易的部分:
public interface Advapi32 extends Library {
Advapi32 INSTANCE = (Advapi32)Native.loadLibrary("advapi32", Advapi32.class);
boolean GetUserNameA(byte[] name, IntByReference intRef);
}
PD我需要一個真正的教程如何使用JNI調用DLL功能(不你好世界),使用指針和數據結構等,等等...
對不起,如果我輸了... 謝謝!
您可能想解釋_「我想擺脫對外部jar Java文件的依賴」,因爲手寫編碼JNI可能不是您唯一的選擇。 – technomage
也許,你有理由,我想深入瞭解JNI,(我不知道JNI) –