All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jgcomptech.tools.NativeMethods Maven / Gradle / Ivy

package com.jgcomptech.tools;

import com.sun.jna.Native;
import com.sun.jna.WString;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.W32APIOptions;

/** Contains methods that allow access to Windows C++ dll files. */
public final class NativeMethods {
    /**
     * Generates a new instance of the VersionInfo object.
     * @param osVersionInfo Empty VersionInfo object to fill
     * @return True if an error occurs
     */
    public static boolean getVersionInfoFailed(final WinNT.OSVERSIONINFOEX osVersionInfo) {
        return !Kernel32.INSTANCE.GetVersionEx(osVersionInfo);
    }

    /**
     * Checks if a system metrics value is true.
     * @param nIndex Value to check for
     * @return False if value is false
     */
    public static boolean getSystemMetrics(final int nIndex) { return Kernel32.INSTANCE.GetSystemMetrics(nIndex); }

    /**
     * Generates a new instance of the ProductInfo object.
     * @param major version
     * @param minor version
     * @return Product Info as an int
     */
    public static int getProductInfo(final int major, final int minor) {
        final IntByReference strProductType = new IntByReference();
        Kernel32.INSTANCE.GetProductInfo(major, minor, 0, 0, strProductType);
        return strProductType.getValue();
    }

    /** Interface object to hold all the Kernel32 Instances. */
    public interface Kernel32 extends com.sun.jna.platform.win32.Kernel32 {
        Kernel32 INSTANCE = (Kernel32)
                Native.loadLibrary("kernel32", Kernel32.class, W32APIOptions.DEFAULT_OPTIONS);

        boolean GetProductInfo(
                int dwOSMajorVersion,
                int dwOSMinorVersion,
                int dwSpMajorVersion,
                int dwSpMinorVersion,
                IntByReference pdwReturnedProductType);

        boolean GetSystemMetrics(int nIndex);
    }

    /** Interface object to hold all the Shell32 Instances. */
    public interface Shell32 extends com.sun.jna.platform.win32.Shell32 {
        Shell32 INSTANCE = (Shell32)
                Native.loadLibrary("shell32", Shell32.class, W32APIOptions.DEFAULT_OPTIONS);

        WinDef.HINSTANCE ShellExecuteW(WinDef.HWND hwnd,
                                       String lpOperation,
                                       WString lpFile,
                                       String lpParameters,
                                       String lpDirectory,
                                       int nShowCmd);
    }

    /** Interface object to hold all the Secur32 Instances. */
    public interface Secur32 extends com.sun.jna.platform.win32.Secur32 {
        Secur32 INSTANCE = (Secur32)
                Native.loadLibrary("secur32", Secur32.class, W32APIOptions.DEFAULT_OPTIONS);
    }

    /** Prevents instantiation of this utility class. */
    private NativeMethods() { }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy