Java 类com.sun.jna.win32.W32APIOptions 实例源码

项目:ui-automation    文件:Utils.java   
/**
 * Finds the given process in the process list.
 *
 * @param processEntry The process entry.
 * @param filenamePattern pattern matching the filename of the process.
 * @return The found process entry.
 */
public static boolean findProcessEntry
                (final Tlhelp32.PROCESSENTRY32.ByReference processEntry,
                 final Pattern filenamePattern) {
    Kernel32 kernel32 = Native.loadLibrary(Kernel32.class, W32APIOptions.UNICODE_OPTIONS);

    WinNT.HANDLE snapshot = kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS, new WinDef.DWORD(0));

    boolean found = false;

    try {
        while (kernel32.Process32Next(snapshot, processEntry)) {
            String fname = Native.toString(processEntry.szExeFile);

            if (fname != null && filenamePattern.matcher(fname).matches()) {
                found = true;
                break;
            }
        }
    } finally {
        kernel32.CloseHandle(snapshot);
    }

    return found;
}
项目:me3modmanager    文件:ModManager.java   
/**
 * Checks if MassEffect3.exe is currently running. Uses native code.
 * 
 * @return
 */
public static boolean isMassEffect3Running() {
    try {
        Kernel32 kernel32 = (Kernel32) Native.loadLibrary(Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
        Tlhelp32.PROCESSENTRY32.ByReference processEntry = new Tlhelp32.PROCESSENTRY32.ByReference();
        boolean result = false;
        WinNT.HANDLE snapshot = kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS, new WinDef.DWORD(0));
        try {
            while (kernel32.Process32Next(snapshot, processEntry)) {
                if ("MassEffect3.exe".toUpperCase().equals(Native.toString(processEntry.szExeFile).toUpperCase())) {
                    result = true;
                    break;
                }
            }
        } finally {
            kernel32.CloseHandle(snapshot);
        }
        ModManager.debugLogger.writeMessage("Mass Effect 3 is " + (result ? "" : "not ") + "currently running.");
        return result;
    } catch (Throwable t) {
        ModManager.debugLogger.writeErrorWithException("Critical native access exception: ", t);
        ModManager.debugLogger.writeError("Mod Manager will report that the game is not running to continue normal operations.");
        return false;
    }
}
项目:Spark-Reader    文件:KernelController.java   
/**
 * Internal function. Ensures kernel libraries are loaded if possible.
 */
private static void attemptLoad()
{
    if(attemptedLoad)return;
    try
    {
        kernel32 = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
        user32 = (User32) Native.loadLibrary("user32", User32.class, W32APIOptions.UNICODE_OPTIONS);
    }catch(UnsatisfiedLinkError ignored)
    {
        System.out.println("Native libraries not available");
    }
    attemptedLoad = true;
}
项目:massif    文件:MatlabRunningManager.java   
/**
 * Returns a map containing the current matlab running processes. The key is the process file path, and the value is
 * the matlab version
 * 
 * @return
 * @throws MatlabRegistryException
 */
public static List<MatlabProcessInformation> getRunningMatlabs() throws MatlabRegistryException {
    Kernel32 kernel32 = (Kernel32) Native.loadLibrary(Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
    Map<String, Integer> processes = findProcessPIDs(kernel32);
    AvailableVersions versions = findAvailableMatlabVersions(kernel32);
    List<MatlabProcessInformation> runningMatlabs = findRunningMatlabsFromPIDs(versions, processes);
    return runningMatlabs;
}