1
我想從Windows安裝中獲取一些信息。 我能夠用C#下面的代碼很容易地做到這一點,但我正在尋找一個Java實現。如何在Java中使用kernel32.dll
我需要訪問下列變量和方法:
internal struct OSVERSIONINFOEX
{
public Int32 dwOSVersionInfoSize;
public Int32 dwMajorVersion;
public Int32 dwMinorVersion;
public Int32 dwBuildNumber;
public Int32 dwPlatFormId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public String szCSDVersion;
public short wServicePackMajor;
public short wServicePackMinor;
public short wSuiteMask;
public byte wProductType;
public byte wReserved;
}
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern Boolean GetVersionEx(ref OSVERSIONINFOEX osVersionInfo);
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern Boolean GetProductInfo(
[In] Int32 dwOSMajorVersion,
[In] Int32 dwOSMinorVersion,
[In] Int32 dwSpMajorVersion,
[In] Int32 dwSpMinorVersion,
[Out] out Int32 pdwReturnedProductType);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern Boolean GetSystemMetrics([In] Int32 nIndex);
您需要的[JNI]一個(http://docs.oracle.com/javase/8/docs/technotes/guides/jni /)*或* [JNA](https://github.com/java-native-access/jna)。 –
謝謝,我明白了。我很快會回答我自己的問題。 –