diff --git a/CHANGES.md b/CHANGES.md
index fbab68af35..7c95da6176 100755
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,6 +1,10 @@
Next Release (3.5.2)
====================
+Bug Fixes
+---------
+* [#183](https://github.com/twall/jna/pull/183): Fix LMAccess.GROUP_INFO_3.getFieldOrder() to return correct fields names. - [@bhamail](https://github.com/bhamail).
+
Features
--------
* [#163](https://github.com/twall/jna/pull/163): The Java `GUID` structure can be used directly as alternative to `Ole32Util.getGUIDFromString()` - [@wolftobias](https://github.com/wolftobias).
@@ -10,6 +14,7 @@ Features
* [#178](https://github.com/twall/jna/pull/178): Added Win32 `USER_INFO_10` structure from `LMAccess.h` - [@davidmc24](https://github.com/davidmc24).
* [#174](https://github.com/twall/jna/pull/174): Recompile linux-amd64 natives to remove glibc-2.11 dependencies, now requires only 2.2.5 or better - [@twall](https://github.com/twall).
* [#180](https://github.com/twall/jna/pull/180): Fix: added missing fields in `XEvents.getFieldOrder()` - [@xwizard](https://github.com/xwizard).
+* [#183](https://github.com/twall/jna/pull/183): Added StructureFieldOrderInspector unit test utility to scan for Structure field issues. See: com.sun.jna.platform.StructureFieldOrderTest.testMethodGetFieldOrder() - [@bhamail](https://github.com/bhamail).
Release 3.5.1
====================
diff --git a/build.xml b/build.xml
index c858b9ad8e..2b49a37680 100644
--- a/build.xml
+++ b/build.xml
@@ -243,6 +243,7 @@
+
diff --git a/contrib/platform/nbproject/project.properties b/contrib/platform/nbproject/project.properties
index b9b4e9036a..c0b5e09573 100644
--- a/contrib/platform/nbproject/project.properties
+++ b/contrib/platform/nbproject/project.properties
@@ -1,59 +1,70 @@
-application.args=
-build.classes.dir=${build.dir}/classes
-build.classes.excludes=**/*.java
-# This directory is removed when the project is cleaned:
-build.dir=build
-build.generated.dir=${build.dir}/generated
-# Only compile against the classpath explicitly listed here:
-build.sysclasspath=ignore
-build.test.classes.dir=${build.dir}/test/classes
-build.test.results.dir=${build.dir}/test/results
-debug.classpath=\
- ${run.classpath}
-debug.test.classpath=\
- ${run.test.classpath}
-# This directory is removed when the project is cleaned:
-dist.dir=dist
-dist.jar=${dist.dir}/platform.jar
-dist.javadoc.dir=${dist.dir}/javadoc
-file.reference.jna.jar=../../build/jna.jar
-libs.junit.classpath=../../lib/junit.jar
-jar.compress=false
-javac.classpath=\
- ${file.reference.jna.jar};
-# Space-separated list of extra javac options
-javac.compilerargs=
-javac.deprecation=false
-javac.source=1.5
-javac.target=1.5
-javac.test.classpath=\
- ${javac.classpath}:\
- ${build.classes.dir}:\
- ${libs.junit.classpath}
-javadoc.additionalparam=
-javadoc.author=false
-javadoc.encoding=
-javadoc.noindex=false
-javadoc.nonavbar=false
-javadoc.notree=false
-javadoc.private=false
-javadoc.splitindex=true
-javadoc.use=true
-javadoc.version=false
-javadoc.windowtitle=
-main.class=
-manifest.file=manifest.mf
-meta.inf.dir=${src.dir}/META-INF
-platform.active=default_platform
-run.classpath=\
- ${javac.classpath}:\
- ${build.classes.dir}
-# Space-separated list of JVM arguments used when running the project
-# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
-# or test-sys-prop.name=value to set system properties for unit tests):
-run.jvmargs=
-run.test.classpath=\
- ${javac.test.classpath}:\
- ${build.test.classes.dir}
-src.dir=src
-test.src.dir=test
+application.args=
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java
+# This directory is removed when the project is cleaned:
+build.dir=build
+build.generated.dir=${build.dir}/generated
+# Only compile against the classpath explicitly listed here:
+build.sysclasspath=ignore
+build.test.classes.dir=${build.dir}/test/classes
+build.test.results.dir=${build.dir}/test/results
+debug.classpath=\
+ ${run.classpath}
+debug.test.classpath=\
+ ${run.test.classpath}
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.jar=${dist.dir}/platform.jar
+dist.javadoc.dir=${dist.dir}/javadoc
+file.reference.jna.jar=../../build/jna.jar
+file.reference.jna-d64.jar=../../build-d64/jna.jar
+file.reference.jna-test.jar=../../build/jna-test.jar
+file.reference.jna-test-d64.jar=../../build-d64/jna-test.jar
+libs.junit.classpath=../../lib/junit.jar
+jar.compress=false
+javac.classpath=\
+ ${file.reference.jna.jar}:\
+ ${file.reference.jna-d64.jar}
+# Space-separated list of extra javac options
+javac.compilerargs=
+javac.deprecation=false
+javac.source=1.5
+javac.target=1.5
+javac.test.classpath=\
+ ${javac.classpath}:\
+ ${file.reference.jna-test.jar}:\
+ ${file.reference.jna-test-d64.jar}:\
+ ${build.classes.dir}:\
+ ${libs.junit.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+main.class=
+manifest.file=manifest.mf
+meta.inf.dir=${src.dir}/META-INF
+platform.active=default_platform
+run.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+# Space-separated list of JVM arguments used when running the project
+# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
+# or test-sys-prop.name=value to set system properties for unit tests):
+run.jvmargs=
+run.test.classpath=\
+ ${javac.test.classpath}:\
+ ../../lib/test/reflections-0.9.8.jar:\
+ ../../lib/test/guava-11.0.2.jar:\
+ ../../lib/test/javassist-3.12.1.GA.jar:\
+ ../../lib/test/slf4j-api-1.6.1.jar:\
+ ../../lib/test/dom4j-1.6.1.jar:\
+ ${build.test.classes.dir}
+src.dir=src
+test.src.dir=test
diff --git a/contrib/platform/src/com/sun/jna/platform/unix/X11.java b/contrib/platform/src/com/sun/jna/platform/unix/X11.java
index eec965c3be..ce9edd8566 100644
--- a/contrib/platform/src/com/sun/jna/platform/unix/X11.java
+++ b/contrib/platform/src/com/sun/jna/platform/unix/X11.java
@@ -1610,7 +1610,7 @@ class XUnmapEvent extends Structure {
public Window window;
public int from_configure;
protected List getFieldOrder() {
- return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "event", "window", "from_configure" });
+ return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "window", "from_configure" });
}
}
@@ -1623,7 +1623,7 @@ class XMapEvent extends Structure {
public Window window;
public int override_redirect; // boolean, is override set...
protected List getFieldOrder() {
- return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "event", "window", "override_redirect" });
+ return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "window", "override_redirect" });
}
}
@@ -1635,7 +1635,7 @@ class XMapRequestEvent extends Structure {
public Window parent;
public Window window;
protected List getFieldOrder() {
- return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "parent", "window" });
+ return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "window" });
}
}
@@ -1650,7 +1650,7 @@ class XReparentEvent extends Structure {
public int x, y;
public int override_redirect;
protected List getFieldOrder() {
- return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "event", "window", "parent", "x", "y", "override_redirect" });
+ return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "window", "x", "y", "override_redirect" });
}
}
@@ -1667,7 +1667,7 @@ class XConfigureEvent extends Structure {
public Window above;
public int override_redirect;
protected List getFieldOrder() {
- return Arrays.asList(new String[] { "type", "serial", "send_event", "display","event", "window", "x", "y", "width", "height", "border_width", "above", "override_redirect" });
+ return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "window", "x", "y", "width", "height", "border_width", "above", "override_redirect" });
}
}
@@ -1680,7 +1680,7 @@ class XGravityEvent extends Structure {
public Window window;
public int x, y;
protected List getFieldOrder() {
- return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "event", "window", "x", "y" });
+ return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "window", "x", "y" });
}
}
@@ -1710,7 +1710,7 @@ class XConfigureRequestEvent extends Structure {
public int detail; // Above, Below, TopIf, BottomIf, Opposite
public NativeLong value_mask;
protected List getFieldOrder() {
- return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "parent", "window", "x", "y", "width", "height", "border_width", "above", "detail", "value_mask" });
+ return Arrays.asList(new String[] { "type", "serial", "send_event", "display", "window", "x", "y", "width", "height", "above", "detail", "value_mask" });
}
}
diff --git a/contrib/platform/src/com/sun/jna/platform/win32/LMAccess.java b/contrib/platform/src/com/sun/jna/platform/win32/LMAccess.java
index 9a77e5a921..ccd7259a31 100644
--- a/contrib/platform/src/com/sun/jna/platform/win32/LMAccess.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/LMAccess.java
@@ -154,50 +154,6 @@ protected List getFieldOrder() {
return Arrays.asList(new String[] { "usri1_name", "usri1_password", "usri1_password_age", "usri1_priv", "usri1_home_dir", "usri1_comment", "usri1_flags", "usri1_script_path" });
}
}
-
- /**
- * The USER_INFO_10 structure contains information about a user account,
- * including the account name, comments associated with the account, and
- * the user's full name.
- */
- public static class USER_INFO_10 extends Structure {
- public USER_INFO_10() {
- super();
- }
-
- public USER_INFO_10(Pointer memory) {
- super(memory);
- read();
- }
-
- /**
- * Pointer to a Unicode string that specifies the name of the user
- * account. Calls to the NetUserSetInfo function ignore this member.
- */
- public WString usri10_name;
- /**
- * Pointer to a Unicode string that contains a comment associated with
- * the user account. The string can be a null string, or can have any
- * number of characters before the terminating null character.
- */
- public WString usri10_comment;
- /**
- * Pointer to a Unicode string that contains a user comment. This
- * string can be a null string, or it can have any number of characters
- * before the terminating null character.
- */
- public WString usri10_usr_comment;
- /**
- * Pointer to a Unicode string that contains the full name of the user.
- * This string can be a null string, or it can have any number of
- * characters before the terminating null character.
- */
- public WString usri10_full_name;
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "usri10_name", "usri10_comment", "usri10_usr_comment", "usri10_full_name" });
- }
- }
/**
* The USER_INFO_23 structure contains information about a user account,
@@ -455,7 +411,7 @@ public GROUP_INFO_3(Pointer memory) {
public int grpi3_attributes;
protected List getFieldOrder() {
- return Arrays.asList(new String[] { "grpi3_name", "grpi3_comment", "grpi3_group_id", "grpi3_attributes" });
+ return Arrays.asList(new String[] { "grpi3_name", "grpi3_comment", "grpi3_group_sid", "grpi3_attributes" });
}
}
diff --git a/contrib/platform/src/com/sun/jna/platform/win32/User32.java b/contrib/platform/src/com/sun/jna/platform/win32/User32.java
index f7feaf736e..38f30c0af1 100644
--- a/contrib/platform/src/com/sun/jna/platform/win32/User32.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/User32.java
@@ -1,1687 +1,1687 @@
-/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package com.sun.jna.platform.win32;
-
-import com.sun.jna.Native;
-import com.sun.jna.Pointer;
-import com.sun.jna.Structure;
-import com.sun.jna.WString;
-import com.sun.jna.platform.win32.BaseTSD.LONG_PTR;
-import com.sun.jna.platform.win32.WinNT.HANDLE;
-import com.sun.jna.ptr.ByteByReference;
-import com.sun.jna.ptr.IntByReference;
-import com.sun.jna.win32.StdCallLibrary;
-import com.sun.jna.win32.W32APIOptions;
-
-// TODO: Auto-generated Javadoc
-/**
- * Provides access to the w32 user32 library. Incomplete implementation to
- * support demos.
- *
- * @author Todd Fast, todd.fast@sun.com
- * @author twalljava@dev.java.net
- * @author Tobias Wolf, wolf.tobias@gmx.net
- */
-public interface User32 extends StdCallLibrary, WinUser {
-
- /** The instance. */
- User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class,
- W32APIOptions.DEFAULT_OPTIONS);
-
- /** The cs globalclass. */
- int CS_GLOBALCLASS = 0x4000;
-
- /** The ws ex topmost. */
- int WS_EX_TOPMOST = 0x00000008;
-
- /** The ws overlapped. */
- int WS_OVERLAPPED = 0x00000000;
-
- /** The hRecipient parameter is a window handle. */
- int DEVICE_NOTIFY_WINDOW_HANDLE = 0x00000000;
-
- /** The hRecipient parameter is a service status handle. */
- int DEVICE_NOTIFY_SERVICE_HANDLE = 0x00000001;
-
- /** The device notify all interface classes. */
- int DEVICE_NOTIFY_ALL_INTERFACE_CLASSES = 0x00000004;
-
- /**
- * This function retrieves a handle to a display device context (DC) for the
- * client area of the specified window. The display device context can be
- * used in subsequent graphics display interface (GDI) functions to draw in
- * the client area of the window.
- *
- * @param hWnd
- * Handle to the window whose device context is to be retrieved.
- * If this value is NULL, GetDC retrieves the device context for
- * the entire screen.
- * @return The handle the device context for the specified window's client
- * area indicates success. NULL indicates failure. To get extended
- * error information, call GetLastError.
- */
- HDC GetDC(HWND hWnd);
-
- /**
- * This function releases a device context (DC), freeing it for use by other
- * applications. The effect of ReleaseDC depends on the type of device
- * context.
- *
- * @param hWnd
- * Handle to the window whose device context is to be released.
- * @param hDC
- * Handle to the device context to be released.
- * @return The return value specifies whether the device context is
- * released. 1 indicates that the device context is released. Zero
- * indicates that the device context is not released.
- */
- int ReleaseDC(HWND hWnd, HDC hDC);
-
- /**
- * This function retrieves the handle to the top-level window whose class
- * name and window name match the specified strings. This function does not
- * search child windows.
- *
- * @param lpClassName
- * Long pointer to a null-terminated string that specifies the
- * class name or is an atom that identifies the class-name
- * string. If this parameter is an atom, it must be a global atom
- * created by a previous call to the GlobalAddAtom function. The
- * atom, a 16-bit value, must be placed in the low-order word of
- * lpClassName; the high-order word must be zero.
- * @param lpWindowName
- * Long pointer to a null-terminated string that specifies the
- * window name (the window's title). If this parameter is NULL,
- * all window names match.
- * @return A handle to the window that has the specified class name and
- * window name indicates success. NULL indicates failure. To get
- * extended error information, call GetLastError.
- */
- HWND FindWindow(String lpClassName, String lpWindowName);
-
- /**
- * This function retrieves the name of the class to which the specified
- * window belongs.
- *
- * @param hWnd
- * Handle to the window and, indirectly, the class to which the
- * window belongs.
- * @param lpClassName
- * Long pointer to the buffer that is to receive the class name
- * string.
- * @param nMaxCount
- * Specifies the length, in characters, of the buffer pointed to
- * by the lpClassName parameter. The class name string is
- * truncated if it is longer than the buffer.
- * @return The number of characters copied to the specified buffer indicates
- * success. Zero indicates failure. To get extended error
- * information, call GetLastError.
- */
- int GetClassName(HWND hWnd, char[] lpClassName, int nMaxCount);
-
- /**
- * Retrieves information about the active window or a specified graphical
- * user interface (GUI) thread.
- *
- * @param idThread
- * Identifies the thread for which information is to be
- * retrieved. To retrieve this value, use the
- * GetWindowThreadProcessId function. If this parameter is NULL,
- * the function returns information for the foreground thread.
- * @param lpgui
- * Pointer to a GUITHREADINFO structure that receives information
- * describing the thread. Note that you must set
- * GUITHREADINFO.cbSize to sizeof(GUITHREADINFO) before calling
- * this function.
- * @return If the function succeeds, the return value is nonzero. If the
- * function fails, the return value is zero. To get extended error
- * information, call GetLastError.
- */
- boolean GetGUIThreadInfo(int idThread, GUITHREADINFO lpgui);
-
- /**
- * The GetWindowInfo function retrieves information about the specified
- * window.
- *
- * @param hWnd
- * Handle to the window whose information is to be retrieved.
- * @param pwi
- * Pointer to a WINDOWINFO structure to receive the information.
- * Note that you must set WINDOWINFO.cbSize to sizeof(WINDOWINFO)
- * before calling this function.
- * @return If the function succeeds, the return value is nonzero. If the
- * function fails, the return value is zero.
- */
- boolean GetWindowInfo(HWND hWnd, WINDOWINFO pwi);
-
- /**
- * This function retrieves the dimensions of the bounding rectangle of the
- * specified window. The dimensions are given in screen coordinates that are
- * relative to the upper-left corner of the screen.
- *
- * @param hWnd
- * Handle to the window.
- * @param rect
- * Long pointer to a RECT structure that receives the screen
- * coordinates of the upper-left and lower-right corners of the
- * window.
- * @return Nonzero indicates success. Zero indicates failure. To get
- * extended error information, call GetLastError.
- */
- boolean GetWindowRect(HWND hWnd, RECT rect);
-
- /**
- * This function copies the text of the specified window's title bar - if it
- * has one - into a buffer. If the specified window is a control, the text
- * of the control is copied.
- *
- * @param hWnd
- * Handle to the window or control containing the text.
- * @param lpString
- * Long pointer to the buffer that will receive the text.
- * @param nMaxCount
- * Specifies the maximum number of characters to copy to the
- * buffer, including the NULL character. If the text exceeds this
- * limit, it is truncated.
- * @return The length, in characters, of the copied string, not including
- * the terminating null character, indicates success. Zero indicates
- * that the window has no title bar or text, if the title bar is
- * empty, or if the window or control handle is invalid. To get
- * extended error information, call GetLastError. This function
- * cannot retrieve the text of an edit control in another
- * application.
- */
- int GetWindowText(HWND hWnd, char[] lpString, int nMaxCount);
-
- /**
- * This function retrieves the length, in characters, of the specified
- * window's title bar text - if the window has a title bar. If the specified
- * window is a control, the function retrieves the length of the text within
- * the control.
- *
- * @param hWnd
- * Handle to the window or control.
- * @return The length, in characters, of the text indicates success. Under
- * certain conditions, this value may actually be greater than the
- * length of the text. Zero indicates that the window has no text.
- * To get extended error information, call GetLastError.
- */
- int GetWindowTextLength(HWND hWnd);
-
- /**
- * The GetWindowModuleFileName function retrieves the full path and file
- * name of the module associated with the specified window handle.
- *
- * @param hWnd
- * Handle to the window whose module file name will be retrieved.
- * @param lpszFileName
- * Pointer to a buffer that receives the path and file name.
- * @param cchFileNameMax
- * Specifies the maximum number of TCHARs that can be copied into
- * the lpszFileName buffer.
- * @return The return value is the total number of TCHARs copied into the
- * buffer.
- */
- int GetWindowModuleFileName(HWND hWnd, char[] lpszFileName,
- int cchFileNameMax);
-
- /**
- * This function retrieves the identifier of the thread that created the
- * specified window and, optionally, the identifier of the process that
- * created the window.
- *
- * @param hWnd
- * Handle to the window.
- * @param lpdwProcessId
- * Pointer to a 32-bit value that receives the process
- * identifier. If this parameter is not NULL,
- * GetWindowThreadProcessId copies the identifier of the process
- * to the 32-bit value; otherwise, it does not.
- * @return The return value is the identifier of the thread that created the
- * window.
- */
- int GetWindowThreadProcessId(HWND hWnd, IntByReference lpdwProcessId);
-
- /**
- * This function enumerates all top-level windows on the screen by passing
- * the handle to each window, in turn, to an application-defined callback
- * function. EnumWindows continues until the last top-level window is
- * enumerated or the callback function returns FALSE.
- *
- * @param lpEnumFunc
- * Long pointer to an application-defined callback function.
- * @param data
- * Specifies an application-defined value to be passed to the
- * callback function.
- * @return Nonzero indicates success. Zero indicates failure. To get
- * extended error information, call GetLastError.
- */
- boolean EnumWindows(WNDENUMPROC lpEnumFunc, Pointer data);
-
- /**
- * The EnumChildWindows function enumerates the child windows that belong to
- * the specified parent window by passing the handle to each child window,
- * in turn, to an application-defined callback function. EnumChildWindows
- * continues until the last child window is enumerated or the callback
- * function returns FALSE.
- *
- * @param hWnd
- * Handle to the parent window whose child windows are to be
- * enumerated. If this parameter is NULL, this function is
- * equivalent to EnumWindows.
- * @param lpEnumFunc
- * Pointer to an application-defined callback function.
- * @param data
- * Specifies an application-defined value to be passed to the
- * callback function.
- * @return If the function succeeds, the return value is nonzero. If the
- * function fails, the return value is zero. To get extended error
- * information, call GetLastError. If EnumChildProc returns zero,
- * the return value is also zero. In this case, the callback
- * function should call SetLastError to obtain a meaningful error
- * code to be returned to the caller of EnumChildWindows.
- */
- boolean EnumChildWindows(HWND hWnd, WNDENUMPROC lpEnumFunc, Pointer data);
-
- /**
- * The EnumThreadWindows function enumerates all nonchild windows associated
- * with a thread by passing the handle to each window, in turn, to an
- * application-defined callback function. EnumThreadWindows continues until
- * the last window is enumerated or the callback function returns FALSE. To
- * enumerate child windows of a particular window, use the EnumChildWindows
- * function.
- *
- * @param dwThreadId
- * Identifies the thread whose windows are to be enumerated.
- * @param lpEnumFunc
- * Pointer to an application-defined callback function.
- * @param data
- * Specifies an application-defined value to be passed to the
- * callback function.
- * @return If the callback function returns TRUE for all windows in the
- * thread specified by dwThreadId, the return value is TRUE. If the
- * callback function returns FALSE on any enumerated window, or if
- * there are no windows found in the thread specified by dwThreadId,
- * the return value is FALSE.
- */
- boolean EnumThreadWindows(int dwThreadId, WNDENUMPROC lpEnumFunc,
- Pointer data);
-
- /**
- * The FlashWindowEx function flashes the specified window. It does not
- * change the active state of the window.
- *
- * @param pfwi
- * Pointer to the FLASHWINFO structure.
- * @return The return value specifies the window's state before the call to
- * the FlashWindowEx function. If the window caption was drawn as
- * active before the call, the return value is nonzero. Otherwise,
- * the return value is zero.
- */
- boolean FlashWindowEx(FLASHWINFO pfwi);
-
- /**
- * This function loads the specified icon resource from the executable
- * (.exe) file associated with an application instance.
- *
- * @param hInstance
- * Handle to an instance of the module whose executable file
- * contains the icon to be loaded. This parameter must be NULL
- * when a standard icon is being loaded.
- * @param iconName
- * Long pointer to a null-terminated string that contains the
- * name of the icon resource to be loaded. Alternatively, this
- * parameter can contain the resource identifier in the low-order
- * word and zero in the high-order word. Use the MAKEINTRESOURCE
- * macro to create this value.
- * @return A handle to the newly loaded icon indicates success. NULL
- * indicates failure. To get extended error information, call
- * GetLastError.
- */
- HICON LoadIcon(HINSTANCE hInstance, String iconName);
-
- /**
- * This function loads an icon, cursor, or bitmap.
- *
- * @param hinst
- * Handle to an instance of the module that contains the image to
- * be loaded.
- * @param name
- * Pointer to a null-terminated string that contains the name of
- * the image resource in the hinst module that identifies the
- * image to load.
- * @param type
- * Specifies the type of image to be loaded.
- * @param xDesired
- * Specifies the width, in pixels, of the icon or cursor. If this
- * parameter is zero, the function uses the SM_CXICON or
- * SM_CXCURSOR system metric value to set the width. If uType is
- * IMAGE_BITMAP, this parameter must be zero.
- * @param yDesired
- * Specifies the height, in pixels, of the icon or cursor. If
- * this parameter is zero, the function uses the SM_CYICON or
- * SM_CYCURSOR system metric value to set the height. If uType is
- * IMAGE_BITMAP, this parameter must be zero.
- * @param load
- * Set to zero.
- * @return The handle of the newly loaded image indicates success. NULL
- * indicates failure. To get extended error information, call
- * GetLastError.
- */
- HANDLE LoadImage(HINSTANCE hinst, String name, int type, int xDesired,
- int yDesired, int load);
-
- /**
- * This function destroys an icon and frees any memory the icon occupied.
- *
- * @param hicon
- * Handle to the icon to be destroyed. The icon must not be in
- * use.
- * @return Nonzero indicates success. Zero indicates failure. To get
- * extended error information, call GetLastError.
- */
- boolean DestroyIcon(HICON hicon);
-
- /**
- * This function retrieves information about the specified window.
- * GetWindowLong also retrieves the 32-bit (long) value at the specified
- * offset into the extra window memory of a window.
- *
- * @param hWnd
- * Handle to the window and, indirectly, the class to which the
- * window belongs.
- * @param nIndex
- * Specifies the zero-based offset to the value to be retrieved.
- * @return The requested 32-bit value indicates success. Zero indicates
- * failure. To get extended error information, call GetLastError.
- */
- int GetWindowLong(HWND hWnd, int nIndex);
-
- /**
- * This function changes an attribute of the specified window. SetWindowLong
- * also sets a 32-bit (LONG) value at the specified offset into the extra
- * window memory of a window.
- *
- * @param hWnd
- * Handle to the window and, indirectly, the class to which the
- * window belongs.
- * @param nIndex
- * Specifies the zero-based offset to the value to be set.
- * @param dwNewLong
- * Specifies the replacement value.
- * @return The previous value of the specified 32-bit integer indicates
- * success. Zero indicates failure. To get extended error
- * information, call GetLastError.
- */
- int SetWindowLong(HWND hWnd, int nIndex, int dwNewLong);
-
- /**
- * This function changes an attribute of the specified window. SetWindowLong
- * also sets a 32-bit (LONG) value at the specified offset into the extra
- * window memory of a window. Do not use this version on Windows-64.
- *
- * @param hWnd
- * Handle to the window and, indirectly, the class to which the
- * window belongs.
- * @param nIndex
- * Specifies the zero-based offset to the value to be set.
- * @param dwNewLong
- * Specifies the replacement value.
- * @return The previous value of the specified 32-bit integer indicates
- * success. Zero indicates failure. To get extended error
- * information, call GetLastError.
- */
- Pointer SetWindowLong(HWND hWnd, int nIndex, Pointer dwNewLong);
-
- /**
- * The GetWindowLongPtr function retrieves information about the specified
- * window. The function also retrieves the value at a specified offset into
- * the extra window memory.
- *
- * @param hWnd
- * Handle to the window and, indirectly, the class to which the
- * window belongs.
- * @param nIndex
- * Specifies the zero-based offset to the value to be retrieved.
- * @return If the function succeeds, the return value is the requested
- * value. If the function fails, the return value is zero. To get
- * extended error information, call GetLastError. If SetWindowLong
- * or SetWindowLongPtr has not been called previously,
- * GetWindowLongPtr returns zero for values in the extra window or
- * class memory.
- */
- LONG_PTR GetWindowLongPtr(HWND hWnd, int nIndex);
-
- /**
- * The SetWindowLongPtr function changes an attribute of the specified
- * window. The function also sets a value at the specified offset in the
- * extra window memory.
- *
- * @param hWnd
- * Handle to the window and, indirectly, the class to which the
- * window belongs.
- * @param nIndex
- * Specifies the zero-based offset to the value to be set.
- * @param dwNewLongPtr
- * Specifies the replacement value.
- * @return If the function succeeds, the return value is the previous value
- * of the specified offset. If the function fails, the return value
- * is zero. To get extended error information, call GetLastError. If
- * the previous value is zero and the function succeeds, the return
- * value is zero, but the function does not clear the last error
- * information. To determine success or failure, clear the last
- * error information by calling SetLastError(0), then call
- * SetWindowLongPtr. Function failure will be indicated by a return
- * value of zero and a GetLastError result that is nonzero.
- */
- LONG_PTR SetWindowLongPtr(HWND hWnd, int nIndex, LONG_PTR dwNewLongPtr);
-
- /**
- * The SetWindowLongPtr function changes an attribute of the specified
- * window. The function also sets a value at the specified offset in the
- * extra window memory.
- *
- * @param hWnd
- * Handle to the window and, indirectly, the class to which the
- * window belongs.
- * @param nIndex
- * Specifies the zero-based offset to the value to be set.
- * @param dwNewLongPtr
- * Specifies the replacement value.
- * @return If the function succeeds, the return value is the previous value
- * of the specified offset. If the function fails, the return value
- * is zero. To get extended error information, call GetLastError. If
- * the previous value is zero and the function succeeds, the return
- * value is zero, but the function does not clear the last error
- * information. To determine success or failure, clear the last
- * error information by calling SetLastError(0), then call
- * SetWindowLongPtr. Function failure will be indicated by a return
- * value of zero and a GetLastError result that is nonzero.
- */
- Pointer SetWindowLongPtr(HWND hWnd, int nIndex, Pointer dwNewLongPtr);
-
- /**
- * The SetLayeredWindowAttributes function sets the opacity and transparency
- * color key of a layered window.
- *
- * @param hwnd
- * Handle to the layered window.
- * @param crKey
- * COLORREF structure that specifies the transparency color key
- * to be used when composing the layered window.
- * @param bAlpha
- * Alpha value used to describe the opacity of the layered
- * window.
- * @param dwFlags
- * Specifies an action to take.
- * @return If the function succeeds, the return value is nonzero. If the
- * function fails, the return value is zero. To get extended error
- * information, call GetLastError.
- */
- boolean SetLayeredWindowAttributes(HWND hwnd, int crKey, byte bAlpha,
- int dwFlags);
-
- /**
- * The GetLayeredWindowAttributes function retrieves the opacity and
- * transparency color key of a layered window.
- *
- * @param hwnd
- * Handle to the layered window. A layered window is created by
- * specifying WS_EX_LAYERED when creating the window with the
- * CreateWindowEx function or by setting WS_EX_LAYERED via
- * SetWindowLong after the window has been created.
- * @param pcrKey
- * Pointer to a COLORREF value that receives the transparency
- * color key to be used when composing the layered window. All
- * pixels painted by the window in this color will be
- * transparent. This can be NULL if the argument is not needed.
- * @param pbAlpha
- * Pointer to a BYTE that receives the Alpha value used to
- * describe the opacity of the layered window. Similar to the
- * SourceConstantAlpha member of the BLENDFUNCTION structure.
- * When the variable referred to by pbAlpha is 0, the window is
- * completely transparent. When the variable referred to by
- * pbAlpha is 255, the window is opaque. This can be NULL if the
- * argument is not needed.
- * @param pdwFlags
- * Pointer to a DWORD that receives a layering flag. This can be
- * NULL if the argument is not needed.
- * @return If the function succeeds, the return value is nonzero. If the
- * function fails, the return value is zero. To get extended error
- * information, call GetLastError.
- */
- boolean GetLayeredWindowAttributes(HWND hwnd, IntByReference pcrKey,
- ByteByReference pbAlpha, IntByReference pdwFlags);
-
- /**
- * The UpdateLayeredWindow function updates the position, size, shape,
- * content, and translucency of a layered window.
- *
- * @param hwnd
- * Handle to a layered window. A layered window is created by
- * specifying WS_EX_LAYERED when creating the window with the
- * CreateWindowEx function.
- * @param hdcDst
- * Handle to a device context (DC) for the screen. This handle is
- * obtained by specifying NULL when calling the function. It is
- * used for palette color matching when the window contents are
- * updated. If hdcDst isNULL, the default palette will be used.
- * If hdcSrc is NULL, hdcDst must be NULL.
- * @param pptDst
- * Pointer to a POINT structure that specifies the new screen
- * position of the layered window. If the current position is not
- * changing, pptDst can be NULL.
- * @param psize
- * Pointer to a SIZE structure that specifies the new size of the
- * layered window. If the size of the window is not changing,
- * psize can be NULL. If hdcSrc is NULL, psize must be NULL.
- * @param hdcSrc
- * Handle to a DC for the surface that defines the layered
- * window. This handle can be obtained by calling the
- * CreateCompatibleDC function. If the shape and visual context
- * of the window are not changing, hdcSrc can be NULL.
- * @param pptSrc
- * Pointer to a POINT structure that specifies the location of
- * the layer in the device context. If hdcSrc is NULL, pptSrc
- * should be NULL.
- * @param crKey
- * Pointer to a COLORREF value that specifies the color key to be
- * used when composing the layered window. To generate a
- * COLORREF, use the RGB macro.
- * @param pblend
- * Pointer to a BLENDFUNCTION structure that specifies the
- * transparency value to be used when composing the layered
- * window.
- * @param dwFlags
- * ULW_* flags.
- * @return If the function succeeds, the return value is nonzero. If the
- * function fails, the return value is zero. To get extended error
- * information, call GetLastError.
- */
- boolean UpdateLayeredWindow(HWND hwnd, HDC hdcDst, POINT pptDst,
- SIZE psize, HDC hdcSrc, POINT pptSrc, int crKey,
- BLENDFUNCTION pblend, int dwFlags);
-
- /**
- * This function sets the window region of a window. The window region
- * determines the area within the window where the system permits drawing.
- * The system does not display any portion of a window that lies outside of
- * the window region.
- *
- * @param hWnd
- * Handle to the window whose window region is to be set.
- * @param hRgn
- * Handle to a region. The function sets the window region of the
- * window to this region. If hRgn is NULL, the function sets the
- * window region to NULL.
- * @param bRedraw
- * Specifies whether the system redraws the window after setting
- * the window region. If bRedraw is TRUE, the system does so;
- * otherwise, it does not. Typically, you set bRedraw to TRUE if
- * the window is visible.
- * @return Nonzero indicates success. Zero indicates failure. To get
- * extended error information, call GetLastError.
- */
- int SetWindowRgn(HWND hWnd, HRGN hRgn, boolean bRedraw);
-
- /**
- * The GetKeyboardState function copies the status of the 256 virtual keys
- * to the specified buffer.
- *
- * @param lpKeyState
- * Pointer to the 256-byte array that receives the status data
- * for each virtual key.
- * @return If the function succeeds, the return value is nonzero. If the
- * function fails, the return value is zero. To get extended error
- * information, call GetLastError.
- */
- boolean GetKeyboardState(byte[] lpKeyState);
-
- /**
- * This function determines whether a key is up or down at the time the
- * function is called, and whether the key was pressed after a previous call
- * to GetAsyncKeyState.
- *
- * @param vKey
- * Specifies one of 256 possible virtual-key codes.
- * @return If the function succeeds, the return value specifies whether the
- * key was pressed since the last call to GetAsyncKeyState, and
- * whether the key is currently up or down. If the most significant
- * bit is set, the key is down.
- */
- short GetAsyncKeyState(int vKey);
-
- /**
- * The SetWindowsHookEx function installs an application-defined hook
- * procedure into a hook chain. You would install a hook procedure to
- * monitor the system for certain types of events. These events are
- * associated either with a specific thread or with all threads in the same
- * desktop as the calling thread.
- *
- * @param idHook
- * Specifies the type of hook procedure to be installed.
- * @param lpfn
- * Pointer to the hook procedure.
- * @param hMod
- * Handle to the DLL containing the hook procedure pointed to by
- * the lpfn parameter.
- * @param dwThreadId
- * Specifies the identifier of the thread with which the hook
- * procedure is to be associated.
- * @return If the function succeeds, the return value is the handle to the
- * hook procedure. If the function fails, the return value is NULL.
- * To get extended error information, call GetLastError.
- */
- HHOOK SetWindowsHookEx(int idHook, HOOKPROC lpfn, HINSTANCE hMod,
- int dwThreadId);
-
- /**
- * The CallNextHookEx function passes the hook information to the next hook
- * procedure in the current hook chain. A hook procedure can call this
- * function either before or after processing the hook information.
- *
- * @param hhk
- * Ignored.
- * @param nCode
- * Specifies the hook code passed to the current hook procedure.
- * The next hook procedure uses this code to determine how to
- * process the hook information.
- * @param wParam
- * Specifies the wParam value passed to the current hook
- * procedure. The meaning of this parameter depends on the type
- * of hook associated with the current hook chain.
- * @param lParam
- * Specifies the lParam value passed to the current hook
- * procedure. The meaning of this parameter depends on the type
- * of hook associated with the current hook chain.
- * @return This value is returned by the next hook procedure in the chain.
- * The current hook procedure must also return this value. The
- * meaning of the return value depends on the hook type.
- */
- LRESULT CallNextHookEx(HHOOK hhk, int nCode, WPARAM wParam, LPARAM lParam);
-
- /**
- * The CallNextHookEx function passes the hook information to the next hook
- * procedure in the current hook chain. A hook procedure can call this
- * function either before or after processing the hook information.
- *
- * @param hhk
- * Ignored.
- * @param nCode
- * Specifies the hook code passed to the current hook procedure.
- * The next hook procedure uses this code to determine how to
- * process the hook information.
- * @param wParam
- * Specifies the wParam value passed to the current hook
- * procedure. The meaning of this parameter depends on the type
- * of hook associated with the current hook chain.
- * @param lParam
- * Specifies the lParam value passed to the current hook
- * procedure. The meaning of this parameter depends on the type
- * of hook associated with the current hook chain.
- * @return This value is returned by the next hook procedure in the chain.
- * The current hook procedure must also return this value. The
- * meaning of the return value depends on the hook type.
- */
- LRESULT CallNextHookEx(HHOOK hhk, int nCode, WPARAM wParam, Pointer lParam);
-
- /**
- * The UnhookWindowsHookEx function removes a hook procedure installed in a
- * hook chain by the SetWindowsHookEx function.
- *
- * @param hhk
- * Handle to the hook to be removed. This parameter is a hook
- * handle obtained by a previous call to SetWindowsHookEx.
- * @return If the function succeeds, the return value is nonzero. If the
- * function fails, the return value is zero. To get extended error
- * information, call GetLastError.
- */
- boolean UnhookWindowsHookEx(HHOOK hhk);
-
- /**
- * This function retrieves a message from the calling thread's message queue
- * and places it in the specified structure.
- *
- * @param lpMsg
- * Pointer to an MSG structure that receives message information
- * from the thread's message queue.
- * @param hWnd
- * Handle to the window whose messages are to be retrieved. One
- * value has a special meaning.
- * @param wMsgFilterMin
- * Specifies the integer value of the lowest message value to be
- * retrieved.
- * @param wMsgFilterMax
- * Specifies the integer value of the highest message value to be
- * retrieved.
- * @return Nonzero indicates that the function retrieves a message other
- * than WM_QUIT. Zero indicates that the function retrieves the
- * WM_QUIT message, or that lpMsg is an invalid pointer. To get
- * extended error information, call GetLastError.
- */
- int GetMessage(MSG lpMsg, HWND hWnd, int wMsgFilterMin, int wMsgFilterMax);
-
- /**
- * This function checks a thread message queue for a message and places the
- * message (if any) in the specified structure.
- *
- * @param lpMsg
- * Pointer to an MSG structure that receives message information.
- * @param hWnd
- * Handle to the window whose messages are to be examined.
- * @param wMsgFilterMin
- * Specifies the value of the first message in the range of
- * messages to be examined.
- * @param wMsgFilterMax
- * Specifies the value of the last message in the range of
- * messages to be examined.
- * @param wRemoveMsg
- * Specifies how messages are handled. This parameter can be one
- * of the following values.
- * @return Nonzero indicates success. Zero indicates failure.
- */
- boolean PeekMessage(MSG lpMsg, HWND hWnd, int wMsgFilterMin,
- int wMsgFilterMax, int wRemoveMsg);
-
- /**
- * This function translates virtual-key messages into character messages.
- * The character messages are posted to the calling thread's message queue,
- * to be read the next time the thread calls the GetMessage or PeekMessage
- * function.
- *
- * @param lpMsg
- * Pointer to an MSG structure that contains message information
- * retrieved from the calling thread's message queue by using the
- * GetMessage or PeekMessage function.
- * @return Nonzero indicates that the message is translated, that is, a
- * character message is posted to the thread's message queue. If the
- * message is WM_KEYDOWN or WM_SYSKEYDOWN, the return value is
- * nonzero, regardless of the translation. Zero indicates that the
- * message is not translated, that is, a character message is not
- * posted to the thread's message queue.
- */
- boolean TranslateMessage(MSG lpMsg);
-
- /**
- * This function dispatches a message to a window procedure. It is typically
- * used to dispatch a message retrieved by the GetMessage function.
- *
- * @param lpMsg
- * Pointer to an MSG structure that contains the message.
- * @return The return value specifies the value returned by the window
- * procedure. Although its meaning depends on the message being
- * dispatched, the return value generally is ignored.
- */
- LRESULT DispatchMessage(MSG lpMsg);
-
- /**
- * This function places a message in the message queue associated with the
- * thread that created the specified window and then returns without waiting
- * for the thread to process the message. Messages in a message queue are
- * retrieved by calls to the GetMessage or PeekMessage function.
- *
- * @param hWnd
- * Handle to the window whose window procedure is to receive the
- * message.
- * @param msg
- * Specifies the message to be posted.
- * @param wParam
- * Specifies additional message-specific information.
- * @param lParam
- * Specifies additional message-specific information.
- */
- void PostMessage(HWND hWnd, int msg, WPARAM wParam, LPARAM lParam);
-
- /**
- * This function indicates to Windows that a thread has made a request to
- * terminate (quit). It is typically used in response to a WM_DESTROY
- * message.
- *
- * @param nExitCode
- * Specifies an application exit code. This value is used as the
- * wParam parameter of the WM_QUIT message.
- */
- void PostQuitMessage(int nExitCode);
-
- /**
- * The GetSystemMetrics function retrieves various system metrics (widths
- * and heights of display elements) and system configuration settings. All
- * dimensions retrieved by GetSystemMetrics are in pixels.
- *
- * @param nIndex
- * System metric or configuration setting to retrieve. This
- * parameter can be one of the following values. Note that all
- * SM_CX* values are widths and all SM_CY* values are heights.
- * Also note that all settings designed to return Boolean data
- * represent TRUE as any nonzero value, and FALSE as a zero
- * value.
- * @return If the function succeeds, the return value is the requested
- * system metric or configuration setting. If the function fails,
- * the return value is zero. GetLastError does not provide extended
- * error information.
- */
- public int GetSystemMetrics(int nIndex);
-
- /**
- * Changes the parent window of the specified child window.
- *
- * @param hWndChild
- * A handle to the child window.
- *
- * @param hWndNewParent
- * A handle to the new parent window. If this parameter is NULL,
- * the desktop window becomes the new parent window. If this
- * parameter is HWND_MESSAGE, the child window becomes a
- * message-only window.
- *
- * @return If the function succeeds, the return value is nonzero.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call GetLastError.
- */
- HWND SetParent(HWND hWndChild, HWND hWndNewParent);
-
- /**
- * Determines the visibility state of the specified window.
- *
- * @param hWnd
- * A handle to the window to be tested.
- *
- * @return If the specified window, its parent window, its parent's parent
- * window, and so forth, have the WS_VISIBLE style, the return value
- * is nonzero. Otherwise, the return value is zero.
- *
- * Because the return value specifies whether the window has the
- * WS_VISIBLE style, it may be nonzero even if the window is totally
- * obscured by other windows.
- */
- boolean IsWindowVisible(HWND hWnd);
-
- /**
- * Changes the position and dimensions of the specified window. For a
- * top-level window, the position and dimensions are relative to the
- * upper-left corner of the screen. For a child window, they are relative to
- * the upper-left corner of the parent window's client area.
- *
- * @param hWnd
- * A handle to the window.
- *
- * @param X
- * The new position of the left side of the window.
- *
- * @param Y
- * The new position of the top of the window.
- *
- * @param nWidth
- * The new width of the window.
- *
- * @param nHeight
- * The new height of the window.
- *
- * @param bRepaint
- * Indicates whether the window is to be repainted. If this
- * parameter is TRUE, the window receives a message. If the
- * parameter is FALSE, no repainting of any kind occurs. This
- * applies to the client area, the nonclient area (including the
- * title bar and scroll bars), and any part of the parent window
- * uncovered as a result of moving a child window.
- *
- * @return If the function succeeds, the return value is nonzero.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call GetLastError.
- */
- boolean MoveWindow(HWND hWnd, int X, int Y, int nWidth, int nHeight,
- boolean bRepaint);
-
- /**
- * Changes the size, position, and Z order of a child, pop-up, or top-level
- * window. These windows are ordered according to their appearance on the
- * screen. The topmost window receives the highest rank and is the first
- * window in the Z order.
- *
- * @param hWnd
- * A handle to the window.
- *
- * @param hWndInsertAfter
- * A handle to the window to precede the positioned window in the
- * Z order.
- *
- * @param X
- * The new position of the left side of the window, in client
- * coordinates.
- *
- * @param Y
- * The new position of the top of the window, in client
- * coordinates.
- *
- * @param cx
- * The new width of the window, in pixels.
- *
- * @param cy
- * The new height of the window, in pixels.
- *
- * @param uFlags
- * The window sizing and positioning flags.
- *
- * @return If the function succeeds, the return value is nonzero.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call GetLastError.
- */
- boolean SetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx,
- int cy, int uFlags);
-
- /**
- * Attaches or detaches the input processing mechanism of one thread to that
- * of another thread.
- *
- * @param idAttach
- * The identifier of the thread to be attached to another thread.
- * The thread to be attached cannot be a system thread.
- *
- * @param idAttachTo
- * The identifier of the thread to which idAttach will be
- * attached. This thread cannot be a system thread. A thread
- * cannot attach to itself. Therefore, idAttachTo cannot equal
- * idAttach.
- *
- * @param fAttach
- * If this parameter is TRUE, the two threads are attached. If
- * the parameter is FALSE, the threads are detached.
- *
- * @return If the function succeeds, the return value is nonzero.
- */
- boolean AttachThreadInput(DWORD idAttach, DWORD idAttachTo, boolean fAttach);
-
- /**
- * Brings the thread that created the specified window into the foreground
- * and activates the window. Keyboard input is directed to the window, and
- * various visual cues are changed for the user. The system assigns a
- * slightly higher priority to the thread that created the foreground window
- * than it does to other threads.
- *
- * @param hWnd
- * A handle to the window that should be activated and brought to
- * the foreground.
- *
- * @return If the window was brought to the foreground, the return value is
- * nonzero.
- */
- boolean SetForegroundWindow(HWND hWnd);
-
- /**
- * Retrieves a handle to the foreground window (the window with which the
- * user is currently working). The system assigns a slightly higher priority
- * to the thread that creates the foreground window than it does to other
- * threads.
- *
- * @return The return value is a handle to the foreground window. The
- * foreground window can be NULL in certain circumstances, such as
- * when a window is losing activation.
- */
- HWND GetForegroundWindow();
-
- /**
- * Sets the keyboard focus to the specified window. The window must be
- * attached to the calling thread's message queue.
- *
- * @param hWnd
- * A handle to the window that will receive the keyboard input.
- * If this parameter is NULL, keystrokes are ignored.
- *
- * @return If the function succeeds, the return value is the handle to the
- * window that previously had the keyboard focus. If the hWnd
- * parameter is invalid or the window is not attached to the calling
- * thread's message queue, the return value is NULL. To get extended
- * error information, call GetLastError.
- */
- HWND SetFocus(HWND hWnd);
-
- /**
- * Synthesizes keystrokes, mouse motions, and button clicks.
- *
- * @param nInputs
- * The number of structures in the pInputs array.
- *
- * @param pInputs
- * An array of INPUT structures. Each structure represents an
- * event to be inserted into the keyboard or mouse input stream.
- *
- * @param cbSize
- * The size, in bytes, of an INPUT structure. If cbSize is not
- * the size of an INPUT structure, the function fails.
- *
- * @return The function returns the number of events that it successfully
- * inserted into the keyboard or mouse input stream. If the function
- * returns zero, the input was already blocked by another thread. To
- * get extended error information, call GetLastError.
- *
- * This function fails when it is blocked by UIPI. Note that neither
- * GetLastError nor the return value will indicate the failure was
- * caused by UIPI blocking.
- */
- DWORD SendInput(DWORD nInputs, WinUser.INPUT[] pInputs, int cbSize);
-
- /**
- * Waits until the specified process has finished processing its initial
- * input and is waiting for user input with no input pending, or until the
- * time-out interval has elapsed.
- *
- * @param hProcess
- * A handle to the process. If this process is a console
- * application or does not have a message queue, WaitForInputIdle
- * returns immediately.
- *
- * @param dwMilliseconds
- * The time-out interval, in milliseconds. If dwMilliseconds is
- * INFINITE, the function does not return until the process is
- * idle.
- *
- * @return The following table shows the possible return values for this
- * function.
- *
- *
- * Return code/value |
- * Description |
- *
- *
- * 0 |
- * The wait was satisfied successfully. |
- *
- *
- * WAIT_TIMEOUT |
- * The wait was terminated because the time-out interval
- * elapsed. |
- *
- *
- * WAIT_FAILED |
- * An error occurred. |
- *
- *
- */
- DWORD WaitForInputIdle(HANDLE hProcess, DWORD dwMilliseconds);
-
- /**
- * The InvalidateRect function adds a rectangle to the specified window's
- * update region. The update region represents the portion of the window's
- * client area that must be redrawn.
- *
- * @param hWnd
- * A handle to the window whose update region has changed. If
- * this parameter is NULL, the system invalidates and redraws all
- * windows, not just the windows for this application, and sends
- * the WM_ERASEBKGND and WM_NCPAINT messages before the function
- * returns. Setting this parameter to NULL is not recommended.
- *
- * @param lpRect
- * A pointer to a RECT structure that contains the client
- * coordinates of the rectangle to be added to the update region.
- * If this parameter is NULL, the entire client area is added to
- * the update region.
- *
- * @param bErase
- * Specifies whether the background within the update region is
- * to be erased when the update region is processed. If this
- * parameter is TRUE, the background is erased when the
- * BeginPaint function is called. If this parameter is FALSE, the
- * background remains unchanged.
- *
- * @return If the function succeeds, the return value is nonzero. If the
- * function fails, the return value is zero.
- */
- boolean InvalidateRect(HWND hWnd, RECT.ByReference lpRect, boolean bErase);
-
- /**
- * The RedrawWindow function updates the specified rectangle or region in a
- * window's client area.
- *
- * @param hWnd
- * A handle to the window to be redrawn. If this parameter is
- * NULL, the desktop window is updated.
- *
- * @param lprcUpdate
- * A pointer to a RECT structure containing the coordinates, in
- * device units, of the update rectangle. This parameter is
- * ignored if the hrgnUpdate parameter identifies a region.
- *
- * @param hrgnUpdate
- * A handle to the update region. If both the hrgnUpdate and
- * lprcUpdate parameters are NULL, the entire client area is
- * added to the update region.
- *
- * @param flags
- * One or more redraw flags. This parameter can be used to
- * invalidate or validate a window, control repainting, and
- * control which windows are affected by RedrawWindow.
- *
- * @return If the function succeeds, the return value is nonzero. If the
- * function fails, the return value is zero.
- */
- boolean RedrawWindow(HWND hWnd, RECT.ByReference lprcUpdate,
- HRGN hrgnUpdate, DWORD flags);
-
- /**
- * Retrieves a handle to a window that has the specified relationship
- * (Z-Order or owner) to the specified window.
- *
- * @param hWnd
- * A handle to a window. The window handle retrieved is relative
- * to this window, based on the value of the uCmd parameter.
- *
- * @param uCmd
- * The relationship between the specified window and the window
- * whose handle is to be retrieved.
- *
- * @return If the function succeeds, the return value is a window handle. If
- * no window exists with the specified relationship to the specified
- * window, the return value is NULL. To get extended error
- * information, call GetLastError.
- */
- HWND GetWindow(HWND hWnd, DWORD uCmd);
-
- /**
- * The UpdateWindow function updates the client area of the specified window
- * by sending a WM_PAINT message to the window if the window's update region
- * is not empty. The function sends a WM_PAINT message directly to the
- * window procedure of the specified window, bypassing the application
- * queue. If the update region is empty, no message is sent.
- *
- * @param hWnd
- * Handle to the window to be updated.
- *
- * @return If the function succeeds, the return value is nonzero. If the
- * function fails, the return value is zero.
- */
- boolean UpdateWindow(HWND hWnd);
-
- /**
- * Sets the specified window's show state.
- *
- * @param hWnd
- * A handle to the window.
- *
- * @param nCmdShow
- * Controls how the window is to be shown. This parameter is
- * ignored the first time an application calls ShowWindow, if the
- * program that launched the application provides a STARTUPINFO
- * structure. Otherwise, the first time ShowWindow is called, the
- * value should be the value obtained by the WinMain function in
- * its nCmdShow parameter.
- *
- * @return If the function succeeds, the return value is nonzero.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call GetLastError.
- */
- boolean ShowWindow(HWND hWnd, int nCmdShow);
-
- /**
- * Minimizes (but does not destroy) the specified window.
- *
- * @param hWnd
- * A handle to the window to be minimized.
- *
- * @return If the function succeeds, the return value is nonzero.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call GetLastError.
- */
- boolean CloseWindow(HWND hWnd);
-
- /**
- * Defines a system-wide hot key.
- *
- * @param hWnd
- * A handle to the window that will receive
- * @param id
- * The identifier of the hot key
- * @param fsModifiers
- * The keys that must be pressed in combination with the key
- * specified by the uVirtKey parameter in order to generate the
- * @param vk
- * The virtual-key code of the hot key
- * @return If the function succeeds, the return value is nonzero.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call {@link Kernel32#GetLastError}.
- * {@link WinUser#WM_HOTKEY} messages generated by the hot key
- * {@link WinUser#WM_HOTKEY} message.
- * A combination of the following values
- *
- * - {@link WinUser#MOD_ALT} Either ALT key must be held down.
- * - {@link WinUser#MOD_CONTROL} Either CTRL key must be held
- * down.
- * - {@link WinUser#MOD_NOREPEAT} Changes the hotkey behavior so
- * that the keyboard auto-repeat does not yield multiple hotkey
- * notifications.
- * Windows Vista and Windows XP/2000: This flag is not
- * supported.
- * - {@link WinUser#MOD_SHIFT} Either SHIFT key must be held down.
- *
- * - {@link WinUser#MOD_WIN} Either WINDOWS key was held down.
- * These keys are labeled with the Windows logo.
- *
- */
- boolean RegisterHotKey(HWND hWnd, int id, int fsModifiers, int vk);
-
- /**
- * Frees a hot key previously registered by the calling thread.
- *
- * @param hWnd
- * A handle to the window associated with the hot key to be
- * freed. This parameter should be NULL if the hot key is not
- * associated with a window.
- *
- * @param id
- * The identifier of the hot key to be freed.
- *
- * @return If the function succeeds, the return value is nonzero.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call {@link Kernel32#GetLastError}.
- */
- boolean UnregisterHotKey(Pointer hWnd, int id);
-
- /**
- * Retrieves the time of the last input event.
- *
- * @param plii
- * structure that receives the time of the last input event
- * @return If the function succeeds, the return value is nonzero.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call {@link Kernel32#GetLastError}.
- */
- boolean GetLastInputInfo(LASTINPUTINFO plii);
-
- /**
- * Registers a window class for subsequent use in calls to the CreateWindow
- * or CreateWindowEx function.
- *
- * @param lpwcx
- * Type: const WNDCLASSEX* A pointer to a WNDCLASSEX structure.
- * You must fill the structure with the appropriate class
- * attributes before passing it to the function.
- *
- * @return If the function succeeds, the return value is a class atom that
- * uniquely identifies the class being registered. This atom can
- * only be used by the CreateWindow, CreateWindowEx, GetClassInfo,
- * GetClassInfoEx, FindWindow, FindWindowEx, and UnregisterClass
- * functions and the IActiveIMMap::FilterClientWindows method.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call {@link Kernel32#GetLastError}.
- */
- public ATOM RegisterClassEx(WNDCLASSEX lpwcx);
-
- /**
- * Unregisters a window class, freeing the memory required for the class.
- *
- * @param lpClassName
- * [in] Type: LPCTSTR
- *
- * A null-terminated string or a class atom. If lpClassName is a
- * string, it specifies the window class name. This class name
- * must have been registered by a previous call to the
- * RegisterClass or RegisterClassEx function. System classes,
- * such as dialog box controls, cannot be unregistered. If this
- * parameter is an atom, it must be a class atom created by a
- * previous call to the RegisterClass or RegisterClassEx
- * function. The atom must be in the low-order word of
- * lpClassName; the high-order word must be zero.
- *
- * @param hInstance
- * [in,optional] Type: HINSTANCE A handle to the instance of the
- * module that created the class. *
- *
- * @return Type: BOOL If the function succeeds, the return value is nonzero.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call {@link Kernel32#GetLastError}.
- */
- public boolean UnregisterClass(WString lpClassName, HINSTANCE hInstance);
-
- /**
- * Creates an overlapped, pop-up, or child window with an extended window
- * style; otherwise, this function is identical to the CreateWindow
- * function. For more information about creating a window and for full
- * descriptions of the other parameters of CreateWindowEx, see CreateWindow.
- *
- * @param dwExStyle
- * [in] Type: DWORD
- *
- * The extended window style of the window being created. For a
- * list of possible values,see Extended Window Styles.
- *
- * @param lpClassName
- * [in, optional] Type: LPCTSTR
- *
- * A null-terminated string or a class atom created by a previous
- * call to the RegisterClass or RegisterClassEx function. The
- * atom must be in the low-order word of lpClassName; the
- * high-order word must be zero. If lpClassName is a string, it
- * specifies the window class name. The class name can be any
- * name registered with RegisterClass or RegisterClassEx,
- * provided that the module that registers the class is also the
- * module that creates the window. The class name can also be any
- * of the predefined system class names.
- *
- * @param lpWindowName
- * [in, optional] Type: LPCTSTR
- *
- * The window name. If the window style specifies a title bar,
- * the window title pointed to by lpWindowName is displayed in
- * the title bar. When using CreateWindow to create controls,
- * such as buttons, check boxes, and static controls, use
- * lpWindowName to specify the text of the control. When creating
- * a static control with the SS_ICON style, use lpWindowName to
- * specify the icon name or identifier. To specify an identifier,
- * use the syntax "#num".
- *
- * @param dwStyle
- * [in] Type: DWORD
- *
- * The style of the window being created. This parameter can be a
- * combination of the window style values, plus the control
- * styles indicated in the Remarks section.
- *
- * @param x
- * [in] Type: int
- *
- * The initial horizontal position of the window. For an
- * overlapped or pop-up window, the x parameter is the initial
- * x-coordinate of the window's upper-left corner, in screen
- * coordinates. For a child window, x is the x-coordinate of the
- * upper-left corner of the window relative to the upper-left
- * corner of the parent window's client area. If x is set to
- * CW_USEDEFAULT, the system selects the default position for the
- * window's upper-left corner and ignores the y parameter.
- * CW_USEDEFAULT is valid only for overlapped windows; if it is
- * specified for a pop-up or child window, the x and y parameters
- * are set to zero.
- *
- * @param y
- * [in] Type: int
- *
- * The initial vertical position of the window. For an overlapped
- * or pop-up window, the y parameter is the initial y-coordinate
- * of the window's upper-left corner, in screen coordinates. For
- * a child window, y is the initial y-coordinate of the
- * upper-left corner of the child window relative to the
- * upper-left corner of the parent window's client area. For a
- * list box y is the initial y-coordinate of the upper-left
- * corner of the list box's client area relative to the
- * upper-left corner of the parent window's client area.
- *
- * If an overlapped window is created with the WS_VISIBLE style
- * bit set and the x parameter is set to CW_USEDEFAULT, then the
- * y parameter determines how the window is shown. If the y
- * parameter is CW_USEDEFAULT, then the window manager calls
- * ShowWindow with the SW_SHOW flag after the window has been
- * created. If the y parameter is some other value, then the
- * window manager calls ShowWindow with that value as the
- * nCmdShow parameter.
- *
- * @param nWidth
- * [in] Type: int
- *
- * The width, in device units, of the window. For overlapped
- * windows, nWidth is the window's width, in screen coordinates,
- * or CW_USEDEFAULT. If nWidth is CW_USEDEFAULT, the system
- * selects a default width and height for the window; the default
- * width extends from the initial x-coordinates to the right edge
- * of the screen; the default height extends from the initial
- * y-coordinate to the top of the icon area. CW_USEDEFAULT is
- * valid only for overlapped windows; if CW_USEDEFAULT is
- * specified for a pop-up or child window, the nWidth and nHeight
- * parameter are set to zero.
- *
- * @param nHeight
- * [in] Type: int
- *
- * The height, in device units, of the window. For overlapped
- * windows, nHeight is the window's height, in screen
- * coordinates. If the nWidth parameter is set to CW_USEDEFAULT,
- * the system ignores nHeight.
- *
- * @param hWndParent
- * [in, optional] Type: HWND
- *
- * A handle to the parent or owner window of the window being
- * created. To create a child window or an owned window, supply a
- * valid window handle. This parameter is optional for pop-up
- * windows.
- *
- * To create a message-only window, supply HWND_MESSAGE or a
- * handle to an existing message-only window.
- *
- * @param hMenu
- * [in, optional] Type: HMENU
- *
- * A handle to a menu, or specifies a child-window identifier,
- * depending on the window style. For an overlapped or pop-up
- * window, hMenu identifies the menu to be used with the window;
- * it can be NULL if the class menu is to be used. For a child
- * window, hMenu specifies the child-window identifier, an
- * integer value used by a dialog box control to notify its
- * parent about events. The application determines the
- * child-window identifier; it must be unique for all child
- * windows with the same parent window.
- *
- * @param hInstance
- * [in, optional] Type: HINSTANCE
- *
- * A handle to the instance of the module to be associated with
- * the window.
- *
- * @param lpParam
- * [in, optional] Type: LPVOID
- *
- * Pointer to a value to be passed to the window through the
- * CREATESTRUCT structure (lpCreateParams member) pointed to by
- * the lParam param of the WM_CREATE message. This message is
- * sent to the created window by this function before it returns.
- *
- * If an application calls CreateWindow to create a MDI client
- * window, lpParam should point to a CLIENTCREATESTRUCT
- * structure. If an MDI client window calls CreateWindow to
- * create an MDI child window, lpParam should point to a
- * MDICREATESTRUCT structure. lpParam may be NULL if no
- * additional data is needed.
- *
- * @return Type: HWND
- *
- * If the function succeeds, the return value is a handle to the new
- * window.
- *
- * If the function fails, the return value is NULL. To get extended
- * error information, call GetLastError.
- *
- * This function typically fails for one of the following reasons: •
- * an invalid parameter value • the system class was registered by a
- * different module • The WH_CBT hook is installed and returns a
- * failure code • if one of the controls in the dialog template is
- * not registered, or its window window procedure fails WM_CREATE or
- * WM_NCCREATE
- */
- public HWND CreateWindowEx(int dwExStyle, WString lpClassName,
- String lpWindowName, int dwStyle, int x, int y, int nWidth,
- int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance,
- LPVOID lpParam);
-
- /**
- * Destroys the specified window. The function sends WM_DESTROY and
- * WM_NCDESTROY messages to the window to deactivate it and remove the
- * keyboard focus from it. The function also destroys the window's menu,
- * flushes the thread message queue, destroys timers, removes clipboard
- * ownership, and breaks the clipboard viewer chain (if the window is at the
- * top of the viewer chain).
- *
- * If the specified window is a parent or owner window, DestroyWindow
- * automatically destroys the associated child or owned windows when it
- * destroys the parent or owner window. The function first destroys child or
- * owned windows, and then it destroys the parent or owner window.
- *
- * DestroyWindow also destroys modeless dialog boxes created by the
- * CreateDialog function.
- *
- * @param hWnd
- * [in] Type: HWND A handle to the window to be destroyed.
- *
- * @return Type: BOOL If the function succeeds, the return value is nonzero.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call {@link Kernel32#GetLastError}.
- */
- public boolean DestroyWindow(HWND hWnd);
-
- /**
- * Retrieves information about a window class, including a handle to the
- * small icon associated with the window class. The GetClassInfo function
- * does not retrieve a handle to the small icon.
- *
- * @param hinst
- * [in, optional] Type: HINSTANCE
- *
- * A handle to the instance of the application that created the
- * class. To retrieve information about classes defined by the
- * system (such as buttons or list boxes), set this parameter to
- * NULL.
- *
- * @param lpszClass
- * [in] Type: LPCTSTR
- *
- * The class name. The name must be that of a preregistered class
- * or a class registered by a previous call to the RegisterClass
- * or RegisterClassEx function. Alternatively, this parameter can
- * be a class atom created by a previous call to RegisterClass or
- * RegisterClassEx. The atom must be in the low-order word of
- * lpszClass; the high-order word must be zero.
- *
- * @param lpwcx
- * [out] Type: LPWNDCLASSEX
- *
- * A pointer to a WNDCLASSEX structure that receives the
- * information about the class.
- *
- * @return Type: BOOL If the function finds a matching class and
- * successfully copies the data, the return value is nonzero.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call {@link Kernel32#GetLastError} .
- */
- public boolean GetClassInfoEx(HINSTANCE hinst, WString lpszClass,
- WNDCLASSEX lpwcx);
-
- /**
- * Calls the default window procedure to provide default processing for any
- * window messages that an application does not process. This function
- * ensures that every message is processed. DefWindowProc is called with the
- * same parameters received by the window procedure.
- *
- * @param hWnd
- * [in] Type: HWND
- *
- * A handle to the window procedure that received the message.
- *
- * @param Msg
- * [in] Type: UINT
- *
- * The message.
- *
- * @param wParam
- * [in] Type: WPARAM
- *
- * Additional message information. The content of this parameter
- * depends on the value of the Msg parameter.
- *
- * @param lParam
- * [in] Type: LPARAM
- *
- * Additional message information. The content of this parameter
- * depends on the value of the Msg parameter.
- *
- * @return Type: LRESULT The return value is the result of the message
- * processing and depends on the message.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call {@link Kernel32#GetLastError}.
- */
- public LRESULT DefWindowProc(HWND hWnd, int Msg, WPARAM wParam,
- LPARAM lParam);
-
- /**
- * Registers the device or type of device for which a window will receive
- * notifications.
- *
- * @hRecipient [in] A handle to the window or service that will receive
- * device events for the devices specified in the
- * NotificationFilter parameter. The same window handle can be
- * used in multiple calls to RegisterDeviceNotification.
- *
- * Services can specify either a window handle or service status
- * handle.
- *
- * @param NotificationFilter
- * [in] A pointer to a block of data that specifies the type of
- * device for which notifications should be sent. This block
- * always begins with the DEV_BROADCAST_HDR structure. The data
- * following this header is dependent on the value of the
- * dbch_devicetype member, which can be
- * DBT_DEVTYP_DEVICEINTERFACE or DBT_DEVTYP_HANDLE. For more
- * information, see Remarks.
- *
- * @param Flags
- * [in] This parameter can be one of the following values.
- * DEVICE_NOTIFY_WINDOW_HANDLE0x00000000 The hRecipient parameter
- * is a window handle.
- *
- * DEVICE_NOTIFY_SERVICE_HANDLE0x00000001 The hRecipient
- * parameter is a service status handle.
- *
- * In addition, you can specify the following value.
- *
- * DEVICE_NOTIFY_ALL_INTERFACE_CLASSES0x00000004 Notifies the
- * recipient of device interface events for all device interface
- * classes. (The dbcc_classguid member is ignored.)
- *
- * This value can be used only if the dbch_devicetype member is
- * DBT_DEVTYP_DEVICEINTERFACE.
- *
- * @return value
- *
- * If the function succeeds, the return value is a device
- * notification handle.
- *
- * If the function fails, the return value is NULL. To get extended
- * error information, call GetLastError.
- */
- HDEVNOTIFY RegisterDeviceNotification(HANDLE hRecipient,
- Structure notificationFilter, int Flags);
-
- /**
- * Closes the specified device notification handle.
- *
- * @Handle [in] Device notification handle returned by the
- * RegisterDeviceNotification function.
- *
- * @return Return value
- *
- * If the function succeeds, the return value is nonzero.
- *
- * If the function fails, the return value is zero. To get extended
- * error information, call GetLastError.
- */
- boolean UnregisterDeviceNotification(HDEVNOTIFY Handle);
-}
+/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package com.sun.jna.platform.win32;
+
+import com.sun.jna.Native;
+import com.sun.jna.Pointer;
+import com.sun.jna.Structure;
+import com.sun.jna.WString;
+import com.sun.jna.platform.win32.BaseTSD.LONG_PTR;
+import com.sun.jna.platform.win32.WinNT.HANDLE;
+import com.sun.jna.ptr.ByteByReference;
+import com.sun.jna.ptr.IntByReference;
+import com.sun.jna.win32.StdCallLibrary;
+import com.sun.jna.win32.W32APIOptions;
+
+// TODO: Auto-generated Javadoc
+/**
+ * Provides access to the w32 user32 library. Incomplete implementation to
+ * support demos.
+ *
+ * @author Todd Fast, todd.fast@sun.com
+ * @author twalljava@dev.java.net
+ * @author Tobias Wolf, wolf.tobias@gmx.net
+ */
+public interface User32 extends StdCallLibrary, WinUser {
+
+ /** The instance. */
+ User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class,
+ W32APIOptions.DEFAULT_OPTIONS);
+
+ /** The cs globalclass. */
+ int CS_GLOBALCLASS = 0x4000;
+
+ /** The ws ex topmost. */
+ int WS_EX_TOPMOST = 0x00000008;
+
+ /** The ws overlapped. */
+ int WS_OVERLAPPED = 0x00000000;
+
+ /** The hRecipient parameter is a window handle. */
+ int DEVICE_NOTIFY_WINDOW_HANDLE = 0x00000000;
+
+ /** The hRecipient parameter is a service status handle. */
+ int DEVICE_NOTIFY_SERVICE_HANDLE = 0x00000001;
+
+ /** The device notify all interface classes. */
+ int DEVICE_NOTIFY_ALL_INTERFACE_CLASSES = 0x00000004;
+
+ /**
+ * This function retrieves a handle to a display device context (DC) for the
+ * client area of the specified window. The display device context can be
+ * used in subsequent graphics display interface (GDI) functions to draw in
+ * the client area of the window.
+ *
+ * @param hWnd
+ * Handle to the window whose device context is to be retrieved.
+ * If this value is NULL, GetDC retrieves the device context for
+ * the entire screen.
+ * @return The handle the device context for the specified window's client
+ * area indicates success. NULL indicates failure. To get extended
+ * error information, call GetLastError.
+ */
+ HDC GetDC(HWND hWnd);
+
+ /**
+ * This function releases a device context (DC), freeing it for use by other
+ * applications. The effect of ReleaseDC depends on the type of device
+ * context.
+ *
+ * @param hWnd
+ * Handle to the window whose device context is to be released.
+ * @param hDC
+ * Handle to the device context to be released.
+ * @return The return value specifies whether the device context is
+ * released. 1 indicates that the device context is released. Zero
+ * indicates that the device context is not released.
+ */
+ int ReleaseDC(HWND hWnd, HDC hDC);
+
+ /**
+ * This function retrieves the handle to the top-level window whose class
+ * name and window name match the specified strings. This function does not
+ * search child windows.
+ *
+ * @param lpClassName
+ * Long pointer to a null-terminated string that specifies the
+ * class name or is an atom that identifies the class-name
+ * string. If this parameter is an atom, it must be a global atom
+ * created by a previous call to the GlobalAddAtom function. The
+ * atom, a 16-bit value, must be placed in the low-order word of
+ * lpClassName; the high-order word must be zero.
+ * @param lpWindowName
+ * Long pointer to a null-terminated string that specifies the
+ * window name (the window's title). If this parameter is NULL,
+ * all window names match.
+ * @return A handle to the window that has the specified class name and
+ * window name indicates success. NULL indicates failure. To get
+ * extended error information, call GetLastError.
+ */
+ HWND FindWindow(String lpClassName, String lpWindowName);
+
+ /**
+ * This function retrieves the name of the class to which the specified
+ * window belongs.
+ *
+ * @param hWnd
+ * Handle to the window and, indirectly, the class to which the
+ * window belongs.
+ * @param lpClassName
+ * Long pointer to the buffer that is to receive the class name
+ * string.
+ * @param nMaxCount
+ * Specifies the length, in characters, of the buffer pointed to
+ * by the lpClassName parameter. The class name string is
+ * truncated if it is longer than the buffer.
+ * @return The number of characters copied to the specified buffer indicates
+ * success. Zero indicates failure. To get extended error
+ * information, call GetLastError.
+ */
+ int GetClassName(HWND hWnd, char[] lpClassName, int nMaxCount);
+
+ /**
+ * Retrieves information about the active window or a specified graphical
+ * user interface (GUI) thread.
+ *
+ * @param idThread
+ * Identifies the thread for which information is to be
+ * retrieved. To retrieve this value, use the
+ * GetWindowThreadProcessId function. If this parameter is NULL,
+ * the function returns information for the foreground thread.
+ * @param lpgui
+ * Pointer to a GUITHREADINFO structure that receives information
+ * describing the thread. Note that you must set
+ * GUITHREADINFO.cbSize to sizeof(GUITHREADINFO) before calling
+ * this function.
+ * @return If the function succeeds, the return value is nonzero. If the
+ * function fails, the return value is zero. To get extended error
+ * information, call GetLastError.
+ */
+ boolean GetGUIThreadInfo(int idThread, GUITHREADINFO lpgui);
+
+ /**
+ * The GetWindowInfo function retrieves information about the specified
+ * window.
+ *
+ * @param hWnd
+ * Handle to the window whose information is to be retrieved.
+ * @param pwi
+ * Pointer to a WINDOWINFO structure to receive the information.
+ * Note that you must set WINDOWINFO.cbSize to sizeof(WINDOWINFO)
+ * before calling this function.
+ * @return If the function succeeds, the return value is nonzero. If the
+ * function fails, the return value is zero.
+ */
+ boolean GetWindowInfo(HWND hWnd, WINDOWINFO pwi);
+
+ /**
+ * This function retrieves the dimensions of the bounding rectangle of the
+ * specified window. The dimensions are given in screen coordinates that are
+ * relative to the upper-left corner of the screen.
+ *
+ * @param hWnd
+ * Handle to the window.
+ * @param rect
+ * Long pointer to a RECT structure that receives the screen
+ * coordinates of the upper-left and lower-right corners of the
+ * window.
+ * @return Nonzero indicates success. Zero indicates failure. To get
+ * extended error information, call GetLastError.
+ */
+ boolean GetWindowRect(HWND hWnd, RECT rect);
+
+ /**
+ * This function copies the text of the specified window's title bar - if it
+ * has one - into a buffer. If the specified window is a control, the text
+ * of the control is copied.
+ *
+ * @param hWnd
+ * Handle to the window or control containing the text.
+ * @param lpString
+ * Long pointer to the buffer that will receive the text.
+ * @param nMaxCount
+ * Specifies the maximum number of characters to copy to the
+ * buffer, including the NULL character. If the text exceeds this
+ * limit, it is truncated.
+ * @return The length, in characters, of the copied string, not including
+ * the terminating null character, indicates success. Zero indicates
+ * that the window has no title bar or text, if the title bar is
+ * empty, or if the window or control handle is invalid. To get
+ * extended error information, call GetLastError. This function
+ * cannot retrieve the text of an edit control in another
+ * application.
+ */
+ int GetWindowText(HWND hWnd, char[] lpString, int nMaxCount);
+
+ /**
+ * This function retrieves the length, in characters, of the specified
+ * window's title bar text - if the window has a title bar. If the specified
+ * window is a control, the function retrieves the length of the text within
+ * the control.
+ *
+ * @param hWnd
+ * Handle to the window or control.
+ * @return The length, in characters, of the text indicates success. Under
+ * certain conditions, this value may actually be greater than the
+ * length of the text. Zero indicates that the window has no text.
+ * To get extended error information, call GetLastError.
+ */
+ int GetWindowTextLength(HWND hWnd);
+
+ /**
+ * The GetWindowModuleFileName function retrieves the full path and file
+ * name of the module associated with the specified window handle.
+ *
+ * @param hWnd
+ * Handle to the window whose module file name will be retrieved.
+ * @param lpszFileName
+ * Pointer to a buffer that receives the path and file name.
+ * @param cchFileNameMax
+ * Specifies the maximum number of TCHARs that can be copied into
+ * the lpszFileName buffer.
+ * @return The return value is the total number of TCHARs copied into the
+ * buffer.
+ */
+ int GetWindowModuleFileName(HWND hWnd, char[] lpszFileName,
+ int cchFileNameMax);
+
+ /**
+ * This function retrieves the identifier of the thread that created the
+ * specified window and, optionally, the identifier of the process that
+ * created the window.
+ *
+ * @param hWnd
+ * Handle to the window.
+ * @param lpdwProcessId
+ * Pointer to a 32-bit value that receives the process
+ * identifier. If this parameter is not NULL,
+ * GetWindowThreadProcessId copies the identifier of the process
+ * to the 32-bit value; otherwise, it does not.
+ * @return The return value is the identifier of the thread that created the
+ * window.
+ */
+ int GetWindowThreadProcessId(HWND hWnd, IntByReference lpdwProcessId);
+
+ /**
+ * This function enumerates all top-level windows on the screen by passing
+ * the handle to each window, in turn, to an application-defined callback
+ * function. EnumWindows continues until the last top-level window is
+ * enumerated or the callback function returns FALSE.
+ *
+ * @param lpEnumFunc
+ * Long pointer to an application-defined callback function.
+ * @param data
+ * Specifies an application-defined value to be passed to the
+ * callback function.
+ * @return Nonzero indicates success. Zero indicates failure. To get
+ * extended error information, call GetLastError.
+ */
+ boolean EnumWindows(WNDENUMPROC lpEnumFunc, Pointer data);
+
+ /**
+ * The EnumChildWindows function enumerates the child windows that belong to
+ * the specified parent window by passing the handle to each child window,
+ * in turn, to an application-defined callback function. EnumChildWindows
+ * continues until the last child window is enumerated or the callback
+ * function returns FALSE.
+ *
+ * @param hWnd
+ * Handle to the parent window whose child windows are to be
+ * enumerated. If this parameter is NULL, this function is
+ * equivalent to EnumWindows.
+ * @param lpEnumFunc
+ * Pointer to an application-defined callback function.
+ * @param data
+ * Specifies an application-defined value to be passed to the
+ * callback function.
+ * @return If the function succeeds, the return value is nonzero. If the
+ * function fails, the return value is zero. To get extended error
+ * information, call GetLastError. If EnumChildProc returns zero,
+ * the return value is also zero. In this case, the callback
+ * function should call SetLastError to obtain a meaningful error
+ * code to be returned to the caller of EnumChildWindows.
+ */
+ boolean EnumChildWindows(HWND hWnd, WNDENUMPROC lpEnumFunc, Pointer data);
+
+ /**
+ * The EnumThreadWindows function enumerates all nonchild windows associated
+ * with a thread by passing the handle to each window, in turn, to an
+ * application-defined callback function. EnumThreadWindows continues until
+ * the last window is enumerated or the callback function returns FALSE. To
+ * enumerate child windows of a particular window, use the EnumChildWindows
+ * function.
+ *
+ * @param dwThreadId
+ * Identifies the thread whose windows are to be enumerated.
+ * @param lpEnumFunc
+ * Pointer to an application-defined callback function.
+ * @param data
+ * Specifies an application-defined value to be passed to the
+ * callback function.
+ * @return If the callback function returns TRUE for all windows in the
+ * thread specified by dwThreadId, the return value is TRUE. If the
+ * callback function returns FALSE on any enumerated window, or if
+ * there are no windows found in the thread specified by dwThreadId,
+ * the return value is FALSE.
+ */
+ boolean EnumThreadWindows(int dwThreadId, WNDENUMPROC lpEnumFunc,
+ Pointer data);
+
+ /**
+ * The FlashWindowEx function flashes the specified window. It does not
+ * change the active state of the window.
+ *
+ * @param pfwi
+ * Pointer to the FLASHWINFO structure.
+ * @return The return value specifies the window's state before the call to
+ * the FlashWindowEx function. If the window caption was drawn as
+ * active before the call, the return value is nonzero. Otherwise,
+ * the return value is zero.
+ */
+ boolean FlashWindowEx(FLASHWINFO pfwi);
+
+ /**
+ * This function loads the specified icon resource from the executable
+ * (.exe) file associated with an application instance.
+ *
+ * @param hInstance
+ * Handle to an instance of the module whose executable file
+ * contains the icon to be loaded. This parameter must be NULL
+ * when a standard icon is being loaded.
+ * @param iconName
+ * Long pointer to a null-terminated string that contains the
+ * name of the icon resource to be loaded. Alternatively, this
+ * parameter can contain the resource identifier in the low-order
+ * word and zero in the high-order word. Use the MAKEINTRESOURCE
+ * macro to create this value.
+ * @return A handle to the newly loaded icon indicates success. NULL
+ * indicates failure. To get extended error information, call
+ * GetLastError.
+ */
+ HICON LoadIcon(HINSTANCE hInstance, String iconName);
+
+ /**
+ * This function loads an icon, cursor, or bitmap.
+ *
+ * @param hinst
+ * Handle to an instance of the module that contains the image to
+ * be loaded.
+ * @param name
+ * Pointer to a null-terminated string that contains the name of
+ * the image resource in the hinst module that identifies the
+ * image to load.
+ * @param type
+ * Specifies the type of image to be loaded.
+ * @param xDesired
+ * Specifies the width, in pixels, of the icon or cursor. If this
+ * parameter is zero, the function uses the SM_CXICON or
+ * SM_CXCURSOR system metric value to set the width. If uType is
+ * IMAGE_BITMAP, this parameter must be zero.
+ * @param yDesired
+ * Specifies the height, in pixels, of the icon or cursor. If
+ * this parameter is zero, the function uses the SM_CYICON or
+ * SM_CYCURSOR system metric value to set the height. If uType is
+ * IMAGE_BITMAP, this parameter must be zero.
+ * @param load
+ * Set to zero.
+ * @return The handle of the newly loaded image indicates success. NULL
+ * indicates failure. To get extended error information, call
+ * GetLastError.
+ */
+ HANDLE LoadImage(HINSTANCE hinst, String name, int type, int xDesired,
+ int yDesired, int load);
+
+ /**
+ * This function destroys an icon and frees any memory the icon occupied.
+ *
+ * @param hicon
+ * Handle to the icon to be destroyed. The icon must not be in
+ * use.
+ * @return Nonzero indicates success. Zero indicates failure. To get
+ * extended error information, call GetLastError.
+ */
+ boolean DestroyIcon(HICON hicon);
+
+ /**
+ * This function retrieves information about the specified window.
+ * GetWindowLong also retrieves the 32-bit (long) value at the specified
+ * offset into the extra window memory of a window.
+ *
+ * @param hWnd
+ * Handle to the window and, indirectly, the class to which the
+ * window belongs.
+ * @param nIndex
+ * Specifies the zero-based offset to the value to be retrieved.
+ * @return The requested 32-bit value indicates success. Zero indicates
+ * failure. To get extended error information, call GetLastError.
+ */
+ int GetWindowLong(HWND hWnd, int nIndex);
+
+ /**
+ * This function changes an attribute of the specified window. SetWindowLong
+ * also sets a 32-bit (LONG) value at the specified offset into the extra
+ * window memory of a window.
+ *
+ * @param hWnd
+ * Handle to the window and, indirectly, the class to which the
+ * window belongs.
+ * @param nIndex
+ * Specifies the zero-based offset to the value to be set.
+ * @param dwNewLong
+ * Specifies the replacement value.
+ * @return The previous value of the specified 32-bit integer indicates
+ * success. Zero indicates failure. To get extended error
+ * information, call GetLastError.
+ */
+ int SetWindowLong(HWND hWnd, int nIndex, int dwNewLong);
+
+ /**
+ * This function changes an attribute of the specified window. SetWindowLong
+ * also sets a 32-bit (LONG) value at the specified offset into the extra
+ * window memory of a window. Do not use this version on Windows-64.
+ *
+ * @param hWnd
+ * Handle to the window and, indirectly, the class to which the
+ * window belongs.
+ * @param nIndex
+ * Specifies the zero-based offset to the value to be set.
+ * @param dwNewLong
+ * Specifies the replacement value.
+ * @return The previous value of the specified 32-bit integer indicates
+ * success. Zero indicates failure. To get extended error
+ * information, call GetLastError.
+ */
+ Pointer SetWindowLong(HWND hWnd, int nIndex, Pointer dwNewLong);
+
+ /**
+ * The GetWindowLongPtr function retrieves information about the specified
+ * window. The function also retrieves the value at a specified offset into
+ * the extra window memory.
+ *
+ * @param hWnd
+ * Handle to the window and, indirectly, the class to which the
+ * window belongs.
+ * @param nIndex
+ * Specifies the zero-based offset to the value to be retrieved.
+ * @return If the function succeeds, the return value is the requested
+ * value. If the function fails, the return value is zero. To get
+ * extended error information, call GetLastError. If SetWindowLong
+ * or SetWindowLongPtr has not been called previously,
+ * GetWindowLongPtr returns zero for values in the extra window or
+ * class memory.
+ */
+ LONG_PTR GetWindowLongPtr(HWND hWnd, int nIndex);
+
+ /**
+ * The SetWindowLongPtr function changes an attribute of the specified
+ * window. The function also sets a value at the specified offset in the
+ * extra window memory.
+ *
+ * @param hWnd
+ * Handle to the window and, indirectly, the class to which the
+ * window belongs.
+ * @param nIndex
+ * Specifies the zero-based offset to the value to be set.
+ * @param dwNewLongPtr
+ * Specifies the replacement value.
+ * @return If the function succeeds, the return value is the previous value
+ * of the specified offset. If the function fails, the return value
+ * is zero. To get extended error information, call GetLastError. If
+ * the previous value is zero and the function succeeds, the return
+ * value is zero, but the function does not clear the last error
+ * information. To determine success or failure, clear the last
+ * error information by calling SetLastError(0), then call
+ * SetWindowLongPtr. Function failure will be indicated by a return
+ * value of zero and a GetLastError result that is nonzero.
+ */
+ LONG_PTR SetWindowLongPtr(HWND hWnd, int nIndex, LONG_PTR dwNewLongPtr);
+
+ /**
+ * The SetWindowLongPtr function changes an attribute of the specified
+ * window. The function also sets a value at the specified offset in the
+ * extra window memory.
+ *
+ * @param hWnd
+ * Handle to the window and, indirectly, the class to which the
+ * window belongs.
+ * @param nIndex
+ * Specifies the zero-based offset to the value to be set.
+ * @param dwNewLongPtr
+ * Specifies the replacement value.
+ * @return If the function succeeds, the return value is the previous value
+ * of the specified offset. If the function fails, the return value
+ * is zero. To get extended error information, call GetLastError. If
+ * the previous value is zero and the function succeeds, the return
+ * value is zero, but the function does not clear the last error
+ * information. To determine success or failure, clear the last
+ * error information by calling SetLastError(0), then call
+ * SetWindowLongPtr. Function failure will be indicated by a return
+ * value of zero and a GetLastError result that is nonzero.
+ */
+ Pointer SetWindowLongPtr(HWND hWnd, int nIndex, Pointer dwNewLongPtr);
+
+ /**
+ * The SetLayeredWindowAttributes function sets the opacity and transparency
+ * color key of a layered window.
+ *
+ * @param hwnd
+ * Handle to the layered window.
+ * @param crKey
+ * COLORREF structure that specifies the transparency color key
+ * to be used when composing the layered window.
+ * @param bAlpha
+ * Alpha value used to describe the opacity of the layered
+ * window.
+ * @param dwFlags
+ * Specifies an action to take.
+ * @return If the function succeeds, the return value is nonzero. If the
+ * function fails, the return value is zero. To get extended error
+ * information, call GetLastError.
+ */
+ boolean SetLayeredWindowAttributes(HWND hwnd, int crKey, byte bAlpha,
+ int dwFlags);
+
+ /**
+ * The GetLayeredWindowAttributes function retrieves the opacity and
+ * transparency color key of a layered window.
+ *
+ * @param hwnd
+ * Handle to the layered window. A layered window is created by
+ * specifying WS_EX_LAYERED when creating the window with the
+ * CreateWindowEx function or by setting WS_EX_LAYERED via
+ * SetWindowLong after the window has been created.
+ * @param pcrKey
+ * Pointer to a COLORREF value that receives the transparency
+ * color key to be used when composing the layered window. All
+ * pixels painted by the window in this color will be
+ * transparent. This can be NULL if the argument is not needed.
+ * @param pbAlpha
+ * Pointer to a BYTE that receives the Alpha value used to
+ * describe the opacity of the layered window. Similar to the
+ * SourceConstantAlpha member of the BLENDFUNCTION structure.
+ * When the variable referred to by pbAlpha is 0, the window is
+ * completely transparent. When the variable referred to by
+ * pbAlpha is 255, the window is opaque. This can be NULL if the
+ * argument is not needed.
+ * @param pdwFlags
+ * Pointer to a DWORD that receives a layering flag. This can be
+ * NULL if the argument is not needed.
+ * @return If the function succeeds, the return value is nonzero. If the
+ * function fails, the return value is zero. To get extended error
+ * information, call GetLastError.
+ */
+ boolean GetLayeredWindowAttributes(HWND hwnd, IntByReference pcrKey,
+ ByteByReference pbAlpha, IntByReference pdwFlags);
+
+ /**
+ * The UpdateLayeredWindow function updates the position, size, shape,
+ * content, and translucency of a layered window.
+ *
+ * @param hwnd
+ * Handle to a layered window. A layered window is created by
+ * specifying WS_EX_LAYERED when creating the window with the
+ * CreateWindowEx function.
+ * @param hdcDst
+ * Handle to a device context (DC) for the screen. This handle is
+ * obtained by specifying NULL when calling the function. It is
+ * used for palette color matching when the window contents are
+ * updated. If hdcDst isNULL, the default palette will be used.
+ * If hdcSrc is NULL, hdcDst must be NULL.
+ * @param pptDst
+ * Pointer to a POINT structure that specifies the new screen
+ * position of the layered window. If the current position is not
+ * changing, pptDst can be NULL.
+ * @param psize
+ * Pointer to a SIZE structure that specifies the new size of the
+ * layered window. If the size of the window is not changing,
+ * psize can be NULL. If hdcSrc is NULL, psize must be NULL.
+ * @param hdcSrc
+ * Handle to a DC for the surface that defines the layered
+ * window. This handle can be obtained by calling the
+ * CreateCompatibleDC function. If the shape and visual context
+ * of the window are not changing, hdcSrc can be NULL.
+ * @param pptSrc
+ * Pointer to a POINT structure that specifies the location of
+ * the layer in the device context. If hdcSrc is NULL, pptSrc
+ * should be NULL.
+ * @param crKey
+ * Pointer to a COLORREF value that specifies the color key to be
+ * used when composing the layered window. To generate a
+ * COLORREF, use the RGB macro.
+ * @param pblend
+ * Pointer to a BLENDFUNCTION structure that specifies the
+ * transparency value to be used when composing the layered
+ * window.
+ * @param dwFlags
+ * ULW_* flags.
+ * @return If the function succeeds, the return value is nonzero. If the
+ * function fails, the return value is zero. To get extended error
+ * information, call GetLastError.
+ */
+ boolean UpdateLayeredWindow(HWND hwnd, HDC hdcDst, POINT pptDst,
+ SIZE psize, HDC hdcSrc, POINT pptSrc, int crKey,
+ BLENDFUNCTION pblend, int dwFlags);
+
+ /**
+ * This function sets the window region of a window. The window region
+ * determines the area within the window where the system permits drawing.
+ * The system does not display any portion of a window that lies outside of
+ * the window region.
+ *
+ * @param hWnd
+ * Handle to the window whose window region is to be set.
+ * @param hRgn
+ * Handle to a region. The function sets the window region of the
+ * window to this region. If hRgn is NULL, the function sets the
+ * window region to NULL.
+ * @param bRedraw
+ * Specifies whether the system redraws the window after setting
+ * the window region. If bRedraw is TRUE, the system does so;
+ * otherwise, it does not. Typically, you set bRedraw to TRUE if
+ * the window is visible.
+ * @return Nonzero indicates success. Zero indicates failure. To get
+ * extended error information, call GetLastError.
+ */
+ int SetWindowRgn(HWND hWnd, HRGN hRgn, boolean bRedraw);
+
+ /**
+ * The GetKeyboardState function copies the status of the 256 virtual keys
+ * to the specified buffer.
+ *
+ * @param lpKeyState
+ * Pointer to the 256-byte array that receives the status data
+ * for each virtual key.
+ * @return If the function succeeds, the return value is nonzero. If the
+ * function fails, the return value is zero. To get extended error
+ * information, call GetLastError.
+ */
+ boolean GetKeyboardState(byte[] lpKeyState);
+
+ /**
+ * This function determines whether a key is up or down at the time the
+ * function is called, and whether the key was pressed after a previous call
+ * to GetAsyncKeyState.
+ *
+ * @param vKey
+ * Specifies one of 256 possible virtual-key codes.
+ * @return If the function succeeds, the return value specifies whether the
+ * key was pressed since the last call to GetAsyncKeyState, and
+ * whether the key is currently up or down. If the most significant
+ * bit is set, the key is down.
+ */
+ short GetAsyncKeyState(int vKey);
+
+ /**
+ * The SetWindowsHookEx function installs an application-defined hook
+ * procedure into a hook chain. You would install a hook procedure to
+ * monitor the system for certain types of events. These events are
+ * associated either with a specific thread or with all threads in the same
+ * desktop as the calling thread.
+ *
+ * @param idHook
+ * Specifies the type of hook procedure to be installed.
+ * @param lpfn
+ * Pointer to the hook procedure.
+ * @param hMod
+ * Handle to the DLL containing the hook procedure pointed to by
+ * the lpfn parameter.
+ * @param dwThreadId
+ * Specifies the identifier of the thread with which the hook
+ * procedure is to be associated.
+ * @return If the function succeeds, the return value is the handle to the
+ * hook procedure. If the function fails, the return value is NULL.
+ * To get extended error information, call GetLastError.
+ */
+ HHOOK SetWindowsHookEx(int idHook, HOOKPROC lpfn, HINSTANCE hMod,
+ int dwThreadId);
+
+ /**
+ * The CallNextHookEx function passes the hook information to the next hook
+ * procedure in the current hook chain. A hook procedure can call this
+ * function either before or after processing the hook information.
+ *
+ * @param hhk
+ * Ignored.
+ * @param nCode
+ * Specifies the hook code passed to the current hook procedure.
+ * The next hook procedure uses this code to determine how to
+ * process the hook information.
+ * @param wParam
+ * Specifies the wParam value passed to the current hook
+ * procedure. The meaning of this parameter depends on the type
+ * of hook associated with the current hook chain.
+ * @param lParam
+ * Specifies the lParam value passed to the current hook
+ * procedure. The meaning of this parameter depends on the type
+ * of hook associated with the current hook chain.
+ * @return This value is returned by the next hook procedure in the chain.
+ * The current hook procedure must also return this value. The
+ * meaning of the return value depends on the hook type.
+ */
+ LRESULT CallNextHookEx(HHOOK hhk, int nCode, WPARAM wParam, LPARAM lParam);
+
+ /**
+ * The CallNextHookEx function passes the hook information to the next hook
+ * procedure in the current hook chain. A hook procedure can call this
+ * function either before or after processing the hook information.
+ *
+ * @param hhk
+ * Ignored.
+ * @param nCode
+ * Specifies the hook code passed to the current hook procedure.
+ * The next hook procedure uses this code to determine how to
+ * process the hook information.
+ * @param wParam
+ * Specifies the wParam value passed to the current hook
+ * procedure. The meaning of this parameter depends on the type
+ * of hook associated with the current hook chain.
+ * @param lParam
+ * Specifies the lParam value passed to the current hook
+ * procedure. The meaning of this parameter depends on the type
+ * of hook associated with the current hook chain.
+ * @return This value is returned by the next hook procedure in the chain.
+ * The current hook procedure must also return this value. The
+ * meaning of the return value depends on the hook type.
+ */
+ LRESULT CallNextHookEx(HHOOK hhk, int nCode, WPARAM wParam, Pointer lParam);
+
+ /**
+ * The UnhookWindowsHookEx function removes a hook procedure installed in a
+ * hook chain by the SetWindowsHookEx function.
+ *
+ * @param hhk
+ * Handle to the hook to be removed. This parameter is a hook
+ * handle obtained by a previous call to SetWindowsHookEx.
+ * @return If the function succeeds, the return value is nonzero. If the
+ * function fails, the return value is zero. To get extended error
+ * information, call GetLastError.
+ */
+ boolean UnhookWindowsHookEx(HHOOK hhk);
+
+ /**
+ * This function retrieves a message from the calling thread's message queue
+ * and places it in the specified structure.
+ *
+ * @param lpMsg
+ * Pointer to an MSG structure that receives message information
+ * from the thread's message queue.
+ * @param hWnd
+ * Handle to the window whose messages are to be retrieved. One
+ * value has a special meaning.
+ * @param wMsgFilterMin
+ * Specifies the integer value of the lowest message value to be
+ * retrieved.
+ * @param wMsgFilterMax
+ * Specifies the integer value of the highest message value to be
+ * retrieved.
+ * @return Nonzero indicates that the function retrieves a message other
+ * than WM_QUIT. Zero indicates that the function retrieves the
+ * WM_QUIT message, or that lpMsg is an invalid pointer. To get
+ * extended error information, call GetLastError.
+ */
+ int GetMessage(MSG lpMsg, HWND hWnd, int wMsgFilterMin, int wMsgFilterMax);
+
+ /**
+ * This function checks a thread message queue for a message and places the
+ * message (if any) in the specified structure.
+ *
+ * @param lpMsg
+ * Pointer to an MSG structure that receives message information.
+ * @param hWnd
+ * Handle to the window whose messages are to be examined.
+ * @param wMsgFilterMin
+ * Specifies the value of the first message in the range of
+ * messages to be examined.
+ * @param wMsgFilterMax
+ * Specifies the value of the last message in the range of
+ * messages to be examined.
+ * @param wRemoveMsg
+ * Specifies how messages are handled. This parameter can be one
+ * of the following values.
+ * @return Nonzero indicates success. Zero indicates failure.
+ */
+ boolean PeekMessage(MSG lpMsg, HWND hWnd, int wMsgFilterMin,
+ int wMsgFilterMax, int wRemoveMsg);
+
+ /**
+ * This function translates virtual-key messages into character messages.
+ * The character messages are posted to the calling thread's message queue,
+ * to be read the next time the thread calls the GetMessage or PeekMessage
+ * function.
+ *
+ * @param lpMsg
+ * Pointer to an MSG structure that contains message information
+ * retrieved from the calling thread's message queue by using the
+ * GetMessage or PeekMessage function.
+ * @return Nonzero indicates that the message is translated, that is, a
+ * character message is posted to the thread's message queue. If the
+ * message is WM_KEYDOWN or WM_SYSKEYDOWN, the return value is
+ * nonzero, regardless of the translation. Zero indicates that the
+ * message is not translated, that is, a character message is not
+ * posted to the thread's message queue.
+ */
+ boolean TranslateMessage(MSG lpMsg);
+
+ /**
+ * This function dispatches a message to a window procedure. It is typically
+ * used to dispatch a message retrieved by the GetMessage function.
+ *
+ * @param lpMsg
+ * Pointer to an MSG structure that contains the message.
+ * @return The return value specifies the value returned by the window
+ * procedure. Although its meaning depends on the message being
+ * dispatched, the return value generally is ignored.
+ */
+ LRESULT DispatchMessage(MSG lpMsg);
+
+ /**
+ * This function places a message in the message queue associated with the
+ * thread that created the specified window and then returns without waiting
+ * for the thread to process the message. Messages in a message queue are
+ * retrieved by calls to the GetMessage or PeekMessage function.
+ *
+ * @param hWnd
+ * Handle to the window whose window procedure is to receive the
+ * message.
+ * @param msg
+ * Specifies the message to be posted.
+ * @param wParam
+ * Specifies additional message-specific information.
+ * @param lParam
+ * Specifies additional message-specific information.
+ */
+ void PostMessage(HWND hWnd, int msg, WPARAM wParam, LPARAM lParam);
+
+ /**
+ * This function indicates to Windows that a thread has made a request to
+ * terminate (quit). It is typically used in response to a WM_DESTROY
+ * message.
+ *
+ * @param nExitCode
+ * Specifies an application exit code. This value is used as the
+ * wParam parameter of the WM_QUIT message.
+ */
+ void PostQuitMessage(int nExitCode);
+
+ /**
+ * The GetSystemMetrics function retrieves various system metrics (widths
+ * and heights of display elements) and system configuration settings. All
+ * dimensions retrieved by GetSystemMetrics are in pixels.
+ *
+ * @param nIndex
+ * System metric or configuration setting to retrieve. This
+ * parameter can be one of the following values. Note that all
+ * SM_CX* values are widths and all SM_CY* values are heights.
+ * Also note that all settings designed to return Boolean data
+ * represent TRUE as any nonzero value, and FALSE as a zero
+ * value.
+ * @return If the function succeeds, the return value is the requested
+ * system metric or configuration setting. If the function fails,
+ * the return value is zero. GetLastError does not provide extended
+ * error information.
+ */
+ public int GetSystemMetrics(int nIndex);
+
+ /**
+ * Changes the parent window of the specified child window.
+ *
+ * @param hWndChild
+ * A handle to the child window.
+ *
+ * @param hWndNewParent
+ * A handle to the new parent window. If this parameter is NULL,
+ * the desktop window becomes the new parent window. If this
+ * parameter is HWND_MESSAGE, the child window becomes a
+ * message-only window.
+ *
+ * @return If the function succeeds, the return value is nonzero.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call GetLastError.
+ */
+ HWND SetParent(HWND hWndChild, HWND hWndNewParent);
+
+ /**
+ * Determines the visibility state of the specified window.
+ *
+ * @param hWnd
+ * A handle to the window to be tested.
+ *
+ * @return If the specified window, its parent window, its parent's parent
+ * window, and so forth, have the WS_VISIBLE style, the return value
+ * is nonzero. Otherwise, the return value is zero.
+ *
+ * Because the return value specifies whether the window has the
+ * WS_VISIBLE style, it may be nonzero even if the window is totally
+ * obscured by other windows.
+ */
+ boolean IsWindowVisible(HWND hWnd);
+
+ /**
+ * Changes the position and dimensions of the specified window. For a
+ * top-level window, the position and dimensions are relative to the
+ * upper-left corner of the screen. For a child window, they are relative to
+ * the upper-left corner of the parent window's client area.
+ *
+ * @param hWnd
+ * A handle to the window.
+ *
+ * @param X
+ * The new position of the left side of the window.
+ *
+ * @param Y
+ * The new position of the top of the window.
+ *
+ * @param nWidth
+ * The new width of the window.
+ *
+ * @param nHeight
+ * The new height of the window.
+ *
+ * @param bRepaint
+ * Indicates whether the window is to be repainted. If this
+ * parameter is TRUE, the window receives a message. If the
+ * parameter is FALSE, no repainting of any kind occurs. This
+ * applies to the client area, the nonclient area (including the
+ * title bar and scroll bars), and any part of the parent window
+ * uncovered as a result of moving a child window.
+ *
+ * @return If the function succeeds, the return value is nonzero.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call GetLastError.
+ */
+ boolean MoveWindow(HWND hWnd, int X, int Y, int nWidth, int nHeight,
+ boolean bRepaint);
+
+ /**
+ * Changes the size, position, and Z order of a child, pop-up, or top-level
+ * window. These windows are ordered according to their appearance on the
+ * screen. The topmost window receives the highest rank and is the first
+ * window in the Z order.
+ *
+ * @param hWnd
+ * A handle to the window.
+ *
+ * @param hWndInsertAfter
+ * A handle to the window to precede the positioned window in the
+ * Z order.
+ *
+ * @param X
+ * The new position of the left side of the window, in client
+ * coordinates.
+ *
+ * @param Y
+ * The new position of the top of the window, in client
+ * coordinates.
+ *
+ * @param cx
+ * The new width of the window, in pixels.
+ *
+ * @param cy
+ * The new height of the window, in pixels.
+ *
+ * @param uFlags
+ * The window sizing and positioning flags.
+ *
+ * @return If the function succeeds, the return value is nonzero.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call GetLastError.
+ */
+ boolean SetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx,
+ int cy, int uFlags);
+
+ /**
+ * Attaches or detaches the input processing mechanism of one thread to that
+ * of another thread.
+ *
+ * @param idAttach
+ * The identifier of the thread to be attached to another thread.
+ * The thread to be attached cannot be a system thread.
+ *
+ * @param idAttachTo
+ * The identifier of the thread to which idAttach will be
+ * attached. This thread cannot be a system thread. A thread
+ * cannot attach to itself. Therefore, idAttachTo cannot equal
+ * idAttach.
+ *
+ * @param fAttach
+ * If this parameter is TRUE, the two threads are attached. If
+ * the parameter is FALSE, the threads are detached.
+ *
+ * @return If the function succeeds, the return value is nonzero.
+ */
+ boolean AttachThreadInput(DWORD idAttach, DWORD idAttachTo, boolean fAttach);
+
+ /**
+ * Brings the thread that created the specified window into the foreground
+ * and activates the window. Keyboard input is directed to the window, and
+ * various visual cues are changed for the user. The system assigns a
+ * slightly higher priority to the thread that created the foreground window
+ * than it does to other threads.
+ *
+ * @param hWnd
+ * A handle to the window that should be activated and brought to
+ * the foreground.
+ *
+ * @return If the window was brought to the foreground, the return value is
+ * nonzero.
+ */
+ boolean SetForegroundWindow(HWND hWnd);
+
+ /**
+ * Retrieves a handle to the foreground window (the window with which the
+ * user is currently working). The system assigns a slightly higher priority
+ * to the thread that creates the foreground window than it does to other
+ * threads.
+ *
+ * @return The return value is a handle to the foreground window. The
+ * foreground window can be NULL in certain circumstances, such as
+ * when a window is losing activation.
+ */
+ HWND GetForegroundWindow();
+
+ /**
+ * Sets the keyboard focus to the specified window. The window must be
+ * attached to the calling thread's message queue.
+ *
+ * @param hWnd
+ * A handle to the window that will receive the keyboard input.
+ * If this parameter is NULL, keystrokes are ignored.
+ *
+ * @return If the function succeeds, the return value is the handle to the
+ * window that previously had the keyboard focus. If the hWnd
+ * parameter is invalid or the window is not attached to the calling
+ * thread's message queue, the return value is NULL. To get extended
+ * error information, call GetLastError.
+ */
+ HWND SetFocus(HWND hWnd);
+
+ /**
+ * Synthesizes keystrokes, mouse motions, and button clicks.
+ *
+ * @param nInputs
+ * The number of structures in the pInputs array.
+ *
+ * @param pInputs
+ * An array of INPUT structures. Each structure represents an
+ * event to be inserted into the keyboard or mouse input stream.
+ *
+ * @param cbSize
+ * The size, in bytes, of an INPUT structure. If cbSize is not
+ * the size of an INPUT structure, the function fails.
+ *
+ * @return The function returns the number of events that it successfully
+ * inserted into the keyboard or mouse input stream. If the function
+ * returns zero, the input was already blocked by another thread. To
+ * get extended error information, call GetLastError.
+ *
+ * This function fails when it is blocked by UIPI. Note that neither
+ * GetLastError nor the return value will indicate the failure was
+ * caused by UIPI blocking.
+ */
+ DWORD SendInput(DWORD nInputs, WinUser.INPUT[] pInputs, int cbSize);
+
+ /**
+ * Waits until the specified process has finished processing its initial
+ * input and is waiting for user input with no input pending, or until the
+ * time-out interval has elapsed.
+ *
+ * @param hProcess
+ * A handle to the process. If this process is a console
+ * application or does not have a message queue, WaitForInputIdle
+ * returns immediately.
+ *
+ * @param dwMilliseconds
+ * The time-out interval, in milliseconds. If dwMilliseconds is
+ * INFINITE, the function does not return until the process is
+ * idle.
+ *
+ * @return The following table shows the possible return values for this
+ * function.
+ *
+ *
+ * Return code/value |
+ * Description |
+ *
+ *
+ * 0 |
+ * The wait was satisfied successfully. |
+ *
+ *
+ * WAIT_TIMEOUT |
+ * The wait was terminated because the time-out interval
+ * elapsed. |
+ *
+ *
+ * WAIT_FAILED |
+ * An error occurred. |
+ *
+ *
+ */
+ DWORD WaitForInputIdle(HANDLE hProcess, DWORD dwMilliseconds);
+
+ /**
+ * The InvalidateRect function adds a rectangle to the specified window's
+ * update region. The update region represents the portion of the window's
+ * client area that must be redrawn.
+ *
+ * @param hWnd
+ * A handle to the window whose update region has changed. If
+ * this parameter is NULL, the system invalidates and redraws all
+ * windows, not just the windows for this application, and sends
+ * the WM_ERASEBKGND and WM_NCPAINT messages before the function
+ * returns. Setting this parameter to NULL is not recommended.
+ *
+ * @param lpRect
+ * A pointer to a RECT structure that contains the client
+ * coordinates of the rectangle to be added to the update region.
+ * If this parameter is NULL, the entire client area is added to
+ * the update region.
+ *
+ * @param bErase
+ * Specifies whether the background within the update region is
+ * to be erased when the update region is processed. If this
+ * parameter is TRUE, the background is erased when the
+ * BeginPaint function is called. If this parameter is FALSE, the
+ * background remains unchanged.
+ *
+ * @return If the function succeeds, the return value is nonzero. If the
+ * function fails, the return value is zero.
+ */
+ boolean InvalidateRect(HWND hWnd, RECT.ByReference lpRect, boolean bErase);
+
+ /**
+ * The RedrawWindow function updates the specified rectangle or region in a
+ * window's client area.
+ *
+ * @param hWnd
+ * A handle to the window to be redrawn. If this parameter is
+ * NULL, the desktop window is updated.
+ *
+ * @param lprcUpdate
+ * A pointer to a RECT structure containing the coordinates, in
+ * device units, of the update rectangle. This parameter is
+ * ignored if the hrgnUpdate parameter identifies a region.
+ *
+ * @param hrgnUpdate
+ * A handle to the update region. If both the hrgnUpdate and
+ * lprcUpdate parameters are NULL, the entire client area is
+ * added to the update region.
+ *
+ * @param flags
+ * One or more redraw flags. This parameter can be used to
+ * invalidate or validate a window, control repainting, and
+ * control which windows are affected by RedrawWindow.
+ *
+ * @return If the function succeeds, the return value is nonzero. If the
+ * function fails, the return value is zero.
+ */
+ boolean RedrawWindow(HWND hWnd, RECT.ByReference lprcUpdate,
+ HRGN hrgnUpdate, DWORD flags);
+
+ /**
+ * Retrieves a handle to a window that has the specified relationship
+ * (Z-Order or owner) to the specified window.
+ *
+ * @param hWnd
+ * A handle to a window. The window handle retrieved is relative
+ * to this window, based on the value of the uCmd parameter.
+ *
+ * @param uCmd
+ * The relationship between the specified window and the window
+ * whose handle is to be retrieved.
+ *
+ * @return If the function succeeds, the return value is a window handle. If
+ * no window exists with the specified relationship to the specified
+ * window, the return value is NULL. To get extended error
+ * information, call GetLastError.
+ */
+ HWND GetWindow(HWND hWnd, DWORD uCmd);
+
+ /**
+ * The UpdateWindow function updates the client area of the specified window
+ * by sending a WM_PAINT message to the window if the window's update region
+ * is not empty. The function sends a WM_PAINT message directly to the
+ * window procedure of the specified window, bypassing the application
+ * queue. If the update region is empty, no message is sent.
+ *
+ * @param hWnd
+ * Handle to the window to be updated.
+ *
+ * @return If the function succeeds, the return value is nonzero. If the
+ * function fails, the return value is zero.
+ */
+ boolean UpdateWindow(HWND hWnd);
+
+ /**
+ * Sets the specified window's show state.
+ *
+ * @param hWnd
+ * A handle to the window.
+ *
+ * @param nCmdShow
+ * Controls how the window is to be shown. This parameter is
+ * ignored the first time an application calls ShowWindow, if the
+ * program that launched the application provides a STARTUPINFO
+ * structure. Otherwise, the first time ShowWindow is called, the
+ * value should be the value obtained by the WinMain function in
+ * its nCmdShow parameter.
+ *
+ * @return If the function succeeds, the return value is nonzero.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call GetLastError.
+ */
+ boolean ShowWindow(HWND hWnd, int nCmdShow);
+
+ /**
+ * Minimizes (but does not destroy) the specified window.
+ *
+ * @param hWnd
+ * A handle to the window to be minimized.
+ *
+ * @return If the function succeeds, the return value is nonzero.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call GetLastError.
+ */
+ boolean CloseWindow(HWND hWnd);
+
+ /**
+ * Defines a system-wide hot key.
+ *
+ * @param hWnd
+ * A handle to the window that will receive
+ * @param id
+ * The identifier of the hot key
+ * @param fsModifiers
+ * The keys that must be pressed in combination with the key
+ * specified by the uVirtKey parameter in order to generate the
+ * @param vk
+ * The virtual-key code of the hot key
+ * @return If the function succeeds, the return value is nonzero.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call {@link Kernel32#GetLastError}.
+ * {@link WinUser#WM_HOTKEY} messages generated by the hot key
+ * {@link WinUser#WM_HOTKEY} message.
+ * A combination of the following values
+ *
+ * - {@link WinUser#MOD_ALT} Either ALT key must be held down.
+ * - {@link WinUser#MOD_CONTROL} Either CTRL key must be held
+ * down.
+ * - {@link WinUser#MOD_NOREPEAT} Changes the hotkey behavior so
+ * that the keyboard auto-repeat does not yield multiple hotkey
+ * notifications.
+ * Windows Vista and Windows XP/2000: This flag is not
+ * supported.
+ * - {@link WinUser#MOD_SHIFT} Either SHIFT key must be held down.
+ *
+ * - {@link WinUser#MOD_WIN} Either WINDOWS key was held down.
+ * These keys are labeled with the Windows logo.
+ *
+ */
+ boolean RegisterHotKey(HWND hWnd, int id, int fsModifiers, int vk);
+
+ /**
+ * Frees a hot key previously registered by the calling thread.
+ *
+ * @param hWnd
+ * A handle to the window associated with the hot key to be
+ * freed. This parameter should be NULL if the hot key is not
+ * associated with a window.
+ *
+ * @param id
+ * The identifier of the hot key to be freed.
+ *
+ * @return If the function succeeds, the return value is nonzero.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call {@link Kernel32#GetLastError}.
+ */
+ boolean UnregisterHotKey(Pointer hWnd, int id);
+
+ /**
+ * Retrieves the time of the last input event.
+ *
+ * @param plii
+ * structure that receives the time of the last input event
+ * @return If the function succeeds, the return value is nonzero.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call {@link Kernel32#GetLastError}.
+ */
+ boolean GetLastInputInfo(LASTINPUTINFO plii);
+
+ /**
+ * Registers a window class for subsequent use in calls to the CreateWindow
+ * or CreateWindowEx function.
+ *
+ * @param lpwcx
+ * Type: const WNDCLASSEX* A pointer to a WNDCLASSEX structure.
+ * You must fill the structure with the appropriate class
+ * attributes before passing it to the function.
+ *
+ * @return If the function succeeds, the return value is a class atom that
+ * uniquely identifies the class being registered. This atom can
+ * only be used by the CreateWindow, CreateWindowEx, GetClassInfo,
+ * GetClassInfoEx, FindWindow, FindWindowEx, and UnregisterClass
+ * functions and the IActiveIMMap::FilterClientWindows method.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call {@link Kernel32#GetLastError}.
+ */
+ public ATOM RegisterClassEx(WNDCLASSEX lpwcx);
+
+ /**
+ * Unregisters a window class, freeing the memory required for the class.
+ *
+ * @param lpClassName
+ * [in] Type: LPCTSTR
+ *
+ * A null-terminated string or a class atom. If lpClassName is a
+ * string, it specifies the window class name. This class name
+ * must have been registered by a previous call to the
+ * RegisterClass or RegisterClassEx function. System classes,
+ * such as dialog box controls, cannot be unregistered. If this
+ * parameter is an atom, it must be a class atom created by a
+ * previous call to the RegisterClass or RegisterClassEx
+ * function. The atom must be in the low-order word of
+ * lpClassName; the high-order word must be zero.
+ *
+ * @param hInstance
+ * [in,optional] Type: HINSTANCE A handle to the instance of the
+ * module that created the class. *
+ *
+ * @return Type: BOOL If the function succeeds, the return value is nonzero.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call {@link Kernel32#GetLastError}.
+ */
+ public boolean UnregisterClass(WString lpClassName, HINSTANCE hInstance);
+
+ /**
+ * Creates an overlapped, pop-up, or child window with an extended window
+ * style; otherwise, this function is identical to the CreateWindow
+ * function. For more information about creating a window and for full
+ * descriptions of the other parameters of CreateWindowEx, see CreateWindow.
+ *
+ * @param dwExStyle
+ * [in] Type: DWORD
+ *
+ * The extended window style of the window being created. For a
+ * list of possible values,see Extended Window Styles.
+ *
+ * @param lpClassName
+ * [in, optional] Type: LPCTSTR
+ *
+ * A null-terminated string or a class atom created by a previous
+ * call to the RegisterClass or RegisterClassEx function. The
+ * atom must be in the low-order word of lpClassName; the
+ * high-order word must be zero. If lpClassName is a string, it
+ * specifies the window class name. The class name can be any
+ * name registered with RegisterClass or RegisterClassEx,
+ * provided that the module that registers the class is also the
+ * module that creates the window. The class name can also be any
+ * of the predefined system class names.
+ *
+ * @param lpWindowName
+ * [in, optional] Type: LPCTSTR
+ *
+ * The window name. If the window style specifies a title bar,
+ * the window title pointed to by lpWindowName is displayed in
+ * the title bar. When using CreateWindow to create controls,
+ * such as buttons, check boxes, and static controls, use
+ * lpWindowName to specify the text of the control. When creating
+ * a static control with the SS_ICON style, use lpWindowName to
+ * specify the icon name or identifier. To specify an identifier,
+ * use the syntax "#num".
+ *
+ * @param dwStyle
+ * [in] Type: DWORD
+ *
+ * The style of the window being created. This parameter can be a
+ * combination of the window style values, plus the control
+ * styles indicated in the Remarks section.
+ *
+ * @param x
+ * [in] Type: int
+ *
+ * The initial horizontal position of the window. For an
+ * overlapped or pop-up window, the x parameter is the initial
+ * x-coordinate of the window's upper-left corner, in screen
+ * coordinates. For a child window, x is the x-coordinate of the
+ * upper-left corner of the window relative to the upper-left
+ * corner of the parent window's client area. If x is set to
+ * CW_USEDEFAULT, the system selects the default position for the
+ * window's upper-left corner and ignores the y parameter.
+ * CW_USEDEFAULT is valid only for overlapped windows; if it is
+ * specified for a pop-up or child window, the x and y parameters
+ * are set to zero.
+ *
+ * @param y
+ * [in] Type: int
+ *
+ * The initial vertical position of the window. For an overlapped
+ * or pop-up window, the y parameter is the initial y-coordinate
+ * of the window's upper-left corner, in screen coordinates. For
+ * a child window, y is the initial y-coordinate of the
+ * upper-left corner of the child window relative to the
+ * upper-left corner of the parent window's client area. For a
+ * list box y is the initial y-coordinate of the upper-left
+ * corner of the list box's client area relative to the
+ * upper-left corner of the parent window's client area.
+ *
+ * If an overlapped window is created with the WS_VISIBLE style
+ * bit set and the x parameter is set to CW_USEDEFAULT, then the
+ * y parameter determines how the window is shown. If the y
+ * parameter is CW_USEDEFAULT, then the window manager calls
+ * ShowWindow with the SW_SHOW flag after the window has been
+ * created. If the y parameter is some other value, then the
+ * window manager calls ShowWindow with that value as the
+ * nCmdShow parameter.
+ *
+ * @param nWidth
+ * [in] Type: int
+ *
+ * The width, in device units, of the window. For overlapped
+ * windows, nWidth is the window's width, in screen coordinates,
+ * or CW_USEDEFAULT. If nWidth is CW_USEDEFAULT, the system
+ * selects a default width and height for the window; the default
+ * width extends from the initial x-coordinates to the right edge
+ * of the screen; the default height extends from the initial
+ * y-coordinate to the top of the icon area. CW_USEDEFAULT is
+ * valid only for overlapped windows; if CW_USEDEFAULT is
+ * specified for a pop-up or child window, the nWidth and nHeight
+ * parameter are set to zero.
+ *
+ * @param nHeight
+ * [in] Type: int
+ *
+ * The height, in device units, of the window. For overlapped
+ * windows, nHeight is the window's height, in screen
+ * coordinates. If the nWidth parameter is set to CW_USEDEFAULT,
+ * the system ignores nHeight.
+ *
+ * @param hWndParent
+ * [in, optional] Type: HWND
+ *
+ * A handle to the parent or owner window of the window being
+ * created. To create a child window or an owned window, supply a
+ * valid window handle. This parameter is optional for pop-up
+ * windows.
+ *
+ * To create a message-only window, supply HWND_MESSAGE or a
+ * handle to an existing message-only window.
+ *
+ * @param hMenu
+ * [in, optional] Type: HMENU
+ *
+ * A handle to a menu, or specifies a child-window identifier,
+ * depending on the window style. For an overlapped or pop-up
+ * window, hMenu identifies the menu to be used with the window;
+ * it can be NULL if the class menu is to be used. For a child
+ * window, hMenu specifies the child-window identifier, an
+ * integer value used by a dialog box control to notify its
+ * parent about events. The application determines the
+ * child-window identifier; it must be unique for all child
+ * windows with the same parent window.
+ *
+ * @param hInstance
+ * [in, optional] Type: HINSTANCE
+ *
+ * A handle to the instance of the module to be associated with
+ * the window.
+ *
+ * @param lpParam
+ * [in, optional] Type: LPVOID
+ *
+ * Pointer to a value to be passed to the window through the
+ * CREATESTRUCT structure (lpCreateParams member) pointed to by
+ * the lParam param of the WM_CREATE message. This message is
+ * sent to the created window by this function before it returns.
+ *
+ * If an application calls CreateWindow to create a MDI client
+ * window, lpParam should point to a CLIENTCREATESTRUCT
+ * structure. If an MDI client window calls CreateWindow to
+ * create an MDI child window, lpParam should point to a
+ * MDICREATESTRUCT structure. lpParam may be NULL if no
+ * additional data is needed.
+ *
+ * @return Type: HWND
+ *
+ * If the function succeeds, the return value is a handle to the new
+ * window.
+ *
+ * If the function fails, the return value is NULL. To get extended
+ * error information, call GetLastError.
+ *
+ * This function typically fails for one of the following reasons:
+ * - an invalid parameter value
+ * - the system class was registered by a different module
+ * - The WH_CBT hook is installed and returns a failure code
+ * - if one of the controls in the dialog template is not registered,
+ * or its window window procedure fails WM_CREATE or WM_NCCREATE
+ */
+ public HWND CreateWindowEx(int dwExStyle, WString lpClassName,
+ String lpWindowName, int dwStyle, int x, int y, int nWidth,
+ int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance,
+ LPVOID lpParam);
+
+ /**
+ * Destroys the specified window. The function sends WM_DESTROY and
+ * WM_NCDESTROY messages to the window to deactivate it and remove the
+ * keyboard focus from it. The function also destroys the window's menu,
+ * flushes the thread message queue, destroys timers, removes clipboard
+ * ownership, and breaks the clipboard viewer chain (if the window is at the
+ * top of the viewer chain).
+ *
+ * If the specified window is a parent or owner window, DestroyWindow
+ * automatically destroys the associated child or owned windows when it
+ * destroys the parent or owner window. The function first destroys child or
+ * owned windows, and then it destroys the parent or owner window.
+ *
+ * DestroyWindow also destroys modeless dialog boxes created by the
+ * CreateDialog function.
+ *
+ * @param hWnd
+ * [in] Type: HWND A handle to the window to be destroyed.
+ *
+ * @return Type: BOOL If the function succeeds, the return value is nonzero.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call {@link Kernel32#GetLastError}.
+ */
+ public boolean DestroyWindow(HWND hWnd);
+
+ /**
+ * Retrieves information about a window class, including a handle to the
+ * small icon associated with the window class. The GetClassInfo function
+ * does not retrieve a handle to the small icon.
+ *
+ * @param hinst
+ * [in, optional] Type: HINSTANCE
+ *
+ * A handle to the instance of the application that created the
+ * class. To retrieve information about classes defined by the
+ * system (such as buttons or list boxes), set this parameter to
+ * NULL.
+ *
+ * @param lpszClass
+ * [in] Type: LPCTSTR
+ *
+ * The class name. The name must be that of a preregistered class
+ * or a class registered by a previous call to the RegisterClass
+ * or RegisterClassEx function. Alternatively, this parameter can
+ * be a class atom created by a previous call to RegisterClass or
+ * RegisterClassEx. The atom must be in the low-order word of
+ * lpszClass; the high-order word must be zero.
+ *
+ * @param lpwcx
+ * [out] Type: LPWNDCLASSEX
+ *
+ * A pointer to a WNDCLASSEX structure that receives the
+ * information about the class.
+ *
+ * @return Type: BOOL If the function finds a matching class and
+ * successfully copies the data, the return value is nonzero.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call {@link Kernel32#GetLastError} .
+ */
+ public boolean GetClassInfoEx(HINSTANCE hinst, WString lpszClass,
+ WNDCLASSEX lpwcx);
+
+ /**
+ * Calls the default window procedure to provide default processing for any
+ * window messages that an application does not process. This function
+ * ensures that every message is processed. DefWindowProc is called with the
+ * same parameters received by the window procedure.
+ *
+ * @param hWnd
+ * [in] Type: HWND
+ *
+ * A handle to the window procedure that received the message.
+ *
+ * @param Msg
+ * [in] Type: UINT
+ *
+ * The message.
+ *
+ * @param wParam
+ * [in] Type: WPARAM
+ *
+ * Additional message information. The content of this parameter
+ * depends on the value of the Msg parameter.
+ *
+ * @param lParam
+ * [in] Type: LPARAM
+ *
+ * Additional message information. The content of this parameter
+ * depends on the value of the Msg parameter.
+ *
+ * @return Type: LRESULT The return value is the result of the message
+ * processing and depends on the message.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call {@link Kernel32#GetLastError}.
+ */
+ public LRESULT DefWindowProc(HWND hWnd, int Msg, WPARAM wParam,
+ LPARAM lParam);
+
+ /**
+ * Registers the device or type of device for which a window will receive
+ * notifications.
+ *
+ * @hRecipient [in] A handle to the window or service that will receive
+ * device events for the devices specified in the
+ * NotificationFilter parameter. The same window handle can be
+ * used in multiple calls to RegisterDeviceNotification.
+ *
+ * Services can specify either a window handle or service status
+ * handle.
+ *
+ * @param NotificationFilter
+ * [in] A pointer to a block of data that specifies the type of
+ * device for which notifications should be sent. This block
+ * always begins with the DEV_BROADCAST_HDR structure. The data
+ * following this header is dependent on the value of the
+ * dbch_devicetype member, which can be
+ * DBT_DEVTYP_DEVICEINTERFACE or DBT_DEVTYP_HANDLE. For more
+ * information, see Remarks.
+ *
+ * @param Flags
+ * [in] This parameter can be one of the following values.
+ * DEVICE_NOTIFY_WINDOW_HANDLE0x00000000 The hRecipient parameter
+ * is a window handle.
+ *
+ * DEVICE_NOTIFY_SERVICE_HANDLE0x00000001 The hRecipient
+ * parameter is a service status handle.
+ *
+ * In addition, you can specify the following value.
+ *
+ * DEVICE_NOTIFY_ALL_INTERFACE_CLASSES0x00000004 Notifies the
+ * recipient of device interface events for all device interface
+ * classes. (The dbcc_classguid member is ignored.)
+ *
+ * This value can be used only if the dbch_devicetype member is
+ * DBT_DEVTYP_DEVICEINTERFACE.
+ *
+ * @return value
+ *
+ * If the function succeeds, the return value is a device
+ * notification handle.
+ *
+ * If the function fails, the return value is NULL. To get extended
+ * error information, call GetLastError.
+ */
+ HDEVNOTIFY RegisterDeviceNotification(HANDLE hRecipient,
+ Structure notificationFilter, int Flags);
+
+ /**
+ * Closes the specified device notification handle.
+ *
+ * @Handle [in] Device notification handle returned by the
+ * RegisterDeviceNotification function.
+ *
+ * @return Return value
+ *
+ * If the function succeeds, the return value is nonzero.
+ *
+ * If the function fails, the return value is zero. To get extended
+ * error information, call GetLastError.
+ */
+ boolean UnregisterDeviceNotification(HDEVNOTIFY Handle);
+}
diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinGDI.java b/contrib/platform/src/com/sun/jna/platform/win32/WinGDI.java
index 1c31ae2afd..c8bc6dffb6 100644
--- a/contrib/platform/src/com/sun/jna/platform/win32/WinGDI.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/WinGDI.java
@@ -1,118 +1,121 @@
-/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package com.sun.jna.platform.win32;
-
-import java.util.Arrays;
-import java.util.List;
-
-import com.sun.jna.Structure;
-import com.sun.jna.platform.win32.WinDef.RECT;
-import com.sun.jna.win32.StdCallLibrary;
-
-/**
- * Ported from WinGDI.h.
- * Microsoft Windows SDK 6.0A.
- * @author dblock[at]dblock.org
- */
-public interface WinGDI extends StdCallLibrary {
- public int RDH_RECTANGLES = 1;
-
- public class RGNDATAHEADER extends Structure {
- public int dwSize = size();
- public int iType = RDH_RECTANGLES; // required
- public int nCount;
- public int nRgnSize;
- public RECT rcBound;
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "dwSize", "iType", "nCount", "nRgnSize", "rcBound" });
- }
- }
-
- public class RGNDATA extends Structure {
- public RGNDATAHEADER rdh;
- public byte[] Buffer;
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "rdh", "Buffer" });
- }
-
- public RGNDATA(int bufferSize) {
- Buffer = new byte[bufferSize];
- allocateMemory();
- }
- }
-
- public int RGN_AND = 1;
- public int RGN_OR = 2;
- public int RGN_XOR = 3;
- public int RGN_DIFF = 4;
- public int RGN_COPY = 5;
-
- public int ERROR = 0;
- public int NULLREGION = 1;
- public int SIMPLEREGION = 2;
- public int COMPLEXREGION = 3;
-
- public int ALTERNATE = 1;
- public int WINDING = 2;
-
- public int BI_RGB = 0;
- public int BI_RLE8 = 1;
- public int BI_RLE4 = 2;
- public int BI_BITFIELDS = 3;
- public int BI_JPEG = 4;
- public int BI_PNG = 5;
-
- public class BITMAPINFOHEADER extends Structure {
- public int biSize = size();
- public int biWidth;
- public int biHeight;
- public short biPlanes;
- public short biBitCount;
- public int biCompression;
- public int biSizeImage;
- public int biXPelsPerMeter;
- public int biYPelsPerMeter;
- public int biClrUsed;
- public int biClrImportant;
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "biSize", "biWidth", "biHeight", "biPlanes", "biBitCount", "biCompression", "biSizeImage", "biXPelsPerMeter", "biYPelsPerMeter", "biClrUsed", "biClrImportant" });
- }
- }
-
- public class RGBQUAD extends Structure {
- public byte rgbBlue;
- public byte rgbGreen;
- public byte rgbRed;
- public byte rgbReserved = 0;
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "rgbBlue", "rgbGreen", "rgbRed", "rgbReserved" });
- }
- }
-
- public class BITMAPINFO extends Structure {
- public BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
- public RGBQUAD[] bmiColors = new RGBQUAD[1];
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "bmiHeader", "bmiColors" });
- }
- public BITMAPINFO() { this(1); }
- public BITMAPINFO(int size) {
- bmiColors = new RGBQUAD[size];
- }
- }
-
- public int DIB_RGB_COLORS = 0;
- public int DIB_PAL_COLORS = 1;
-}
\ No newline at end of file
+/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package com.sun.jna.platform.win32;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.sun.jna.Structure;
+import com.sun.jna.platform.win32.WinDef.RECT;
+import com.sun.jna.win32.StdCallLibrary;
+
+/**
+ * Ported from WinGDI.h.
+ * Microsoft Windows SDK 6.0A.
+ * @author dblock[at]dblock.org
+ */
+public interface WinGDI extends StdCallLibrary {
+ public int RDH_RECTANGLES = 1;
+
+ public class RGNDATAHEADER extends Structure {
+ public int dwSize = size();
+ public int iType = RDH_RECTANGLES; // required
+ public int nCount;
+ public int nRgnSize;
+ public RECT rcBound;
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "dwSize", "iType", "nCount", "nRgnSize", "rcBound" });
+ }
+ }
+
+ public class RGNDATA extends Structure {
+ public RGNDATAHEADER rdh;
+ public byte[] Buffer;
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "rdh", "Buffer" });
+ }
+
+ public RGNDATA() {
+ this(1);
+ }
+ public RGNDATA(int bufferSize) {
+ Buffer = new byte[bufferSize];
+ allocateMemory();
+ }
+ }
+
+ public int RGN_AND = 1;
+ public int RGN_OR = 2;
+ public int RGN_XOR = 3;
+ public int RGN_DIFF = 4;
+ public int RGN_COPY = 5;
+
+ public int ERROR = 0;
+ public int NULLREGION = 1;
+ public int SIMPLEREGION = 2;
+ public int COMPLEXREGION = 3;
+
+ public int ALTERNATE = 1;
+ public int WINDING = 2;
+
+ public int BI_RGB = 0;
+ public int BI_RLE8 = 1;
+ public int BI_RLE4 = 2;
+ public int BI_BITFIELDS = 3;
+ public int BI_JPEG = 4;
+ public int BI_PNG = 5;
+
+ public class BITMAPINFOHEADER extends Structure {
+ public int biSize = size();
+ public int biWidth;
+ public int biHeight;
+ public short biPlanes;
+ public short biBitCount;
+ public int biCompression;
+ public int biSizeImage;
+ public int biXPelsPerMeter;
+ public int biYPelsPerMeter;
+ public int biClrUsed;
+ public int biClrImportant;
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "biSize", "biWidth", "biHeight", "biPlanes", "biBitCount", "biCompression", "biSizeImage", "biXPelsPerMeter", "biYPelsPerMeter", "biClrUsed", "biClrImportant" });
+ }
+ }
+
+ public class RGBQUAD extends Structure {
+ public byte rgbBlue;
+ public byte rgbGreen;
+ public byte rgbRed;
+ public byte rgbReserved = 0;
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "rgbBlue", "rgbGreen", "rgbRed", "rgbReserved" });
+ }
+ }
+
+ public class BITMAPINFO extends Structure {
+ public BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
+ public RGBQUAD[] bmiColors = new RGBQUAD[1];
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "bmiHeader", "bmiColors" });
+ }
+ public BITMAPINFO() { this(1); }
+ public BITMAPINFO(int size) {
+ bmiColors = new RGBQUAD[size];
+ }
+ }
+
+ public int DIB_RGB_COLORS = 0;
+ public int DIB_PAL_COLORS = 1;
+}
diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java b/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java
index 997d7125d6..4469b38af8 100644
--- a/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java
@@ -1,2157 +1,2175 @@
-/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package com.sun.jna.platform.win32;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import com.sun.jna.FromNativeContext;
-import com.sun.jna.Memory;
-import com.sun.jna.NativeLong;
-import com.sun.jna.Pointer;
-import com.sun.jna.PointerType;
-import com.sun.jna.Structure;
-import com.sun.jna.Union;
-import com.sun.jna.ptr.ByReference;
-
-/**
- * This module defines the 32-Bit Windows types and constants that are defined
- * by NT, but exposed through the Win32 API. Ported from WinNT.h Microsoft
- * Windows SDK 6.0A. Avoid including any NIO Buffer mappings here; put them in a
- * DLL-derived interface (e.g. kernel32, user32, etc) instead.
- *
- * @author dblock[at]dblock.org
- */
-@SuppressWarnings("serial")
-public interface WinNT extends WinError, WinDef, WinBase, BaseTSD {
-
- //
- // The following are masks for the predefined standard access types
- //
-
- int DELETE = 0x00010000;
- int READ_CONTROL = 0x00020000;
- int WRITE_DAC = 0x00040000;
- int WRITE_OWNER = 0x00080000;
- int SYNCHRONIZE = 0x00100000;
-
- int STANDARD_RIGHTS_REQUIRED = 0x000F0000;
- int STANDARD_RIGHTS_READ = READ_CONTROL;
- int STANDARD_RIGHTS_WRITE = READ_CONTROL;
- int STANDARD_RIGHTS_EXECUTE = READ_CONTROL;
- int STANDARD_RIGHTS_ALL = 0x001F0000;
-
- int SPECIFIC_RIGHTS_ALL = 0x0000FFFF;
-
- //
- // Token Specific Access Rights.
- //
-
- /**
- * Required to attach a primary token to a process. The
- * SE_ASSIGNPRIMARYTOKEN_NAME privilege is also required to accomplish this
- * task.
- */
- int TOKEN_ASSIGN_PRIMARY = 0x0001;
-
- /**
- * Required to duplicate an access token.
- */
- int TOKEN_DUPLICATE = 0x0002;
-
- /**
- * Required to attach an impersonation access token to a process.
- */
- int TOKEN_IMPERSONATE = 0x0004;
-
- /**
- * Required to query an access token.
- */
- int TOKEN_QUERY = 0x0008;
-
- /**
- * Required to query the source of an access token.
- */
- int TOKEN_QUERY_SOURCE = 0x0010;
-
- /**
- * Required to enable or disable the privileges in an access token.
- */
- int TOKEN_ADJUST_PRIVILEGES = 0x0020;
-
- /**
- * Required to adjust the attributes of the groups in an access token.
- */
- int TOKEN_ADJUST_GROUPS = 0x0040;
-
- /**
- * Required to change the default owner, primary group, or DACL of an access
- * token.
- */
- int TOKEN_ADJUST_DEFAULT = 0x0080;
-
- /**
- * Required to adjust the session ID of an access token. The SE_TCB_NAME
- * privilege is required.
- */
- int TOKEN_ADJUST_SESSIONID = 0x0100;
-
- int TOKEN_ALL_ACCESS_P = STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY
- | TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY
- | TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES
- | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT;
-
- /**
- * Combines all possible access rights for a token.
- */
- int TOKEN_ALL_ACCESS = TOKEN_ALL_ACCESS_P | TOKEN_ADJUST_SESSIONID;
-
- /**
- * Combines STANDARD_RIGHTS_READ and TOKEN_QUERY.
- */
- int TOKEN_READ = STANDARD_RIGHTS_READ | TOKEN_QUERY;
-
- /**
- * Combines STANDARD_RIGHTS_WRITE, TOKEN_ADJUST_PRIVILEGES,
- * TOKEN_ADJUST_GROUPS, and TOKEN_ADJUST_DEFAULT.
- */
- int TOKEN_WRITE = STANDARD_RIGHTS_WRITE | TOKEN_ADJUST_PRIVILEGES
- | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT;
-
- /**
- * Combines STANDARD_RIGHTS_EXECUTE and TOKEN_IMPERSONATE.
- */
- int TOKEN_EXECUTE = STANDARD_RIGHTS_EXECUTE;
-
- int THREAD_TERMINATE = 0x0001;
- int THREAD_SUSPEND_RESUME = 0x0002;
- int THREAD_GET_CONTEXT = 0x0008;
- int THREAD_SET_CONTEXT = 0x0010;
- int THREAD_QUERY_INFORMATION = 0x0040;
- int THREAD_SET_INFORMATION = 0x0020;
- int THREAD_SET_THREAD_TOKEN = 0x0080;
- int THREAD_IMPERSONATE = 0x0100;
- int THREAD_DIRECT_IMPERSONATION = 0x0200;
- int THREAD_SET_LIMITED_INFORMATION = 0x0400;
- int THREAD_QUERY_LIMITED_INFORMATION = 0x0800;
- int THREAD_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3FF;
-
- /**
- * The SECURITY_IMPERSONATION_LEVEL enumeration type contains values that
- * specify security impersonation levels. Security impersonation levels
- * govern the degree to which a server process can act on behalf of a client
- * process.
- */
- public abstract class SECURITY_IMPERSONATION_LEVEL {
- /**
- * The server process cannot obtain identification information about the
- * client, and it cannot impersonate the client. It is defined with no
- * value given, and thus, by ANSI C rules, defaults to a value of zero.
- */
- public static final int SecurityAnonymous = 0;
-
- /**
- * The server process can obtain information about the client, such as
- * security identifiers and privileges, but it cannot impersonate the
- * client. This is useful for servers that export their own objects, for
- * example, database products that export tables and views. Using the
- * retrieved client-security information, the server can make
- * access-validation decisions without being able to use other services
- * that are using the client's security context.
- */
- public static final int SecurityIdentification = 1;
-
- /**
- * The server process can impersonate the client's security context on
- * its local system. The server cannot impersonate the client on remote
- * systems.
- */
- public static final int SecurityImpersonation = 2;
-
- /**
- * The server process can impersonate the client's security context on
- * remote systems.
- */
- public static final int SecurityDelegation = 3;
- }
-
- /**
- * The TOKEN_INFORMATION_CLASS enumeration type contains values that specify
- * the type of information being assigned to or retrieved from an access
- * token.
- */
- public abstract class TOKEN_INFORMATION_CLASS {
- public static final int TokenUser = 1;
- public static final int TokenGroups = 2;
- public static final int TokenPrivileges = 3;
- public static final int TokenOwner = 4;
- public static final int TokenPrimaryGroup = 5;
- public static final int TokenDefaultDacl = 6;
- public static final int TokenSource = 7;
- public static final int TokenType = 8;
- public static final int TokenImpersonationLevel = 9;
- public static final int TokenStatistics = 10;
- public static final int TokenRestrictedSids = 11;
- public static final int TokenSessionId = 12;
- public static final int TokenGroupsAndPrivileges = 13;
- public static final int TokenSessionReference = 14;
- public static final int TokenSandBoxInert = 15;
- public static final int TokenAuditPolicy = 16;
- public static final int TokenOrigin = 17;
- public static final int TokenElevationType = 18;
- public static final int TokenLinkedToken = 19;
- public static final int TokenElevation = 20;
- public static final int TokenHasRestrictions = 21;
- public static final int TokenAccessInformation = 22;
- public static final int TokenVirtualizationAllowed = 23;
- public static final int TokenVirtualizationEnabled = 24;
- public static final int TokenIntegrityLevel = 25;
- public static final int TokenUIAccess = 26;
- public static final int TokenMandatoryPolicy = 27;
- public static final int TokenLogonSid = 28;
- }
-
- /**
- * The TOKEN_TYPE enumeration type contains values that differentiate
- * between a primary token and an impersonation token.
- */
- public abstract class TOKEN_TYPE {
- public static final int TokenPrimary = 1;
- public static final int TokenImpersonation = 2;
- }
-
- /**
- * The LUID_AND_ATTRIBUTES structure represents a locally unique identifier
- * (LUID) and its attributes.
- */
- public static class LUID_AND_ATTRIBUTES extends Structure {
- /**
- * Specifies an LUID value.
- */
- public LUID Luid;
-
- /**
- * Specifies attributes of the LUID. This value contains up to 32
- * one-bit flags. Its meaning is dependent on the definition and use of
- * the LUID.
- */
- public DWORD Attributes;
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "Luid", "Attributes" });
- }
-
- public LUID_AND_ATTRIBUTES() {
- }
-
- public LUID_AND_ATTRIBUTES(LUID luid, DWORD attributes) {
- this.Luid = luid;
- this.Attributes = attributes;
- }
- }
-
- /**
- * The SID_AND_ATTRIBUTES structure represents a security identifier (SID)
- * and its attributes. SIDs are used to uniquely identify users or groups.
- */
- public static class SID_AND_ATTRIBUTES extends Structure {
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "Sid", "Attributes" });
- }
-
- public SID_AND_ATTRIBUTES() {
- super();
- }
-
- public SID_AND_ATTRIBUTES(Pointer memory) {
- super(memory);
- }
-
- /**
- * Pointer to a SID structure.
- */
- public PSID.ByReference Sid;
-
- /**
- * Specifies attributes of the SID. This value contains up to 32 one-bit
- * flags. Its meaning depends on the definition and use of the SID.
- */
- public int Attributes;
- }
-
- /**
- * The TOKEN_OWNER structure contains the default owner security identifier
- * (SID) that will be applied to newly created objects.
- */
- public static class TOKEN_OWNER extends Structure {
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "Owner" });
- }
-
- public TOKEN_OWNER() {
- super();
- }
-
- public TOKEN_OWNER(int size) {
- super(new Memory(size));
- }
-
- public TOKEN_OWNER(Pointer memory) {
- super(memory);
- read();
- }
-
- /**
- * Pointer to a SID structure representing a user who will become the
- * owner of any objects created by a process using this access token.
- * The SID must be one of the user or group SIDs already in the token.
- */
- public PSID.ByReference Owner; // PSID
- }
-
- public static class PSID extends Structure {
- public static class ByReference extends PSID implements Structure.ByReference { }
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "sid" });
- }
-
- public PSID() {
- super();
- }
-
- public PSID(byte[] data) {
- super(new Memory(data.length));
- getPointer().write(0, data, 0, data.length);
- read();
- }
-
- public PSID(int size) {
- super(new Memory(size));
- }
-
- public PSID(Pointer memory) {
- super(memory);
- read();
- }
-
- public byte[] getBytes() {
- int len = Advapi32.INSTANCE.GetLengthSid(this);
- return getPointer().getByteArray(0, len);
- }
-
- public Pointer sid;
- }
-
- public static class PSIDByReference extends ByReference {
- public PSIDByReference() {
- this(null);
- }
-
- public PSIDByReference(PSID h) {
- super(Pointer.SIZE);
- setValue(h);
- }
-
- public void setValue(PSID h) {
- getPointer().setPointer(0, h != null ? h.getPointer() : null);
- }
-
- public PSID getValue() {
- Pointer p = getPointer().getPointer(0);
- if (p == null) {
- return null;
- }
- else {
- return new PSID(p);
- }
- }
- }
-
- /**
- * The TOKEN_USER structure identifies the user associated with an access
- * token.
- */
- public static class TOKEN_USER extends Structure {
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "User" });
- }
-
- public TOKEN_USER() {
- super();
- }
-
- public TOKEN_USER(Pointer memory) {
- super(memory);
- read();
- }
-
- public TOKEN_USER(int size) {
- super(new Memory(size));
- }
-
- /**
- * Specifies a SID_AND_ATTRIBUTES structure representing the user
- * associated with the access token. There are currently no attributes
- * defined for user security identifiers (SIDs).
- */
- public SID_AND_ATTRIBUTES User;
- }
-
- /**
- * The TOKEN_GROUPS structure contains information about the group security
- * identifiers (SIDs) in an access token.
- */
- public static class TOKEN_GROUPS extends Structure {
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "GroupCount", "Group0" });
- }
-
- public TOKEN_GROUPS() {
- super();
- }
-
- public TOKEN_GROUPS(Pointer memory) {
- super(memory);
- read();
- }
-
- public TOKEN_GROUPS(int size) {
- super(new Memory(size));
- }
-
- /**
- * Specifies the number of groups in the access token.
- */
- public int GroupCount;
- public SID_AND_ATTRIBUTES Group0;
-
- /**
- * Specifies an array of SID_AND_ATTRIBUTES structures that contain a
- * set of SIDs and corresponding attributes.
- */
- public SID_AND_ATTRIBUTES[] getGroups() {
- return (SID_AND_ATTRIBUTES[]) Group0.toArray(GroupCount);
- }
- }
-
- /**
- * The TOKEN_PRIVILEGES structure contains information about a set of
- * privileges for an access token.
- */
- public static class TOKEN_PRIVILEGES extends Structure {
- /**
- * This must be set to the number of entries in the Privileges array.
- */
- public DWORD PrivilegeCount;
-
- /**
- * Specifies an array of LUID_AND_ATTRIBUTES structures. Each structure
- * contains the LUID and attributes of a privilege.
- */
- public LUID_AND_ATTRIBUTES Privileges[];
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "PrivilegeCount", "Privileges" });
- }
-
- /**
- * @param nbOfPrivileges
- * Desired size of the Privileges array
- */
- public TOKEN_PRIVILEGES(int nbOfPrivileges) {
- PrivilegeCount = new DWORD(nbOfPrivileges);
- Privileges = new LUID_AND_ATTRIBUTES[nbOfPrivileges];
- }
- }
-
- /**
- * The SID_NAME_USE enumeration type contains values that specify the type
- * of a security identifier (SID).
- */
- public abstract class SID_NAME_USE {
- /**
- * Indicates a user SID.
- */
- public static final int SidTypeUser = 1;
-
- /**
- * Indicates a group SID.
- */
- public static final int SidTypeGroup = 2;
-
- /**
- * Indicates a domain SID.
- */
- public static final int SidTypeDomain = 3;
-
- /**
- * Indicates an alias SID.
- */
- public static final int SidTypeAlias = 4;
-
- /**
- * Indicates a SID for a well-known group.
- */
- public static final int SidTypeWellKnownGroup = 5;
-
- /**
- * Indicates a SID for a deleted account.
- */
- public static final int SidTypeDeletedAccount = 6;
-
- /**
- * Indicates an invalid SID.
- */
- public static final int SidTypeInvalid = 7;
-
- /**
- * Indicates an unknown SID type.
- */
- public static final int SidTypeUnknown = 8;
-
- /**
- * Indicates a SID for a computer.
- */
- public static final int SidTypeComputer = 9;
-
- /**
- * ?
- */
- public static final int SidTypeLabel = 10;
- }
-
- /* File access rights */
- int FILE_READ_DATA = 0x00000001;
- int FILE_LIST_DIRECTORY = 0x00000001;
- int FILE_WRITE_DATA = 0x00000002;
- int FILE_ADD_FILE = 0x00000002;
- int FILE_APPEND_DATA = 0x00000004;
- int FILE_ADD_SUBDIRECTORY = 0x00000004;
- int FILE_CREATE_PIPE_INSTANCE = 0x00000004;
- int FILE_READ_EA = 0x00000008;
- int FILE_WRITE_EA = 0x00000010;
- int FILE_EXECUTE = 0x00000020;
- int FILE_TRAVERSE = 0x00000020;
- int FILE_DELETE_CHILD = 0x00000040;
- int FILE_READ_ATTRIBUTES = 0x00000080;
- int FILE_WRITE_ATTRIBUTES = 0x00000100;
-
- int FILE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x000001FF;
-
- int FILE_GENERIC_READ = STANDARD_RIGHTS_READ | SYNCHRONIZE | FILE_READ_DATA
- | FILE_READ_ATTRIBUTES | FILE_READ_EA;
-
- int FILE_GENERIC_WRITE = STANDARD_RIGHTS_WRITE | SYNCHRONIZE
- | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA
- | FILE_APPEND_DATA;
-
- int FILE_GENERIC_EXECUTE = STANDARD_RIGHTS_EXECUTE | SYNCHRONIZE
- | FILE_READ_ATTRIBUTES | FILE_EXECUTE;
-
- int CREATE_NEW = 1;
- int CREATE_ALWAYS = 2;
- int OPEN_EXISTING = 3;
- int OPEN_ALWAYS = 4;
- int TRUNCATE_EXISTING = 5;
-
- int FILE_FLAG_WRITE_THROUGH = 0x80000000;
- int FILE_FLAG_OVERLAPPED = 0x40000000;
- int FILE_FLAG_NO_BUFFERING = 0x20000000;
- int FILE_FLAG_RANDOM_ACCESS = 0x10000000;
- int FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;
- int FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
- int FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
- int FILE_FLAG_POSIX_SEMANTICS = 0x01000000;
- int FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000;
- int FILE_FLAG_OPEN_NO_RECALL = 0x00100000;
-
- //
- // These are the generic rights.
- //
-
- int GENERIC_READ = 0x80000000;
- int GENERIC_WRITE = 0x40000000;
- int GENERIC_EXECUTE = 0x20000000;
- int GENERIC_ALL = 0x10000000;
-
- //
- // AccessSystemAcl access type
- //
-
- int ACCESS_SYSTEM_SECURITY = 0x01000000;
-
- int PAGE_READONLY = 0x02;
- int PAGE_READWRITE = 0x04;
- int PAGE_WRITECOPY = 0x08;
- int PAGE_EXECUTE = 0x10;
- int PAGE_EXECUTE_READ = 0x20;
- int PAGE_EXECUTE_READWRITE = 0x40;
-
- int SECTION_QUERY = 0x0001;
- int SECTION_MAP_WRITE = 0x0002;
- int SECTION_MAP_READ = 0x0004;
- int SECTION_MAP_EXECUTE = 0x0008;
- int SECTION_EXTEND_SIZE = 0x0010;
-
- int FILE_SHARE_READ = 0x00000001;
- int FILE_SHARE_WRITE = 0x00000002;
- int FILE_SHARE_DELETE = 0x00000004;
- int FILE_TYPE_CHAR = 0x0002;
- int FILE_TYPE_DISK = 0x0001;
- int FILE_TYPE_PIPE = 0x0003;
- int FILE_TYPE_REMOTE = 0x8000;
- int FILE_TYPE_UNKNOWN = 0x0000;
- int FILE_ATTRIBUTE_READONLY = 0x00000001;
- int FILE_ATTRIBUTE_HIDDEN = 0x00000002;
- int FILE_ATTRIBUTE_SYSTEM = 0x00000004;
- int FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
- int FILE_ATTRIBUTE_ARCHIVE = 0x00000020;
- int FILE_ATTRIBUTE_DEVICE = 0x00000040;
- int FILE_ATTRIBUTE_NORMAL = 0x00000080;
- int FILE_ATTRIBUTE_TEMPORARY = 0x00000100;
- int FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200;
- int FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400;
- int FILE_ATTRIBUTE_COMPRESSED = 0x00000800;
- int FILE_ATTRIBUTE_OFFLINE = 0x00001000;
- int FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000;
- int FILE_ATTRIBUTE_ENCRYPTED = 0x00004000;
- int FILE_ATTRIBUTE_VIRTUAL = 0x00010000;
- int FILE_NOTIFY_CHANGE_FILE_NAME = 0x00000001;
- int FILE_NOTIFY_CHANGE_DIR_NAME = 0x00000002;
- int FILE_NOTIFY_CHANGE_NAME = 0x00000003;
- int FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x00000004;
- int FILE_NOTIFY_CHANGE_SIZE = 0x00000008;
- int FILE_NOTIFY_CHANGE_LAST_WRITE = 0x00000010;
- int FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x00000020;
- int FILE_NOTIFY_CHANGE_CREATION = 0x00000040;
- int FILE_NOTIFY_CHANGE_SECURITY = 0x00000100;
- int FILE_ACTION_ADDED = 0x00000001;
- int FILE_ACTION_REMOVED = 0x00000002;
- int FILE_ACTION_MODIFIED = 0x00000003;
- int FILE_ACTION_RENAMED_OLD_NAME = 0x00000004;
- int FILE_ACTION_RENAMED_NEW_NAME = 0x00000005;
- int FILE_CASE_SENSITIVE_SEARCH = 0x00000001;
- int FILE_CASE_PRESERVED_NAMES = 0x00000002;
- int FILE_UNICODE_ON_DISK = 0x00000004;
- int FILE_PERSISTENT_ACLS = 0x00000008;
- int FILE_FILE_COMPRESSION = 0x00000010;
- int FILE_VOLUME_QUOTAS = 0x00000020;
- int FILE_SUPPORTS_SPARSE_FILES = 0x00000040;
- int FILE_SUPPORTS_REPARSE_POINTS = 0x00000080;
- int FILE_SUPPORTS_REMOTE_STORAGE = 0x00000100;
- int FILE_VOLUME_IS_COMPRESSED = 0x00008000;
- int FILE_SUPPORTS_OBJECT_IDS = 0x00010000;
- int FILE_SUPPORTS_ENCRYPTION = 0x00020000;
- int FILE_NAMED_STREAMS = 0x00040000;
- int FILE_READ_ONLY_VOLUME = 0x00080000;
- int FILE_SEQUENTIAL_WRITE_ONCE = 0x00100000;
- int FILE_SUPPORTS_TRANSACTIONS = 0x00200000;
-
- /**
- * The FILE_NOTIFY_INFORMATION structure describes the changes found by the
- * ReadDirectoryChangesW function.
- *
- * This structure is non-trivial since it is a pattern stamped into a large
- * block of result memory rather than something that stands alone or is used
- * for input.
- */
- public static class FILE_NOTIFY_INFORMATION extends Structure {
- public int NextEntryOffset;
- public int Action;
- public int FileNameLength;
- // filename is not nul-terminated, so we can't use a String/WString
- public char[] FileName = new char[1];
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "NextEntryOffset", "Action", "FileNameLength", "FileName" });
- }
-
- private FILE_NOTIFY_INFORMATION() {
- }
-
- public FILE_NOTIFY_INFORMATION(int size) {
- if (size < size()) {
- throw new IllegalArgumentException("Size must greater than "
- + size() + ", requested " + size);
- }
- allocateMemory(size);
- }
-
- /**
- * WARNING: this filename may be either the short or long form of the
- * filename.
- */
- public String getFilename() {
- return new String(FileName, 0, FileNameLength / 2);
- }
-
- public void read() {
- // avoid reading filename until we know how long it is
- FileName = new char[0];
- super.read();
- FileName = getPointer().getCharArray(12, FileNameLength / 2);
- }
-
- public FILE_NOTIFY_INFORMATION next() {
- if (NextEntryOffset == 0) {
- return null;
- }
- FILE_NOTIFY_INFORMATION next = new FILE_NOTIFY_INFORMATION();
- next.useMemory(getPointer(), NextEntryOffset);
- next.read();
- return next;
- }
- }
-
- /**
- * Registry options.
- */
- int KEY_QUERY_VALUE = 0x0001;
- int KEY_SET_VALUE = 0x0002;
- int KEY_CREATE_SUB_KEY = 0x0004;
- int KEY_ENUMERATE_SUB_KEYS = 0x0008;
- int KEY_NOTIFY = 0x0010;
- int KEY_CREATE_LINK = 0x0020;
- int KEY_WOW64_32KEY = 0x0200;
- int KEY_WOW64_64KEY = 0x0100;
- int KEY_WOW64_RES = 0x0300;
-
- int KEY_READ = STANDARD_RIGHTS_READ | KEY_QUERY_VALUE
- | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY & (~SYNCHRONIZE);
-
- int KEY_WRITE = STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY
- & (~SYNCHRONIZE);
-
- int KEY_EXECUTE = KEY_READ & (~SYNCHRONIZE);
-
- int KEY_ALL_ACCESS = STANDARD_RIGHTS_ALL | KEY_QUERY_VALUE | KEY_SET_VALUE
- | KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY
- | KEY_CREATE_LINK & (~SYNCHRONIZE);
-
- //
- // Open/Create Options
- //
-
- /**
- * Parameter is reserved.
- */
- int REG_OPTION_RESERVED = 0x00000000;
-
- /**
- * Key is preserved when system is rebooted.
- */
- int REG_OPTION_NON_VOLATILE = 0x00000000;
-
- /**
- * Key is not preserved when system is rebooted.
- */
- int REG_OPTION_VOLATILE = 0x00000001;
-
- /**
- * Created key is a symbolic link.
- */
- int REG_OPTION_CREATE_LINK = 0x00000002;
-
- /**
- * Open for backup or restore special access rules privilege required.
- */
- int REG_OPTION_BACKUP_RESTORE = 0x00000004;
-
- /**
- * Open symbolic link.
- */
- int REG_OPTION_OPEN_LINK = 0x00000008;
-
- int REG_LEGAL_OPTION = REG_OPTION_RESERVED | REG_OPTION_NON_VOLATILE
- | REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK
- | REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK;
-
- //
- // Key creation/open disposition
- //
-
- /**
- * New Registry Key created.
- */
- int REG_CREATED_NEW_KEY = 0x00000001;
-
- /**
- * Existing Key opened.
- */
- int REG_OPENED_EXISTING_KEY = 0x00000002;
-
- int REG_STANDARD_FORMAT = 1;
- int REG_LATEST_FORMAT = 2;
- int REG_NO_COMPRESSION = 4;
-
- //
- // Key restore & hive load flags
- //
-
- /**
- * Restore whole hive volatile.
- */
- int REG_WHOLE_HIVE_VOLATILE = 0x00000001;
-
- /**
- * Unwind changes to last flush.
- */
- int REG_REFRESH_HIVE = 0x00000002;
-
- /**
- * Never lazy flush this hive.
- */
- int REG_NO_LAZY_FLUSH = 0x00000004;
-
- /**
- * Force the restore process even when we have open handles on subkeys.
- */
- int REG_FORCE_RESTORE = 0x00000008;
-
- /**
- * Loads the hive visible to the calling process.
- */
- int REG_APP_HIVE = 0x00000010;
-
- /**
- * Hive cannot be mounted by any other process while in use.
- */
- int REG_PROCESS_PRIVATE = 0x00000020;
-
- /**
- * Starts Hive Journal.
- */
- int REG_START_JOURNAL = 0x00000040;
-
- /**
- * Grow hive file in exact 4k increments.
- */
- int REG_HIVE_EXACT_FILE_GROWTH = 0x00000080;
-
- /**
- * No RM is started for this hive = no transactions.
- */
- int REG_HIVE_NO_RM = 0x00000100;
-
- /**
- * Legacy single logging is used for this hive.
- */
- int REG_HIVE_SINGLE_LOG = 0x00000200;
-
- //
- // Unload Flags
- //
-
- int REG_FORCE_UNLOAD = 1;
-
- //
- // Notify filter values
- //
-
- int REG_NOTIFY_CHANGE_NAME = 0x00000001;
- int REG_NOTIFY_CHANGE_ATTRIBUTES = 0x00000002;
- int REG_NOTIFY_CHANGE_LAST_SET = 0x00000004;
- int REG_NOTIFY_CHANGE_SECURITY = 0x00000008;
-
- int REG_LEGAL_CHANGE_FILTER = REG_NOTIFY_CHANGE_NAME
- | REG_NOTIFY_CHANGE_ATTRIBUTES | REG_NOTIFY_CHANGE_LAST_SET
- | REG_NOTIFY_CHANGE_SECURITY;
-
- //
- // Predefined Value Types.
- //
-
- /**
- * No value type.
- */
- int REG_NONE = 0;
-
- /**
- * Unicode null-terminated string.
- */
- int REG_SZ = 1;
-
- /**
- * Unicode null-terminated string with environment variable references.
- */
- int REG_EXPAND_SZ = 2;
-
- /**
- * Free-formed binary.
- */
- int REG_BINARY = 3;
-
- /**
- * 32-bit number.
- */
- int REG_DWORD = 4;
-
- /**
- * 32-bit number, same as REG_DWORD.
- */
- int REG_DWORD_LITTLE_ENDIAN = 4;
-
- /**
- * 32-bit number.
- */
- int REG_DWORD_BIG_ENDIAN = 5;
-
- /**
- * Symbolic link (unicode).
- */
- int REG_LINK = 6;
-
- /**
- * Multiple unicode strings.
- */
- int REG_MULTI_SZ = 7;
-
- /**
- * Resource list in the resource map.
- */
- int REG_RESOURCE_LIST = 8;
-
- /**
- * Resource list in the hardware description.
- */
- int REG_FULL_RESOURCE_DESCRIPTOR = 9;
-
- /**
- *
- */
- int REG_RESOURCE_REQUIREMENTS_LIST = 10;
-
- /**
- * 64-bit number.
- */
- int REG_QWORD = 11;
-
- /**
- * 64-bit number, same as REG_QWORD.
- */
- int REG_QWORD_LITTLE_ENDIAN = 11;
-
- /**
- * A 64-bit value that is guaranteed to be unique on the operating system
- * that generated it until the system is restarted.
- */
- public static class LUID extends Structure {
- public int LowPart;
- public int HighPart;
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "LowPart", "HighPart" });
- }
- }
-
- /**
- * A 64-bit integer;
- */
- public static class LARGE_INTEGER extends Structure {
- public static class ByReference extends LARGE_INTEGER implements
- Structure.ByReference {
- }
-
- public static class LowHigh extends Structure {
- public DWORD LowPart;
- public DWORD HighPart;
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "LowPart", "HighPart" });
- }
- }
-
- public static class UNION extends Union {
- public LowHigh lh;
- public long value;
- }
-
- public UNION u;
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "u" });
- }
-
- /**
- * Low DWORD.
- *
- * @return DWORD.
- */
- public DWORD getLow() {
- return u.lh.LowPart;
- }
-
- /**
- * High DWORD.
- *
- * @return DWORD.
- */
- public DWORD getHigh() {
- return u.lh.HighPart;
- }
-
- /**
- * 64-bit value.
- *
- * @return 64-bit value.
- */
- public long getValue() {
- return u.value;
- }
- }
-
- /**
- * Handle to an object.
- */
- public static class HANDLE extends PointerType {
- private boolean immutable;
-
- public HANDLE() {
- }
-
- public HANDLE(Pointer p) {
- setPointer(p);
- immutable = true;
- }
-
- /** Override to the appropriate object for INVALID_HANDLE_VALUE. */
- public Object fromNative(Object nativeValue, FromNativeContext context) {
- Object o = super.fromNative(nativeValue, context);
- if (WinBase.INVALID_HANDLE_VALUE.equals(o)) {
- return WinBase.INVALID_HANDLE_VALUE;
- }
- return o;
- }
-
- public void setPointer(Pointer p) {
- if (immutable) {
- throw new UnsupportedOperationException("immutable reference");
- }
-
- super.setPointer(p);
- }
- }
-
- /**
- * LPHANDLE
- */
- public static class HANDLEByReference extends ByReference {
- public HANDLEByReference() {
- this(null);
- }
-
- public HANDLEByReference(HANDLE h) {
- super(Pointer.SIZE);
- setValue(h);
- }
-
- public void setValue(HANDLE h) {
- getPointer().setPointer(0, h != null ? h.getPointer() : null);
- }
-
- public HANDLE getValue() {
- Pointer p = getPointer().getPointer(0);
- if (p == null) {
- return null;
- }
- if (WinBase.INVALID_HANDLE_VALUE.getPointer().equals(p)) {
- return WinBase.INVALID_HANDLE_VALUE;
- }
- HANDLE h = new HANDLE();
- h.setPointer(p);
- return h;
- }
- }
-
- /**
- * Return code used by interfaces. It is zero upon success and nonzero to
- * represent an error code or status information.
- */
- class HRESULT extends NativeLong {
- public HRESULT() {
- }
-
- public HRESULT(int value) {
- super(value);
- }
- }
-
- /**
- * The WELL_KNOWN_SID_TYPE enumeration type is a list of commonly used
- * security identifiers (SIDs). Programs can pass these values to the
- * CreateWellKnownSid function to create a SID from this list.
- */
- public abstract class WELL_KNOWN_SID_TYPE {
- /**
- * Indicates a null SID.
- */
- public static final int WinNullSid = 0;
-
- /**
- * Indicates a SID that matches everyone.
- */
- public static final int WinWorldSid = 1;
-
- /**
- * Indicates a local SID.
- */
- public static final int WinLocalSid = 2;
-
- /**
- * Indicates a SID that matches the owner or creator of an object.
- */
- public static final int WinCreatorOwnerSid = 3;
-
- /**
- * Indicates a SID that matches the creator group of an object.
- */
- public static final int WinCreatorGroupSid = 4;
-
- /**
- * Indicates a creator owner server SID.
- */
- public static final int WinCreatorOwnerServerSid = 5;
-
- /**
- * Indicates a creator group server SID.
- */
- public static final int WinCreatorGroupServerSid = 6;
-
- /**
- * Indicates a SID for the Windows NT authority.
- */
- public static final int WinNtAuthoritySid = 7;
-
- /**
- * Indicates a SID for a dial-up account.
- */
- public static final int WinDialupSid = 8;
-
- /**
- * Indicates a SID for a network account. This SID is added to the
- * process of a token when it logs on across a network. The
- * corresponding logon type is LOGON32_LOGON_NETWORK.
- */
- public static final int WinNetworkSid = 9;
-
- /**
- * Indicates a SID for a batch process. This SID is added to the process
- * of a token when it logs on as a batch job. The corresponding logon
- * type is LOGON32_LOGON_BATCH.
- */
- public static final int WinBatchSid = 10;
-
- /**
- * Indicates a SID for an interactive account. This SID is added to the
- * process of a token when it logs on interactively. The corresponding
- * logon type is LOGON32_LOGON_INTERACTIVE.
- */
- public static final int WinInteractiveSid = 11;
-
- /**
- * Indicates a SID for a service. This SID is added to the process of a
- * token when it logs on as a service. The corresponding logon type is
- * LOGON32_LOGON_bSERVICE.
- */
- public static final int WinServiceSid = 12;
-
- /**
- * Indicates a SID for the anonymous account.
- */
- public static final int WinAnonymousSid = 13;
-
- /**
- * Indicates a proxy SID.
- */
- public static final int WinProxySid = 14;
-
- /**
- * Indicates a SID for an enterprise controller.
- */
- public static final int WinEnterpriseControllersSid = 15;
-
- /**
- * Indicates a SID for self.
- */
- public static final int WinSelfSid = 16;
-
- /**
- * Indicates a SID that matches any authenticated user.
- */
- public static final int WinAuthenticatedUserSid = 17;
-
- /**
- * Indicates a SID for restricted code.
- */
- public static final int WinRestrictedCodeSid = 18;
-
- /**
- * Indicates a SID that matches a terminal server account.
- */
- public static final int WinTerminalServerSid = 19;
-
- /**
- * Indicates a SID that matches remote logons.
- */
- public static final int WinRemoteLogonIdSid = 20;
-
- /**
- * Indicates a SID that matches logon IDs.
- */
- public static final int WinLogonIdsSid = 21;
-
- /**
- * Indicates a SID that matches the local system.
- */
- public static final int WinLocalSystemSid = 22;
-
- /**
- * Indicates a SID that matches a local service.
- */
- public static final int WinLocalServiceSid = 23;
-
- /**
- * Indicates a SID that matches a network service.
- */
- public static final int WinNetworkServiceSid = 24;
-
- /**
- * Indicates a SID that matches the domain account.
- */
- public static final int WinBuiltinDomainSid = 25;
-
- /**
- * Indicates a SID that matches the administrator account.
- */
- public static final int WinBuiltinAdministratorsSid = 26;
-
- /**
- * Indicates a SID that matches built-in user accounts.
- */
- public static final int WinBuiltinUsersSid = 27;
-
- /**
- * Indicates a SID that matches the guest account.
- */
- public static final int WinBuiltinGuestsSid = 28;
-
- /**
- * Indicates a SID that matches the power users group.
- */
- public static final int WinBuiltinPowerUsersSid = 29;
-
- /**
- * Indicates a SID that matches the account operators account.
- */
- public static final int WinBuiltinAccountOperatorsSid = 30;
-
- /**
- * Indicates a SID that matches the system operators group.
- */
- public static final int WinBuiltinSystemOperatorsSid = 31;
-
- /**
- * Indicates a SID that matches the print operators group.
- */
- public static final int WinBuiltinPrintOperatorsSid = 32;
-
- /**
- * Indicates a SID that matches the backup operators group.
- */
- public static final int WinBuiltinBackupOperatorsSid = 33;
-
- /**
- * Indicates a SID that matches the replicator account.
- */
- public static final int WinBuiltinReplicatorSid = 34;
-
- /**
- * Indicates a SID that matches pre-Windows 2000 compatible accounts.
- */
- public static final int WinBuiltinPreWindows2000CompatibleAccessSid = 35;
-
- /**
- * Indicates a SID that matches remote desktop users.
- */
- public static final int WinBuiltinRemoteDesktopUsersSid = 36;
-
- /**
- * Indicates a SID that matches the network operators group.
- */
- public static final int WinBuiltinNetworkConfigurationOperatorsSid = 37;
-
- /**
- * Indicates a SID that matches the account administrators group.
- */
- public static final int WinAccountAdministratorSid = 38;
-
- /**
- * Indicates a SID that matches the account guest group.
- */
- public static final int WinAccountGuestSid = 39;
-
- /**
- * Indicates a SID that matches account Kerberos target group.
- */
- public static final int WinAccountKrbtgtSid = 40;
-
- /**
- * Indicates a SID that matches the account domain administrator group.
- */
- public static final int WinAccountDomainAdminsSid = 41;
-
- /**
- * Indicates a SID that matches the account domain users group.
- */
- public static final int WinAccountDomainUsersSid = 42;
-
- /**
- * Indicates a SID that matches the account domain guests group.
- */
- public static final int WinAccountDomainGuestsSid = 43;
-
- /**
- * Indicates a SID that matches the account computer group.
- */
- public static final int WinAccountComputersSid = 44;
-
- /**
- * Indicates a SID that matches the account controller group.
- */
- public static final int WinAccountControllersSid = 45;
-
- /**
- * Indicates a SID that matches the certificate administrators group.
- */
- public static final int WinAccountCertAdminsSid = 46;
-
- /**
- * Indicates a SID that matches the schema administrators group.
- */
- public static final int WinAccountSchemaAdminsSid = 47;
-
- /**
- * Indicates a SID that matches the enterprise administrators group.
- */
- public static final int WinAccountEnterpriseAdminsSid = 48;
-
- /**
- * Indicates a SID that matches the policy administrators group.
- */
- public static final int WinAccountPolicyAdminsSid = 49;
-
- /**
- * Indicates a SID that matches the RAS and IAS server account.
- */
- public static final int WinAccountRasAndIasServersSid = 50;
-
- /**
- * Indicates a SID present when the Microsoft NTLM authentication
- * package authenticated the client.
- */
- public static final int WinNTLMAuthenticationSid = 51;
-
- /**
- * Indicates a SID present when the Microsoft Digest authentication
- * package authenticated the client.
- */
- public static final int WinDigestAuthenticationSid = 52;
-
- /**
- * Indicates a SID present when the Secure Channel (SSL/TLS)
- * authentication package authenticated the client.
- */
- public static final int WinSChannelAuthenticationSid = 53;
-
- /**
- * Indicates a SID present when the user authenticated from within the
- * forest or across a trust that does not have the selective
- * authentication option enabled. If this SID is present, then
- * WinOtherOrganizationSid cannot be present.
- */
- public static final int WinThisOrganizationSid = 54;
-
- /**
- * Indicates a SID present when the user authenticated across a forest
- * with the selective authentication option enabled. If this SID is
- * present, then WinThisOrganizationSid cannot be present.
- */
- public static final int WinOtherOrganizationSid = 55;
-
- /**
- * Indicates a SID that allows a user to create incoming forest trusts.
- * It is added to the token of users who are a member of the Incoming
- * Forest Trust Builders built-in group in the root domain of the
- * forest.
- */
- public static final int WinBuiltinIncomingForestTrustBuildersSid = 56;
-
- /**
- * Indicates a SID that matches the performance monitor user group.
- */
- public static final int WinBuiltinPerfMonitoringUsersSid = 57;
-
- /**
- * Indicates a SID that matches the performance log user group.
- */
- public static final int WinBuiltinPerfLoggingUsersSid = 58;
-
- /**
- * Indicates a SID that matches the Windows Authorization Access group.
- */
- public static final int WinBuiltinAuthorizationAccessSid = 59;
-
- /**
- * Indicates a SID is present in a server that can issue Terminal Server
- * licenses.
- */
- public static final int WinBuiltinTerminalServerLicenseServersSid = 60;
-
- /**
- *
- */
- public static final int WinBuiltinDCOMUsersSid = 61;
-
- /**
- *
- */
- public static final int WinBuiltinIUsersSid = 62;
-
- /**
- *
- */
- public static final int WinIUserSid = 63;
-
- /**
- *
- */
- public static final int WinBuiltinCryptoOperatorsSid = 64;
-
- /**
- *
- */
- public static final int WinUntrustedLabelSid = 65;
-
- /**
- *
- */
- public static final int WinLowLabelSid = 66;
-
- /**
- *
- */
- public static final int WinMediumLabelSid = 67;
-
- /**
- *
- */
- public static final int WinHighLabelSid = 68;
-
- /**
- *
- */
- public static final int WinSystemLabelSid = 69;
-
- /**
- *
- */
- public static final int WinWriteRestrictedCodeSid = 70;
-
- /**
- *
- */
- public static final int WinCreatorOwnerRightsSid = 71;
-
- /**
- *
- */
- public static final int WinCacheablePrincipalsGroupSid = 72;
-
- /**
- *
- */
- public static final int WinNonCacheablePrincipalsGroupSid = 73;
-
- /**
- *
- */
- public static final int WinEnterpriseReadonlyControllersSid = 74;
-
- /**
- * Indicates a SID that matches a read-only enterprise domain
- * controller.
- */
- public static final int WinAccountReadonlyControllersSid = 75;
-
- /**
- * Indicates a SID that matches the built-in DCOM certification services
- * access group.
- */
- public static final int WinBuiltinEventLogReadersGroup = 76;
- }
-
- /**
- * Current SID revision level.
- */
- int SID_REVISION = 1;
- int SID_MAX_SUB_AUTHORITIES = 15;
- int SID_RECOMMENDED_SUB_AUTHORITIES = 1;
-
- /**
- * Maximum bytes used by a SID. (sizeof(SID) - sizeof(DWORD) +
- * (SID_MAX_SUB_AUTHORITIES * sizeof(DWORD)))
- */
- int SECURITY_MAX_SID_SIZE = 68;
-
- /**
- * The OSVERSIONINFO data structure contains operating system version
- * information. The information includes major and minor version numbers, a
- * build number, a platform identifier, and descriptive text about the
- * operating system. This structure is used with the GetVersionEx function.
- */
- public static class OSVERSIONINFO extends Structure {
- /**
- * Size of this data structure, in bytes. Set this member to
- * sizeof(OSVERSIONINFO) before calling the GetVersionEx function.
- */
- public DWORD dwOSVersionInfoSize;
-
- /**
- * Major version number of the operating system.
- */
- public DWORD dwMajorVersion;
-
- /**
- * Minor version number of the operating system.
- */
- public DWORD dwMinorVersion;
-
- /**
- * Build number of the operating system.
- */
- public DWORD dwBuildNumber;
-
- /**
- * Operating system platform.
- */
- public DWORD dwPlatformId;
-
- /**
- * Pointer to a null-terminated string, such as "Service Pack 3", that
- * indicates the latest Service Pack installed on the system.
- */
- public char szCSDVersion[];
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "dwOSVersionInfoSize", "dwMajorVersion", "dwMinorVersion", "dwBuildNumber", "dwPlatformId", "szCSDVersion" });
- }
-
- public OSVERSIONINFO() {
- szCSDVersion = new char[128];
- dwOSVersionInfoSize = new DWORD(size()); // sizeof(OSVERSIONINFO)
- }
-
- public OSVERSIONINFO(Pointer memory) {
- super(memory);
- read();
- }
- }
-
- /**
- * Contains operating system version information. The information includes
- * major and minor version numbers, a build number, a platform identifier,
- * and information about product suites and the latest Service Pack
- * installed on the system.
- */
- public static class OSVERSIONINFOEX extends Structure {
- /**
- * The size of this data structure, in bytes.
- */
- public DWORD dwOSVersionInfoSize;
-
- /**
- * The major version number of the operating system.
- */
- public DWORD dwMajorVersion;
-
- /**
- * The minor version number of the operating system.
- */
- public DWORD dwMinorVersion;
-
- /**
- * The build number of the operating system.
- */
- public DWORD dwBuildNumber;
-
- /**
- * The operating system platform. This member can be
- * VER_PLATFORM_WIN32_NT.
- */
- public DWORD dwPlatformId;
-
- /**
- * A null-terminated string, such as "Service Pack 3", that indicates
- * the latest Service Pack installed on the system. If no Service Pack
- * has been installed, the string is empty.
- */
- public char szCSDVersion[];
-
- /**
- * The major version number of the latest Service Pack installed on the
- * system. For example, for Service Pack 3, the major version number is
- * 3. If no Service Pack has been installed, the value is zero.
- */
- public WORD wServicePackMajor;
-
- /**
- * The minor version number of the latest Service Pack installed on the
- * system. For example, for Service Pack 3, the minor version number is
- * 0.
- */
- public WORD wServicePackMinor;
-
- /**
- * A bit mask that identifies the product suites available on the
- * system.
- */
- public WORD wSuiteMask;
-
- /**
- * Any additional information about the system.
- */
- public byte wProductType;
-
- /**
- * Reserved for future use.
- */
- public byte wReserved;
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "dwOSVersionInfoSize", "dwMajorVersion", "dwMinorVersion", "dwBuildNumber", "dwPlatformId", "szCSDVersion", "wServicePackMajor", "wServicePackMinor", "wSuiteMask", "wProductType", "wReserved"});
- }
-
- public OSVERSIONINFOEX() {
- szCSDVersion = new char[128];
- dwOSVersionInfoSize = new DWORD(size()); // sizeof(OSVERSIONINFOEX)
- }
-
- public OSVERSIONINFOEX(Pointer memory) {
- super(memory);
- read();
- }
- }
-
- int VER_EQUAL = 1;
- int VER_GREATER = 2;
- int VER_GREATER_EQUAL = 3;
- int VER_LESS = 4;
- int VER_LESS_EQUAL = 5;
- int VER_AND = 6;
- int VER_OR = 7;
-
- int VER_CONDITION_MASK = 7;
- int VER_NUM_BITS_PER_CONDITION_MASK = 3;
-
- int VER_MINORVERSION = 0x0000001;
- int VER_MAJORVERSION = 0x0000002;
- int VER_BUILDNUMBER = 0x0000004;
- int VER_PLATFORMID = 0x0000008;
- int VER_SERVICEPACKMINOR = 0x0000010;
- int VER_SERVICEPACKMAJOR = 0x0000020;
- int VER_SUITENAME = 0x0000040;
- int VER_PRODUCT_TYPE = 0x0000080;
-
- int VER_NT_WORKSTATION = 0x0000001;
- int VER_NT_DOMAIN_CONTROLLER = 0x0000002;
- int VER_NT_SERVER = 0x0000003;
-
- int VER_PLATFORM_WIN32s = 0;
- int VER_PLATFORM_WIN32_WINDOWS = 1;
- int VER_PLATFORM_WIN32_NT = 2;
-
- /**
- * Read the records sequentially. If this is the first read operation, the
- * EVENTLOG_FORWARDS_READ EVENTLOG_BACKWARDS_READ flags determines which
- * record is read first.
- */
- int EVENTLOG_SEQUENTIAL_READ = 0x0001;
-
- /**
- * Begin reading from the record specified in the dwRecordOffset parameter.
- * This option may not work with large log files if the function cannot
- * determine the log file's size. For details, see Knowledge Base article,
- * 177199.
- */
- int EVENTLOG_SEEK_READ = 0x0002;
-
- /**
- * The log is read in chronological order (oldest to newest). The default.
- */
- int EVENTLOG_FORWARDS_READ = 0x0004;
-
- /**
- * The log is read in reverse chronological order (newest to oldest).
- */
- int EVENTLOG_BACKWARDS_READ = 0x0008;
-
- /**
- * Information event
- */
- int EVENTLOG_SUCCESS = 0x0000;
-
- /**
- * Error event
- */
- int EVENTLOG_ERROR_TYPE = 0x0001;
-
- /**
- * Warning event
- */
- int EVENTLOG_WARNING_TYPE = 0x0002;
-
- /**
- * Information event
- */
- int EVENTLOG_INFORMATION_TYPE = 0x0004;
-
- /**
- * Success Audit event
- */
- int EVENTLOG_AUDIT_SUCCESS = 0x0008;
-
- /**
- * Failure Audit event
- */
- int EVENTLOG_AUDIT_FAILURE = 0x0010;
-
- /**
- * The EVENTLOGRECORD structure contains information about an event record
- * returned by the ReadEventLog function.
- */
- public static class EVENTLOGRECORD extends Structure {
- /**
- * Size of this event record, in bytes. Note that this value is stored
- * at both ends of the entry to ease moving forward or backward through
- * the log. The length includes any pad bytes inserted at the end of the
- * record for DWORD alignment.
- */
- public DWORD Length;
-
- /**
- * Reserved.
- */
- public DWORD Reserved;
-
- /**
- * Record number of the record. This value can be used with the
- * EVENTLOG_SEEK_READ flag in the ReadEventLog function to begin reading
- * at a specified record.
- */
- public DWORD RecordNumber;
-
- /**
- * Time at which this entry was submitted. This time is measured in the
- * number of seconds elapsed since 00:00:00 January 1, 1970, Universal
- * Coordinated Time.
- */
- public DWORD TimeGenerated;
-
- /**
- * Time at which this entry was received by the service to be written to
- * the log. This time is measured in the number of seconds elapsed since
- * 00:00:00 January 1, 1970, Universal Coordinated Time.
- */
- public DWORD TimeWritten;
-
- /**
- * Event identifier. The value is specific to the event source for the
- * event, and is used with source name to locate a description string in
- * the message file for the event source.
- */
- public DWORD EventID;
-
- /**
- * Type of event.
- */
- public WORD EventType;
-
- /**
- * Number of strings present in the log (at the position indicated by
- * StringOffset). These strings are merged into the message before it is
- * displayed to the user.
- */
- public WORD NumStrings;
-
- /**
- * Category for this event. The meaning of this value depends on the
- * event source.
- */
- public WORD EventCategory;
-
- /**
- * Reserved.
- */
- public WORD ReservedFlags;
-
- /**
- * Reserved.
- */
- public DWORD ClosingRecordNumber;
-
- /**
- * Offset of the description strings within this event log record.
- */
- public DWORD StringOffset;
-
- /**
- * Size of the UserSid member, in bytes. This value can be zero if no
- * security identifier was provided.
- */
- public DWORD UserSidLength;
-
- /**
- * Offset of the security identifier (SID) within this event log record.
- * To obtain the user name for this SID, use the LookupAccountSid
- * function.
- */
- public DWORD UserSidOffset;
-
- /**
- * Size of the event-specific data (at the position indicated by
- * DataOffset), in bytes.
- */
- public DWORD DataLength;
-
- /**
- * Offset of the event-specific information within this event log
- * record, in bytes. This information could be something specific (a
- * disk driver might log the number of retries, for example), followed
- * by binary information specific to the event being logged and to the
- * source that generated the entry.
- */
- public DWORD DataOffset;
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "Length", "Reserved", "RecordNumber", "TimeGenerated", "TimeWritten", "EventID", "EventType", "NumStrings", "EventCategory", "ReservedFlags", "ClosingRecordNumber", "StringOffset", "UserSidLength", "UserSidOffset", "DataLength", "DataOffset"});
- }
-
- public EVENTLOGRECORD() {
- }
-
- public EVENTLOGRECORD(Pointer p) {
- super(p);
- read();
- }
- }
-
- //
- // Service Types (Bit Mask)
- //
- int SERVICE_KERNEL_DRIVER = 0x00000001;
- int SERVICE_FILE_SYSTEM_DRIVER = 0x00000002;
- int SERVICE_ADAPTER = 0x00000004;
- int SERVICE_RECOGNIZER_DRIVER = 0x00000008;
- int SERVICE_DRIVER = SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER
- | SERVICE_RECOGNIZER_DRIVER;
- int SERVICE_WIN32_OWN_PROCESS = 0x00000010;
- int SERVICE_WIN32_SHARE_PROCESS = 0x00000020;
- int SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS;
- int SERVICE_INTERACTIVE_PROCESS = 0x00000100;
- int SERVICE_TYPE_ALL = SERVICE_WIN32 | SERVICE_ADAPTER | SERVICE_DRIVER
- | SERVICE_INTERACTIVE_PROCESS;
- int STATUS_PENDING = 0x00000103;
-
- // Privilege Constants
- String SE_CREATE_TOKEN_NAME = "SeCreateTokenPrivilege";
- String SE_ASSIGNPRIMARYTOKEN_NAME = "SeAssignPrimaryTokenPrivilege";
- String SE_LOCK_MEMORY_NAME = "SeLockMemoryPrivilege";
- String SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege";
- String SE_UNSOLICITED_INPUT_NAME = "SeUnsolicitedInputPrivilege";
- String SE_MACHINE_ACCOUNT_NAME = "SeMachineAccountPrivilege";
- String SE_TCB_NAME = "SeTcbPrivilege";
- String SE_SECURITY_NAME = "SeSecurityPrivilege";
- String SE_TAKE_OWNERSHIP_NAME = "SeTakeOwnershipPrivilege";
- String SE_LOAD_DRIVER_NAME = "SeLoadDriverPrivilege";
- String SE_SYSTEM_PROFILE_NAME = "SeSystemProfilePrivilege";
- String SE_SYSTEMTIME_NAME = "SeSystemtimePrivilege";
- String SE_PROF_SINGLE_PROCESS_NAME = "SeProfileSingleProcessPrivilege";
- String SE_INC_BASE_PRIORITY_NAME = "SeIncreaseBasePriorityPrivilege";
- String SE_CREATE_PAGEFILE_NAME = "SeCreatePagefilePrivilege";
- String SE_CREATE_PERMANENT_NAME = "SeCreatePermanentPrivilege";
- String SE_BACKUP_NAME = "SeBackupPrivilege";
- String SE_RESTORE_NAME = "SeRestorePrivilege";
- String SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
- String SE_DEBUG_NAME = "SeDebugPrivilege";
- String SE_AUDIT_NAME = "SeAuditPrivilege";
- String SE_SYSTEM_ENVIRONMENT_NAME = "SeSystemEnvironmentPrivilege";
- String SE_CHANGE_NOTIFY_NAME = "SeChangeNotifyPrivilege";
- String SE_REMOTE_SHUTDOWN_NAME = "SeRemoteShutdownPrivilege";
- String SE_UNDOCK_NAME = "SeUndockPrivilege";
- String SE_SYNC_AGENT_NAME = "SeSyncAgentPrivilege";
- String SE_ENABLE_DELEGATION_NAME = "SeEnableDelegationPrivilege";
- String SE_MANAGE_VOLUME_NAME = "SeManageVolumePrivilege";
- String SE_IMPERSONATE_NAME = "SeImpersonatePrivilege";
- String SE_CREATE_GLOBAL_NAME = "SeCreateGlobalPrivilege";
-
- int SE_PRIVILEGE_ENABLED_BY_DEFAULT = 0x00000001;
- int SE_PRIVILEGE_ENABLED = 0x00000002;
- int SE_PRIVILEGE_REMOVED = 0X00000004;
- int SE_PRIVILEGE_USED_FOR_ACCESS = 0x80000000;
-
- int PROCESS_TERMINATE = 0x00000001;
- int PROCESS_SYNCHRONIZE = 0x00100000;
-
- /* Security information types */
- int OWNER_SECURITY_INFORMATION = 0x00000001;
- int GROUP_SECURITY_INFORMATION = 0x00000002;
- int DACL_SECURITY_INFORMATION = 0x00000004;
- int SACL_SECURITY_INFORMATION = 0x00000008;
- int LABEL_SECURITY_INFORMATION = 0x00000010;
- int PROTECTED_DACL_SECURITY_INFORMATION = 0x80000000;
- int PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000;
- int UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000;
- int UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000;
-
- public static class SECURITY_DESCRIPTOR extends Structure {
- public static class ByReference extends SECURITY_DESCRIPTOR implements
- Structure.ByReference {
- }
-
- public SECURITY_DESCRIPTOR() {
- }
-
- public SECURITY_DESCRIPTOR(byte[] data) {
- super();
- this.data = data;
- useMemory(new Memory(data.length));
- }
-
- public SECURITY_DESCRIPTOR(Pointer memory) {
- super(memory);
- read();
- }
-
- public byte[] data;
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "data" });
- }
- }
-
- public static class ACL extends Structure {
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "AclRevision", "Sbz1", "AclSize", "AceCount", "Sbz2" });
- }
-
- public ACL() {
- }
-
- public ACL(Pointer pointer) {
- super(pointer);
- read();
- ACEs = new ACCESS_ACEStructure[AceCount];
- int offset = size();
- for (int i = 0; i < AceCount; i++) {
- Pointer share = pointer.share(offset);
- // ACE_HEADER.AceType
- final byte aceType = share.getByte(0);
- ACCESS_ACEStructure ace = null;
- switch (aceType) {
- case ACCESS_ALLOWED_ACE_TYPE:
- ace = new ACCESS_ALLOWED_ACE(share);
- break;
- case ACCESS_DENIED_ACE_TYPE:
- ace = new ACCESS_DENIED_ACE(share);
- break;
- default:
- throw new IllegalArgumentException("Unknwon ACE type "
- + aceType);
- }
- ACEs[i] = ace;
- offset += ace.AceSize;
- }
- }
-
- public byte AclRevision;
- public byte Sbz1;
- public short AclSize;
- public short AceCount;
- public short Sbz2;
-
- ACCESS_ACEStructure[] ACEs;
-
- public ACCESS_ACEStructure[] getACEStructures() {
- return ACEs;
- }
- }
-
- public static class SECURITY_DESCRIPTOR_RELATIVE extends Structure {
- public static class ByReference extends SECURITY_DESCRIPTOR_RELATIVE
- implements Structure.ByReference {
- }
-
- public byte Revision;
- public byte Sbz1;
- public short Control;
- public int Owner;
- public int Group;
- public int Sacl;
- public int Dacl;
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "Revision", "Sbz1", "Control", "Owner", "Group", "Sacl", "Dacl" });
- }
-
- private ACL DACL;
-
- public SECURITY_DESCRIPTOR_RELATIVE() {
- }
-
- public SECURITY_DESCRIPTOR_RELATIVE(byte[] data) {
- super(new Memory(data.length));
- getPointer().write(0, data, 0, data.length);
- setDacl();
- }
-
- public SECURITY_DESCRIPTOR_RELATIVE(Memory memory) {
- super(memory);
- setDacl();
- }
-
- public ACL getDiscretionaryACL() {
- return DACL;
- }
-
- private final void setDacl() {
- read();
- if (Dacl != 0) {
- DACL = new ACL(getPointer().share(Dacl));
- }
- }
- }
-
- public static abstract class ACEStructure extends Structure {
- public byte AceType;
- public byte AceFlags;
- public short AceSize;
-
- PSID psid;
-
- public ACEStructure(Pointer p) {
- super(p);
- }
-
- protected List getFieldOrder() {
- return Arrays.asList(new String[] { "AceType", "AceFlags", "AceSize" });
- }
-
- public String getSidString() {
- return Advapi32Util.convertSidToStringSid(psid);
- }
-
- public PSID getSID() {
- return psid;
- }
- }
-
- /* ACE header */
- public static class ACE_HEADER extends ACEStructure {
- public ACE_HEADER(Pointer p) {
- super(p);
- read();
- }
- }
-
- /**
- * ACCESS_ALLOWED_ACE and ACCESS_DENIED_ACE have the same structure layout
- */
- public static abstract class ACCESS_ACEStructure extends ACEStructure {
- protected List getFieldOrder() {
- List list = new ArrayList(super.getFieldOrder());
- list.addAll(Arrays.asList(new String[] { "Mask", "SidStart"}));
- return list;
- }
- public ACCESS_ACEStructure(Pointer p) {
- super(p);
- read();
- // AceSize - size of public members of the structure + size of DWORD
- // (SidStart)
- int sizeOfSID = super.AceSize - size() + 4;
- // ACE_HEADER + size of int (Mask)
- int offsetOfSID = 4 + 4;
- byte[] data = p.getByteArray(offsetOfSID, sizeOfSID);
- psid = new PSID(data);
- }
-
- public int Mask;
-
- /**
- * first 4 bytes of the SID
- */
- public DWORD SidStart;
- }
-
- /* Access allowed ACE */
- public static class ACCESS_ALLOWED_ACE extends ACCESS_ACEStructure {
- public ACCESS_ALLOWED_ACE(Pointer p) {
- super(p);
- }
- }
-
- /* Access denied ACE */
- public static class ACCESS_DENIED_ACE extends ACCESS_ACEStructure {
- public ACCESS_DENIED_ACE(Pointer p) {
- super(p);
- }
- }
-
- /* ACE types */
- byte ACCESS_ALLOWED_ACE_TYPE = 0x00;
- byte ACCESS_DENIED_ACE_TYPE = 0x01;
- byte SYSTEM_AUDIT_ACE_TYPE = 0x02;
- byte SYSTEM_ALARM_ACE_TYPE = 0x03;
- byte ACCESS_ALLOWED_COMPOUND_ACE_TYPE = 0x04;
- byte ACCESS_ALLOWED_OBJECT_ACE_TYPE = 0x05;
- byte ACCESS_DENIED_OBJECT_ACE_TYPE = 0x06;
- byte SYSTEM_AUDIT_OBJECT_ACE_TYPE = 0x07;
- byte SYSTEM_ALARM_OBJECT_ACE_TYPE = 0x08;
- byte ACCESS_ALLOWED_CALLBACK_ACE_TYPE = 0x09;
- byte ACCESS_DENIED_CALLBACK_ACE_TYPE = 0x0A;
- byte ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE = 0x0B;
- byte ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE = 0x0C;
- byte SYSTEM_AUDIT_CALLBACK_ACE_TYPE = 0x0D;
- byte SYSTEM_ALARM_CALLBACK_ACE_TYPE = 0x0E;
- byte SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE = 0x0F;
- byte SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE = 0x10;
- byte SYSTEM_MANDATORY_LABEL_ACE_TYPE = 0x11;
-
- /* ACE inherit flags */
- byte OBJECT_INHERIT_ACE = 0x01;
- byte CONTAINER_INHERIT_ACE = 0x02;
- byte NO_PROPAGATE_INHERIT_ACE = 0x04;
- byte INHERIT_ONLY_ACE = 0x08;
- byte INHERITED_ACE = 0x10;
- byte VALID_INHERIT_FLAGS = 0x1F;
-
- // TODO: figure out how OVERLAPPED is used and apply an appropriate mapping
- interface OVERLAPPED_COMPLETION_ROUTINE extends StdCallCallback {
- void callback(int errorCode, int nBytesTransferred,
- WinBase.OVERLAPPED overlapped);
- }
-}
+/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package com.sun.jna.platform.win32;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import com.sun.jna.FromNativeContext;
+import com.sun.jna.Memory;
+import com.sun.jna.NativeLong;
+import com.sun.jna.Pointer;
+import com.sun.jna.PointerType;
+import com.sun.jna.Structure;
+import com.sun.jna.Union;
+import com.sun.jna.ptr.ByReference;
+
+/**
+ * This module defines the 32-Bit Windows types and constants that are defined
+ * by NT, but exposed through the Win32 API. Ported from WinNT.h Microsoft
+ * Windows SDK 6.0A. Avoid including any NIO Buffer mappings here; put them in a
+ * DLL-derived interface (e.g. kernel32, user32, etc) instead.
+ *
+ * @author dblock[at]dblock.org
+ */
+@SuppressWarnings("serial")
+public interface WinNT extends WinError, WinDef, WinBase, BaseTSD {
+
+ //
+ // The following are masks for the predefined standard access types
+ //
+
+ int DELETE = 0x00010000;
+ int READ_CONTROL = 0x00020000;
+ int WRITE_DAC = 0x00040000;
+ int WRITE_OWNER = 0x00080000;
+ int SYNCHRONIZE = 0x00100000;
+
+ int STANDARD_RIGHTS_REQUIRED = 0x000F0000;
+ int STANDARD_RIGHTS_READ = READ_CONTROL;
+ int STANDARD_RIGHTS_WRITE = READ_CONTROL;
+ int STANDARD_RIGHTS_EXECUTE = READ_CONTROL;
+ int STANDARD_RIGHTS_ALL = 0x001F0000;
+
+ int SPECIFIC_RIGHTS_ALL = 0x0000FFFF;
+
+ //
+ // Token Specific Access Rights.
+ //
+
+ /**
+ * Required to attach a primary token to a process. The
+ * SE_ASSIGNPRIMARYTOKEN_NAME privilege is also required to accomplish this
+ * task.
+ */
+ int TOKEN_ASSIGN_PRIMARY = 0x0001;
+
+ /**
+ * Required to duplicate an access token.
+ */
+ int TOKEN_DUPLICATE = 0x0002;
+
+ /**
+ * Required to attach an impersonation access token to a process.
+ */
+ int TOKEN_IMPERSONATE = 0x0004;
+
+ /**
+ * Required to query an access token.
+ */
+ int TOKEN_QUERY = 0x0008;
+
+ /**
+ * Required to query the source of an access token.
+ */
+ int TOKEN_QUERY_SOURCE = 0x0010;
+
+ /**
+ * Required to enable or disable the privileges in an access token.
+ */
+ int TOKEN_ADJUST_PRIVILEGES = 0x0020;
+
+ /**
+ * Required to adjust the attributes of the groups in an access token.
+ */
+ int TOKEN_ADJUST_GROUPS = 0x0040;
+
+ /**
+ * Required to change the default owner, primary group, or DACL of an access
+ * token.
+ */
+ int TOKEN_ADJUST_DEFAULT = 0x0080;
+
+ /**
+ * Required to adjust the session ID of an access token. The SE_TCB_NAME
+ * privilege is required.
+ */
+ int TOKEN_ADJUST_SESSIONID = 0x0100;
+
+ int TOKEN_ALL_ACCESS_P = STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY
+ | TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY
+ | TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES
+ | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT;
+
+ /**
+ * Combines all possible access rights for a token.
+ */
+ int TOKEN_ALL_ACCESS = TOKEN_ALL_ACCESS_P | TOKEN_ADJUST_SESSIONID;
+
+ /**
+ * Combines STANDARD_RIGHTS_READ and TOKEN_QUERY.
+ */
+ int TOKEN_READ = STANDARD_RIGHTS_READ | TOKEN_QUERY;
+
+ /**
+ * Combines STANDARD_RIGHTS_WRITE, TOKEN_ADJUST_PRIVILEGES,
+ * TOKEN_ADJUST_GROUPS, and TOKEN_ADJUST_DEFAULT.
+ */
+ int TOKEN_WRITE = STANDARD_RIGHTS_WRITE | TOKEN_ADJUST_PRIVILEGES
+ | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT;
+
+ /**
+ * Combines STANDARD_RIGHTS_EXECUTE and TOKEN_IMPERSONATE.
+ */
+ int TOKEN_EXECUTE = STANDARD_RIGHTS_EXECUTE;
+
+ int THREAD_TERMINATE = 0x0001;
+ int THREAD_SUSPEND_RESUME = 0x0002;
+ int THREAD_GET_CONTEXT = 0x0008;
+ int THREAD_SET_CONTEXT = 0x0010;
+ int THREAD_QUERY_INFORMATION = 0x0040;
+ int THREAD_SET_INFORMATION = 0x0020;
+ int THREAD_SET_THREAD_TOKEN = 0x0080;
+ int THREAD_IMPERSONATE = 0x0100;
+ int THREAD_DIRECT_IMPERSONATION = 0x0200;
+ int THREAD_SET_LIMITED_INFORMATION = 0x0400;
+ int THREAD_QUERY_LIMITED_INFORMATION = 0x0800;
+ int THREAD_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3FF;
+
+ /**
+ * The SECURITY_IMPERSONATION_LEVEL enumeration type contains values that
+ * specify security impersonation levels. Security impersonation levels
+ * govern the degree to which a server process can act on behalf of a client
+ * process.
+ */
+ public abstract class SECURITY_IMPERSONATION_LEVEL {
+ /**
+ * The server process cannot obtain identification information about the
+ * client, and it cannot impersonate the client. It is defined with no
+ * value given, and thus, by ANSI C rules, defaults to a value of zero.
+ */
+ public static final int SecurityAnonymous = 0;
+
+ /**
+ * The server process can obtain information about the client, such as
+ * security identifiers and privileges, but it cannot impersonate the
+ * client. This is useful for servers that export their own objects, for
+ * example, database products that export tables and views. Using the
+ * retrieved client-security information, the server can make
+ * access-validation decisions without being able to use other services
+ * that are using the client's security context.
+ */
+ public static final int SecurityIdentification = 1;
+
+ /**
+ * The server process can impersonate the client's security context on
+ * its local system. The server cannot impersonate the client on remote
+ * systems.
+ */
+ public static final int SecurityImpersonation = 2;
+
+ /**
+ * The server process can impersonate the client's security context on
+ * remote systems.
+ */
+ public static final int SecurityDelegation = 3;
+ }
+
+ /**
+ * The TOKEN_INFORMATION_CLASS enumeration type contains values that specify
+ * the type of information being assigned to or retrieved from an access
+ * token.
+ */
+ public abstract class TOKEN_INFORMATION_CLASS {
+ public static final int TokenUser = 1;
+ public static final int TokenGroups = 2;
+ public static final int TokenPrivileges = 3;
+ public static final int TokenOwner = 4;
+ public static final int TokenPrimaryGroup = 5;
+ public static final int TokenDefaultDacl = 6;
+ public static final int TokenSource = 7;
+ public static final int TokenType = 8;
+ public static final int TokenImpersonationLevel = 9;
+ public static final int TokenStatistics = 10;
+ public static final int TokenRestrictedSids = 11;
+ public static final int TokenSessionId = 12;
+ public static final int TokenGroupsAndPrivileges = 13;
+ public static final int TokenSessionReference = 14;
+ public static final int TokenSandBoxInert = 15;
+ public static final int TokenAuditPolicy = 16;
+ public static final int TokenOrigin = 17;
+ public static final int TokenElevationType = 18;
+ public static final int TokenLinkedToken = 19;
+ public static final int TokenElevation = 20;
+ public static final int TokenHasRestrictions = 21;
+ public static final int TokenAccessInformation = 22;
+ public static final int TokenVirtualizationAllowed = 23;
+ public static final int TokenVirtualizationEnabled = 24;
+ public static final int TokenIntegrityLevel = 25;
+ public static final int TokenUIAccess = 26;
+ public static final int TokenMandatoryPolicy = 27;
+ public static final int TokenLogonSid = 28;
+ }
+
+ /**
+ * The TOKEN_TYPE enumeration type contains values that differentiate
+ * between a primary token and an impersonation token.
+ */
+ public abstract class TOKEN_TYPE {
+ public static final int TokenPrimary = 1;
+ public static final int TokenImpersonation = 2;
+ }
+
+ /**
+ * The LUID_AND_ATTRIBUTES structure represents a locally unique identifier
+ * (LUID) and its attributes.
+ */
+ public static class LUID_AND_ATTRIBUTES extends Structure {
+ /**
+ * Specifies an LUID value.
+ */
+ public LUID Luid;
+
+ /**
+ * Specifies attributes of the LUID. This value contains up to 32
+ * one-bit flags. Its meaning is dependent on the definition and use of
+ * the LUID.
+ */
+ public DWORD Attributes;
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "Luid", "Attributes" });
+ }
+
+ public LUID_AND_ATTRIBUTES() {
+ }
+
+ public LUID_AND_ATTRIBUTES(LUID luid, DWORD attributes) {
+ this.Luid = luid;
+ this.Attributes = attributes;
+ }
+ }
+
+ /**
+ * The SID_AND_ATTRIBUTES structure represents a security identifier (SID)
+ * and its attributes. SIDs are used to uniquely identify users or groups.
+ */
+ public static class SID_AND_ATTRIBUTES extends Structure {
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "Sid", "Attributes" });
+ }
+
+ public SID_AND_ATTRIBUTES() {
+ super();
+ }
+
+ public SID_AND_ATTRIBUTES(Pointer memory) {
+ super(memory);
+ }
+
+ /**
+ * Pointer to a SID structure.
+ */
+ public PSID.ByReference Sid;
+
+ /**
+ * Specifies attributes of the SID. This value contains up to 32 one-bit
+ * flags. Its meaning depends on the definition and use of the SID.
+ */
+ public int Attributes;
+ }
+
+ /**
+ * The TOKEN_OWNER structure contains the default owner security identifier
+ * (SID) that will be applied to newly created objects.
+ */
+ public static class TOKEN_OWNER extends Structure {
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "Owner" });
+ }
+
+ public TOKEN_OWNER() {
+ super();
+ }
+
+ public TOKEN_OWNER(int size) {
+ super(new Memory(size));
+ }
+
+ public TOKEN_OWNER(Pointer memory) {
+ super(memory);
+ read();
+ }
+
+ /**
+ * Pointer to a SID structure representing a user who will become the
+ * owner of any objects created by a process using this access token.
+ * The SID must be one of the user or group SIDs already in the token.
+ */
+ public PSID.ByReference Owner; // PSID
+ }
+
+ public static class PSID extends Structure {
+ public static class ByReference extends PSID implements Structure.ByReference { }
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "sid" });
+ }
+
+ public PSID() {
+ super();
+ }
+
+ public PSID(byte[] data) {
+ super(new Memory(data.length));
+ getPointer().write(0, data, 0, data.length);
+ read();
+ }
+
+ public PSID(int size) {
+ super(new Memory(size));
+ }
+
+ public PSID(Pointer memory) {
+ super(memory);
+ read();
+ }
+
+ public byte[] getBytes() {
+ int len = Advapi32.INSTANCE.GetLengthSid(this);
+ return getPointer().getByteArray(0, len);
+ }
+
+ public Pointer sid;
+ }
+
+ public static class PSIDByReference extends ByReference {
+ public PSIDByReference() {
+ this(null);
+ }
+
+ public PSIDByReference(PSID h) {
+ super(Pointer.SIZE);
+ setValue(h);
+ }
+
+ public void setValue(PSID h) {
+ getPointer().setPointer(0, h != null ? h.getPointer() : null);
+ }
+
+ public PSID getValue() {
+ Pointer p = getPointer().getPointer(0);
+ if (p == null) {
+ return null;
+ }
+ else {
+ return new PSID(p);
+ }
+ }
+ }
+
+ /**
+ * The TOKEN_USER structure identifies the user associated with an access
+ * token.
+ */
+ public static class TOKEN_USER extends Structure {
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "User" });
+ }
+
+ public TOKEN_USER() {
+ super();
+ }
+
+ public TOKEN_USER(Pointer memory) {
+ super(memory);
+ read();
+ }
+
+ public TOKEN_USER(int size) {
+ super(new Memory(size));
+ }
+
+ /**
+ * Specifies a SID_AND_ATTRIBUTES structure representing the user
+ * associated with the access token. There are currently no attributes
+ * defined for user security identifiers (SIDs).
+ */
+ public SID_AND_ATTRIBUTES User;
+ }
+
+ /**
+ * The TOKEN_GROUPS structure contains information about the group security
+ * identifiers (SIDs) in an access token.
+ */
+ public static class TOKEN_GROUPS extends Structure {
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "GroupCount", "Group0" });
+ }
+
+ public TOKEN_GROUPS() {
+ super();
+ }
+
+ public TOKEN_GROUPS(Pointer memory) {
+ super(memory);
+ read();
+ }
+
+ public TOKEN_GROUPS(int size) {
+ super(new Memory(size));
+ }
+
+ /**
+ * Specifies the number of groups in the access token.
+ */
+ public int GroupCount;
+ public SID_AND_ATTRIBUTES Group0;
+
+ /**
+ * Specifies an array of SID_AND_ATTRIBUTES structures that contain a
+ * set of SIDs and corresponding attributes.
+ */
+ public SID_AND_ATTRIBUTES[] getGroups() {
+ return (SID_AND_ATTRIBUTES[]) Group0.toArray(GroupCount);
+ }
+ }
+
+ /**
+ * The TOKEN_PRIVILEGES structure contains information about a set of
+ * privileges for an access token.
+ */
+ public static class TOKEN_PRIVILEGES extends Structure {
+ /**
+ * This must be set to the number of entries in the Privileges array.
+ */
+ public DWORD PrivilegeCount;
+
+ /**
+ * Specifies an array of LUID_AND_ATTRIBUTES structures. Each structure
+ * contains the LUID and attributes of a privilege.
+ */
+ public LUID_AND_ATTRIBUTES Privileges[];
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "PrivilegeCount", "Privileges" });
+ }
+
+ /** Creates an empty instance with no privileges. */
+ public TOKEN_PRIVILEGES() {
+ this(0);
+ }
+ /**
+ * @param nbOfPrivileges
+ * Desired size of the Privileges array
+ */
+ public TOKEN_PRIVILEGES(int nbOfPrivileges) {
+ PrivilegeCount = new DWORD(nbOfPrivileges);
+ Privileges = new LUID_AND_ATTRIBUTES[nbOfPrivileges];
+ }
+
+ /** Initialize a TOKEN_PRIVILEGES instance from initialized memory. */
+ public TOKEN_PRIVILEGES(Pointer p) {
+ super(p);
+ int count = p.getInt(0);
+ PrivilegeCount = new DWORD(count);
+ Privileges = new LUID_AND_ATTRIBUTES[count];
+ read();
+ }
+ }
+
+ /**
+ * The SID_NAME_USE enumeration type contains values that specify the type
+ * of a security identifier (SID).
+ */
+ public abstract class SID_NAME_USE {
+ /**
+ * Indicates a user SID.
+ */
+ public static final int SidTypeUser = 1;
+
+ /**
+ * Indicates a group SID.
+ */
+ public static final int SidTypeGroup = 2;
+
+ /**
+ * Indicates a domain SID.
+ */
+ public static final int SidTypeDomain = 3;
+
+ /**
+ * Indicates an alias SID.
+ */
+ public static final int SidTypeAlias = 4;
+
+ /**
+ * Indicates a SID for a well-known group.
+ */
+ public static final int SidTypeWellKnownGroup = 5;
+
+ /**
+ * Indicates a SID for a deleted account.
+ */
+ public static final int SidTypeDeletedAccount = 6;
+
+ /**
+ * Indicates an invalid SID.
+ */
+ public static final int SidTypeInvalid = 7;
+
+ /**
+ * Indicates an unknown SID type.
+ */
+ public static final int SidTypeUnknown = 8;
+
+ /**
+ * Indicates a SID for a computer.
+ */
+ public static final int SidTypeComputer = 9;
+
+ /**
+ * ?
+ */
+ public static final int SidTypeLabel = 10;
+ }
+
+ /* File access rights */
+ int FILE_READ_DATA = 0x00000001;
+ int FILE_LIST_DIRECTORY = 0x00000001;
+ int FILE_WRITE_DATA = 0x00000002;
+ int FILE_ADD_FILE = 0x00000002;
+ int FILE_APPEND_DATA = 0x00000004;
+ int FILE_ADD_SUBDIRECTORY = 0x00000004;
+ int FILE_CREATE_PIPE_INSTANCE = 0x00000004;
+ int FILE_READ_EA = 0x00000008;
+ int FILE_WRITE_EA = 0x00000010;
+ int FILE_EXECUTE = 0x00000020;
+ int FILE_TRAVERSE = 0x00000020;
+ int FILE_DELETE_CHILD = 0x00000040;
+ int FILE_READ_ATTRIBUTES = 0x00000080;
+ int FILE_WRITE_ATTRIBUTES = 0x00000100;
+
+ int FILE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x000001FF;
+
+ int FILE_GENERIC_READ = STANDARD_RIGHTS_READ | SYNCHRONIZE | FILE_READ_DATA
+ | FILE_READ_ATTRIBUTES | FILE_READ_EA;
+
+ int FILE_GENERIC_WRITE = STANDARD_RIGHTS_WRITE | SYNCHRONIZE
+ | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA
+ | FILE_APPEND_DATA;
+
+ int FILE_GENERIC_EXECUTE = STANDARD_RIGHTS_EXECUTE | SYNCHRONIZE
+ | FILE_READ_ATTRIBUTES | FILE_EXECUTE;
+
+ int CREATE_NEW = 1;
+ int CREATE_ALWAYS = 2;
+ int OPEN_EXISTING = 3;
+ int OPEN_ALWAYS = 4;
+ int TRUNCATE_EXISTING = 5;
+
+ int FILE_FLAG_WRITE_THROUGH = 0x80000000;
+ int FILE_FLAG_OVERLAPPED = 0x40000000;
+ int FILE_FLAG_NO_BUFFERING = 0x20000000;
+ int FILE_FLAG_RANDOM_ACCESS = 0x10000000;
+ int FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;
+ int FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
+ int FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
+ int FILE_FLAG_POSIX_SEMANTICS = 0x01000000;
+ int FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000;
+ int FILE_FLAG_OPEN_NO_RECALL = 0x00100000;
+
+ //
+ // These are the generic rights.
+ //
+
+ int GENERIC_READ = 0x80000000;
+ int GENERIC_WRITE = 0x40000000;
+ int GENERIC_EXECUTE = 0x20000000;
+ int GENERIC_ALL = 0x10000000;
+
+ //
+ // AccessSystemAcl access type
+ //
+
+ int ACCESS_SYSTEM_SECURITY = 0x01000000;
+
+ int PAGE_READONLY = 0x02;
+ int PAGE_READWRITE = 0x04;
+ int PAGE_WRITECOPY = 0x08;
+ int PAGE_EXECUTE = 0x10;
+ int PAGE_EXECUTE_READ = 0x20;
+ int PAGE_EXECUTE_READWRITE = 0x40;
+
+ int SECTION_QUERY = 0x0001;
+ int SECTION_MAP_WRITE = 0x0002;
+ int SECTION_MAP_READ = 0x0004;
+ int SECTION_MAP_EXECUTE = 0x0008;
+ int SECTION_EXTEND_SIZE = 0x0010;
+
+ int FILE_SHARE_READ = 0x00000001;
+ int FILE_SHARE_WRITE = 0x00000002;
+ int FILE_SHARE_DELETE = 0x00000004;
+ int FILE_TYPE_CHAR = 0x0002;
+ int FILE_TYPE_DISK = 0x0001;
+ int FILE_TYPE_PIPE = 0x0003;
+ int FILE_TYPE_REMOTE = 0x8000;
+ int FILE_TYPE_UNKNOWN = 0x0000;
+ int FILE_ATTRIBUTE_READONLY = 0x00000001;
+ int FILE_ATTRIBUTE_HIDDEN = 0x00000002;
+ int FILE_ATTRIBUTE_SYSTEM = 0x00000004;
+ int FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
+ int FILE_ATTRIBUTE_ARCHIVE = 0x00000020;
+ int FILE_ATTRIBUTE_DEVICE = 0x00000040;
+ int FILE_ATTRIBUTE_NORMAL = 0x00000080;
+ int FILE_ATTRIBUTE_TEMPORARY = 0x00000100;
+ int FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200;
+ int FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400;
+ int FILE_ATTRIBUTE_COMPRESSED = 0x00000800;
+ int FILE_ATTRIBUTE_OFFLINE = 0x00001000;
+ int FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000;
+ int FILE_ATTRIBUTE_ENCRYPTED = 0x00004000;
+ int FILE_ATTRIBUTE_VIRTUAL = 0x00010000;
+ int FILE_NOTIFY_CHANGE_FILE_NAME = 0x00000001;
+ int FILE_NOTIFY_CHANGE_DIR_NAME = 0x00000002;
+ int FILE_NOTIFY_CHANGE_NAME = 0x00000003;
+ int FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x00000004;
+ int FILE_NOTIFY_CHANGE_SIZE = 0x00000008;
+ int FILE_NOTIFY_CHANGE_LAST_WRITE = 0x00000010;
+ int FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x00000020;
+ int FILE_NOTIFY_CHANGE_CREATION = 0x00000040;
+ int FILE_NOTIFY_CHANGE_SECURITY = 0x00000100;
+ int FILE_ACTION_ADDED = 0x00000001;
+ int FILE_ACTION_REMOVED = 0x00000002;
+ int FILE_ACTION_MODIFIED = 0x00000003;
+ int FILE_ACTION_RENAMED_OLD_NAME = 0x00000004;
+ int FILE_ACTION_RENAMED_NEW_NAME = 0x00000005;
+ int FILE_CASE_SENSITIVE_SEARCH = 0x00000001;
+ int FILE_CASE_PRESERVED_NAMES = 0x00000002;
+ int FILE_UNICODE_ON_DISK = 0x00000004;
+ int FILE_PERSISTENT_ACLS = 0x00000008;
+ int FILE_FILE_COMPRESSION = 0x00000010;
+ int FILE_VOLUME_QUOTAS = 0x00000020;
+ int FILE_SUPPORTS_SPARSE_FILES = 0x00000040;
+ int FILE_SUPPORTS_REPARSE_POINTS = 0x00000080;
+ int FILE_SUPPORTS_REMOTE_STORAGE = 0x00000100;
+ int FILE_VOLUME_IS_COMPRESSED = 0x00008000;
+ int FILE_SUPPORTS_OBJECT_IDS = 0x00010000;
+ int FILE_SUPPORTS_ENCRYPTION = 0x00020000;
+ int FILE_NAMED_STREAMS = 0x00040000;
+ int FILE_READ_ONLY_VOLUME = 0x00080000;
+ int FILE_SEQUENTIAL_WRITE_ONCE = 0x00100000;
+ int FILE_SUPPORTS_TRANSACTIONS = 0x00200000;
+
+ /**
+ * The FILE_NOTIFY_INFORMATION structure describes the changes found by the
+ * ReadDirectoryChangesW function.
+ *
+ * This structure is non-trivial since it is a pattern stamped into a large
+ * block of result memory rather than something that stands alone or is used
+ * for input.
+ */
+ public static class FILE_NOTIFY_INFORMATION extends Structure {
+ public int NextEntryOffset;
+ public int Action;
+ public int FileNameLength;
+ // filename is not nul-terminated, so we can't use a String/WString
+ public char[] FileName = new char[1];
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "NextEntryOffset", "Action", "FileNameLength", "FileName" });
+ }
+
+ private FILE_NOTIFY_INFORMATION() {
+ }
+
+ public FILE_NOTIFY_INFORMATION(int size) {
+ if (size < size()) {
+ throw new IllegalArgumentException("Size must greater than "
+ + size() + ", requested " + size);
+ }
+ allocateMemory(size);
+ }
+
+ /**
+ * WARNING: this filename may be either the short or long form of the
+ * filename.
+ */
+ public String getFilename() {
+ return new String(FileName, 0, FileNameLength / 2);
+ }
+
+ public void read() {
+ // avoid reading filename until we know how long it is
+ FileName = new char[0];
+ super.read();
+ FileName = getPointer().getCharArray(12, FileNameLength / 2);
+ }
+
+ public FILE_NOTIFY_INFORMATION next() {
+ if (NextEntryOffset == 0) {
+ return null;
+ }
+ FILE_NOTIFY_INFORMATION next = new FILE_NOTIFY_INFORMATION();
+ next.useMemory(getPointer(), NextEntryOffset);
+ next.read();
+ return next;
+ }
+ }
+
+ /**
+ * Registry options.
+ */
+ int KEY_QUERY_VALUE = 0x0001;
+ int KEY_SET_VALUE = 0x0002;
+ int KEY_CREATE_SUB_KEY = 0x0004;
+ int KEY_ENUMERATE_SUB_KEYS = 0x0008;
+ int KEY_NOTIFY = 0x0010;
+ int KEY_CREATE_LINK = 0x0020;
+ int KEY_WOW64_32KEY = 0x0200;
+ int KEY_WOW64_64KEY = 0x0100;
+ int KEY_WOW64_RES = 0x0300;
+
+ int KEY_READ = STANDARD_RIGHTS_READ | KEY_QUERY_VALUE
+ | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY & (~SYNCHRONIZE);
+
+ int KEY_WRITE = STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY
+ & (~SYNCHRONIZE);
+
+ int KEY_EXECUTE = KEY_READ & (~SYNCHRONIZE);
+
+ int KEY_ALL_ACCESS = STANDARD_RIGHTS_ALL | KEY_QUERY_VALUE | KEY_SET_VALUE
+ | KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY
+ | KEY_CREATE_LINK & (~SYNCHRONIZE);
+
+ //
+ // Open/Create Options
+ //
+
+ /**
+ * Parameter is reserved.
+ */
+ int REG_OPTION_RESERVED = 0x00000000;
+
+ /**
+ * Key is preserved when system is rebooted.
+ */
+ int REG_OPTION_NON_VOLATILE = 0x00000000;
+
+ /**
+ * Key is not preserved when system is rebooted.
+ */
+ int REG_OPTION_VOLATILE = 0x00000001;
+
+ /**
+ * Created key is a symbolic link.
+ */
+ int REG_OPTION_CREATE_LINK = 0x00000002;
+
+ /**
+ * Open for backup or restore special access rules privilege required.
+ */
+ int REG_OPTION_BACKUP_RESTORE = 0x00000004;
+
+ /**
+ * Open symbolic link.
+ */
+ int REG_OPTION_OPEN_LINK = 0x00000008;
+
+ int REG_LEGAL_OPTION = REG_OPTION_RESERVED | REG_OPTION_NON_VOLATILE
+ | REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK
+ | REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK;
+
+ //
+ // Key creation/open disposition
+ //
+
+ /**
+ * New Registry Key created.
+ */
+ int REG_CREATED_NEW_KEY = 0x00000001;
+
+ /**
+ * Existing Key opened.
+ */
+ int REG_OPENED_EXISTING_KEY = 0x00000002;
+
+ int REG_STANDARD_FORMAT = 1;
+ int REG_LATEST_FORMAT = 2;
+ int REG_NO_COMPRESSION = 4;
+
+ //
+ // Key restore & hive load flags
+ //
+
+ /**
+ * Restore whole hive volatile.
+ */
+ int REG_WHOLE_HIVE_VOLATILE = 0x00000001;
+
+ /**
+ * Unwind changes to last flush.
+ */
+ int REG_REFRESH_HIVE = 0x00000002;
+
+ /**
+ * Never lazy flush this hive.
+ */
+ int REG_NO_LAZY_FLUSH = 0x00000004;
+
+ /**
+ * Force the restore process even when we have open handles on subkeys.
+ */
+ int REG_FORCE_RESTORE = 0x00000008;
+
+ /**
+ * Loads the hive visible to the calling process.
+ */
+ int REG_APP_HIVE = 0x00000010;
+
+ /**
+ * Hive cannot be mounted by any other process while in use.
+ */
+ int REG_PROCESS_PRIVATE = 0x00000020;
+
+ /**
+ * Starts Hive Journal.
+ */
+ int REG_START_JOURNAL = 0x00000040;
+
+ /**
+ * Grow hive file in exact 4k increments.
+ */
+ int REG_HIVE_EXACT_FILE_GROWTH = 0x00000080;
+
+ /**
+ * No RM is started for this hive = no transactions.
+ */
+ int REG_HIVE_NO_RM = 0x00000100;
+
+ /**
+ * Legacy single logging is used for this hive.
+ */
+ int REG_HIVE_SINGLE_LOG = 0x00000200;
+
+ //
+ // Unload Flags
+ //
+
+ int REG_FORCE_UNLOAD = 1;
+
+ //
+ // Notify filter values
+ //
+
+ int REG_NOTIFY_CHANGE_NAME = 0x00000001;
+ int REG_NOTIFY_CHANGE_ATTRIBUTES = 0x00000002;
+ int REG_NOTIFY_CHANGE_LAST_SET = 0x00000004;
+ int REG_NOTIFY_CHANGE_SECURITY = 0x00000008;
+
+ int REG_LEGAL_CHANGE_FILTER = REG_NOTIFY_CHANGE_NAME
+ | REG_NOTIFY_CHANGE_ATTRIBUTES | REG_NOTIFY_CHANGE_LAST_SET
+ | REG_NOTIFY_CHANGE_SECURITY;
+
+ //
+ // Predefined Value Types.
+ //
+
+ /**
+ * No value type.
+ */
+ int REG_NONE = 0;
+
+ /**
+ * Unicode null-terminated string.
+ */
+ int REG_SZ = 1;
+
+ /**
+ * Unicode null-terminated string with environment variable references.
+ */
+ int REG_EXPAND_SZ = 2;
+
+ /**
+ * Free-formed binary.
+ */
+ int REG_BINARY = 3;
+
+ /**
+ * 32-bit number.
+ */
+ int REG_DWORD = 4;
+
+ /**
+ * 32-bit number, same as REG_DWORD.
+ */
+ int REG_DWORD_LITTLE_ENDIAN = 4;
+
+ /**
+ * 32-bit number.
+ */
+ int REG_DWORD_BIG_ENDIAN = 5;
+
+ /**
+ * Symbolic link (unicode).
+ */
+ int REG_LINK = 6;
+
+ /**
+ * Multiple unicode strings.
+ */
+ int REG_MULTI_SZ = 7;
+
+ /**
+ * Resource list in the resource map.
+ */
+ int REG_RESOURCE_LIST = 8;
+
+ /**
+ * Resource list in the hardware description.
+ */
+ int REG_FULL_RESOURCE_DESCRIPTOR = 9;
+
+ /**
+ *
+ */
+ int REG_RESOURCE_REQUIREMENTS_LIST = 10;
+
+ /**
+ * 64-bit number.
+ */
+ int REG_QWORD = 11;
+
+ /**
+ * 64-bit number, same as REG_QWORD.
+ */
+ int REG_QWORD_LITTLE_ENDIAN = 11;
+
+ /**
+ * A 64-bit value that is guaranteed to be unique on the operating system
+ * that generated it until the system is restarted.
+ */
+ public static class LUID extends Structure {
+ public int LowPart;
+ public int HighPart;
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "LowPart", "HighPart" });
+ }
+ }
+
+ /**
+ * A 64-bit integer;
+ */
+ public static class LARGE_INTEGER extends Structure {
+ public static class ByReference extends LARGE_INTEGER implements
+ Structure.ByReference {
+ }
+
+ public static class LowHigh extends Structure {
+ public DWORD LowPart;
+ public DWORD HighPart;
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "LowPart", "HighPart" });
+ }
+ }
+
+ public static class UNION extends Union {
+ public LowHigh lh;
+ public long value;
+ }
+
+ public UNION u;
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "u" });
+ }
+
+ /**
+ * Low DWORD.
+ *
+ * @return DWORD.
+ */
+ public DWORD getLow() {
+ return u.lh.LowPart;
+ }
+
+ /**
+ * High DWORD.
+ *
+ * @return DWORD.
+ */
+ public DWORD getHigh() {
+ return u.lh.HighPart;
+ }
+
+ /**
+ * 64-bit value.
+ *
+ * @return 64-bit value.
+ */
+ public long getValue() {
+ return u.value;
+ }
+ }
+
+ /**
+ * Handle to an object.
+ */
+ public static class HANDLE extends PointerType {
+ private boolean immutable;
+
+ public HANDLE() {
+ }
+
+ public HANDLE(Pointer p) {
+ setPointer(p);
+ immutable = true;
+ }
+
+ /** Override to the appropriate object for INVALID_HANDLE_VALUE. */
+ public Object fromNative(Object nativeValue, FromNativeContext context) {
+ Object o = super.fromNative(nativeValue, context);
+ if (WinBase.INVALID_HANDLE_VALUE.equals(o)) {
+ return WinBase.INVALID_HANDLE_VALUE;
+ }
+ return o;
+ }
+
+ public void setPointer(Pointer p) {
+ if (immutable) {
+ throw new UnsupportedOperationException("immutable reference");
+ }
+
+ super.setPointer(p);
+ }
+ }
+
+ /**
+ * LPHANDLE
+ */
+ public static class HANDLEByReference extends ByReference {
+ public HANDLEByReference() {
+ this(null);
+ }
+
+ public HANDLEByReference(HANDLE h) {
+ super(Pointer.SIZE);
+ setValue(h);
+ }
+
+ public void setValue(HANDLE h) {
+ getPointer().setPointer(0, h != null ? h.getPointer() : null);
+ }
+
+ public HANDLE getValue() {
+ Pointer p = getPointer().getPointer(0);
+ if (p == null) {
+ return null;
+ }
+ if (WinBase.INVALID_HANDLE_VALUE.getPointer().equals(p)) {
+ return WinBase.INVALID_HANDLE_VALUE;
+ }
+ HANDLE h = new HANDLE();
+ h.setPointer(p);
+ return h;
+ }
+ }
+
+ /**
+ * Return code used by interfaces. It is zero upon success and nonzero to
+ * represent an error code or status information.
+ */
+ class HRESULT extends NativeLong {
+ public HRESULT() {
+ }
+
+ public HRESULT(int value) {
+ super(value);
+ }
+ }
+
+ /**
+ * The WELL_KNOWN_SID_TYPE enumeration type is a list of commonly used
+ * security identifiers (SIDs). Programs can pass these values to the
+ * CreateWellKnownSid function to create a SID from this list.
+ */
+ public abstract class WELL_KNOWN_SID_TYPE {
+ /**
+ * Indicates a null SID.
+ */
+ public static final int WinNullSid = 0;
+
+ /**
+ * Indicates a SID that matches everyone.
+ */
+ public static final int WinWorldSid = 1;
+
+ /**
+ * Indicates a local SID.
+ */
+ public static final int WinLocalSid = 2;
+
+ /**
+ * Indicates a SID that matches the owner or creator of an object.
+ */
+ public static final int WinCreatorOwnerSid = 3;
+
+ /**
+ * Indicates a SID that matches the creator group of an object.
+ */
+ public static final int WinCreatorGroupSid = 4;
+
+ /**
+ * Indicates a creator owner server SID.
+ */
+ public static final int WinCreatorOwnerServerSid = 5;
+
+ /**
+ * Indicates a creator group server SID.
+ */
+ public static final int WinCreatorGroupServerSid = 6;
+
+ /**
+ * Indicates a SID for the Windows NT authority.
+ */
+ public static final int WinNtAuthoritySid = 7;
+
+ /**
+ * Indicates a SID for a dial-up account.
+ */
+ public static final int WinDialupSid = 8;
+
+ /**
+ * Indicates a SID for a network account. This SID is added to the
+ * process of a token when it logs on across a network. The
+ * corresponding logon type is LOGON32_LOGON_NETWORK.
+ */
+ public static final int WinNetworkSid = 9;
+
+ /**
+ * Indicates a SID for a batch process. This SID is added to the process
+ * of a token when it logs on as a batch job. The corresponding logon
+ * type is LOGON32_LOGON_BATCH.
+ */
+ public static final int WinBatchSid = 10;
+
+ /**
+ * Indicates a SID for an interactive account. This SID is added to the
+ * process of a token when it logs on interactively. The corresponding
+ * logon type is LOGON32_LOGON_INTERACTIVE.
+ */
+ public static final int WinInteractiveSid = 11;
+
+ /**
+ * Indicates a SID for a service. This SID is added to the process of a
+ * token when it logs on as a service. The corresponding logon type is
+ * LOGON32_LOGON_bSERVICE.
+ */
+ public static final int WinServiceSid = 12;
+
+ /**
+ * Indicates a SID for the anonymous account.
+ */
+ public static final int WinAnonymousSid = 13;
+
+ /**
+ * Indicates a proxy SID.
+ */
+ public static final int WinProxySid = 14;
+
+ /**
+ * Indicates a SID for an enterprise controller.
+ */
+ public static final int WinEnterpriseControllersSid = 15;
+
+ /**
+ * Indicates a SID for self.
+ */
+ public static final int WinSelfSid = 16;
+
+ /**
+ * Indicates a SID that matches any authenticated user.
+ */
+ public static final int WinAuthenticatedUserSid = 17;
+
+ /**
+ * Indicates a SID for restricted code.
+ */
+ public static final int WinRestrictedCodeSid = 18;
+
+ /**
+ * Indicates a SID that matches a terminal server account.
+ */
+ public static final int WinTerminalServerSid = 19;
+
+ /**
+ * Indicates a SID that matches remote logons.
+ */
+ public static final int WinRemoteLogonIdSid = 20;
+
+ /**
+ * Indicates a SID that matches logon IDs.
+ */
+ public static final int WinLogonIdsSid = 21;
+
+ /**
+ * Indicates a SID that matches the local system.
+ */
+ public static final int WinLocalSystemSid = 22;
+
+ /**
+ * Indicates a SID that matches a local service.
+ */
+ public static final int WinLocalServiceSid = 23;
+
+ /**
+ * Indicates a SID that matches a network service.
+ */
+ public static final int WinNetworkServiceSid = 24;
+
+ /**
+ * Indicates a SID that matches the domain account.
+ */
+ public static final int WinBuiltinDomainSid = 25;
+
+ /**
+ * Indicates a SID that matches the administrator account.
+ */
+ public static final int WinBuiltinAdministratorsSid = 26;
+
+ /**
+ * Indicates a SID that matches built-in user accounts.
+ */
+ public static final int WinBuiltinUsersSid = 27;
+
+ /**
+ * Indicates a SID that matches the guest account.
+ */
+ public static final int WinBuiltinGuestsSid = 28;
+
+ /**
+ * Indicates a SID that matches the power users group.
+ */
+ public static final int WinBuiltinPowerUsersSid = 29;
+
+ /**
+ * Indicates a SID that matches the account operators account.
+ */
+ public static final int WinBuiltinAccountOperatorsSid = 30;
+
+ /**
+ * Indicates a SID that matches the system operators group.
+ */
+ public static final int WinBuiltinSystemOperatorsSid = 31;
+
+ /**
+ * Indicates a SID that matches the print operators group.
+ */
+ public static final int WinBuiltinPrintOperatorsSid = 32;
+
+ /**
+ * Indicates a SID that matches the backup operators group.
+ */
+ public static final int WinBuiltinBackupOperatorsSid = 33;
+
+ /**
+ * Indicates a SID that matches the replicator account.
+ */
+ public static final int WinBuiltinReplicatorSid = 34;
+
+ /**
+ * Indicates a SID that matches pre-Windows 2000 compatible accounts.
+ */
+ public static final int WinBuiltinPreWindows2000CompatibleAccessSid = 35;
+
+ /**
+ * Indicates a SID that matches remote desktop users.
+ */
+ public static final int WinBuiltinRemoteDesktopUsersSid = 36;
+
+ /**
+ * Indicates a SID that matches the network operators group.
+ */
+ public static final int WinBuiltinNetworkConfigurationOperatorsSid = 37;
+
+ /**
+ * Indicates a SID that matches the account administrators group.
+ */
+ public static final int WinAccountAdministratorSid = 38;
+
+ /**
+ * Indicates a SID that matches the account guest group.
+ */
+ public static final int WinAccountGuestSid = 39;
+
+ /**
+ * Indicates a SID that matches account Kerberos target group.
+ */
+ public static final int WinAccountKrbtgtSid = 40;
+
+ /**
+ * Indicates a SID that matches the account domain administrator group.
+ */
+ public static final int WinAccountDomainAdminsSid = 41;
+
+ /**
+ * Indicates a SID that matches the account domain users group.
+ */
+ public static final int WinAccountDomainUsersSid = 42;
+
+ /**
+ * Indicates a SID that matches the account domain guests group.
+ */
+ public static final int WinAccountDomainGuestsSid = 43;
+
+ /**
+ * Indicates a SID that matches the account computer group.
+ */
+ public static final int WinAccountComputersSid = 44;
+
+ /**
+ * Indicates a SID that matches the account controller group.
+ */
+ public static final int WinAccountControllersSid = 45;
+
+ /**
+ * Indicates a SID that matches the certificate administrators group.
+ */
+ public static final int WinAccountCertAdminsSid = 46;
+
+ /**
+ * Indicates a SID that matches the schema administrators group.
+ */
+ public static final int WinAccountSchemaAdminsSid = 47;
+
+ /**
+ * Indicates a SID that matches the enterprise administrators group.
+ */
+ public static final int WinAccountEnterpriseAdminsSid = 48;
+
+ /**
+ * Indicates a SID that matches the policy administrators group.
+ */
+ public static final int WinAccountPolicyAdminsSid = 49;
+
+ /**
+ * Indicates a SID that matches the RAS and IAS server account.
+ */
+ public static final int WinAccountRasAndIasServersSid = 50;
+
+ /**
+ * Indicates a SID present when the Microsoft NTLM authentication
+ * package authenticated the client.
+ */
+ public static final int WinNTLMAuthenticationSid = 51;
+
+ /**
+ * Indicates a SID present when the Microsoft Digest authentication
+ * package authenticated the client.
+ */
+ public static final int WinDigestAuthenticationSid = 52;
+
+ /**
+ * Indicates a SID present when the Secure Channel (SSL/TLS)
+ * authentication package authenticated the client.
+ */
+ public static final int WinSChannelAuthenticationSid = 53;
+
+ /**
+ * Indicates a SID present when the user authenticated from within the
+ * forest or across a trust that does not have the selective
+ * authentication option enabled. If this SID is present, then
+ * WinOtherOrganizationSid cannot be present.
+ */
+ public static final int WinThisOrganizationSid = 54;
+
+ /**
+ * Indicates a SID present when the user authenticated across a forest
+ * with the selective authentication option enabled. If this SID is
+ * present, then WinThisOrganizationSid cannot be present.
+ */
+ public static final int WinOtherOrganizationSid = 55;
+
+ /**
+ * Indicates a SID that allows a user to create incoming forest trusts.
+ * It is added to the token of users who are a member of the Incoming
+ * Forest Trust Builders built-in group in the root domain of the
+ * forest.
+ */
+ public static final int WinBuiltinIncomingForestTrustBuildersSid = 56;
+
+ /**
+ * Indicates a SID that matches the performance monitor user group.
+ */
+ public static final int WinBuiltinPerfMonitoringUsersSid = 57;
+
+ /**
+ * Indicates a SID that matches the performance log user group.
+ */
+ public static final int WinBuiltinPerfLoggingUsersSid = 58;
+
+ /**
+ * Indicates a SID that matches the Windows Authorization Access group.
+ */
+ public static final int WinBuiltinAuthorizationAccessSid = 59;
+
+ /**
+ * Indicates a SID is present in a server that can issue Terminal Server
+ * licenses.
+ */
+ public static final int WinBuiltinTerminalServerLicenseServersSid = 60;
+
+ /**
+ *
+ */
+ public static final int WinBuiltinDCOMUsersSid = 61;
+
+ /**
+ *
+ */
+ public static final int WinBuiltinIUsersSid = 62;
+
+ /**
+ *
+ */
+ public static final int WinIUserSid = 63;
+
+ /**
+ *
+ */
+ public static final int WinBuiltinCryptoOperatorsSid = 64;
+
+ /**
+ *
+ */
+ public static final int WinUntrustedLabelSid = 65;
+
+ /**
+ *
+ */
+ public static final int WinLowLabelSid = 66;
+
+ /**
+ *
+ */
+ public static final int WinMediumLabelSid = 67;
+
+ /**
+ *
+ */
+ public static final int WinHighLabelSid = 68;
+
+ /**
+ *
+ */
+ public static final int WinSystemLabelSid = 69;
+
+ /**
+ *
+ */
+ public static final int WinWriteRestrictedCodeSid = 70;
+
+ /**
+ *
+ */
+ public static final int WinCreatorOwnerRightsSid = 71;
+
+ /**
+ *
+ */
+ public static final int WinCacheablePrincipalsGroupSid = 72;
+
+ /**
+ *
+ */
+ public static final int WinNonCacheablePrincipalsGroupSid = 73;
+
+ /**
+ *
+ */
+ public static final int WinEnterpriseReadonlyControllersSid = 74;
+
+ /**
+ * Indicates a SID that matches a read-only enterprise domain
+ * controller.
+ */
+ public static final int WinAccountReadonlyControllersSid = 75;
+
+ /**
+ * Indicates a SID that matches the built-in DCOM certification services
+ * access group.
+ */
+ public static final int WinBuiltinEventLogReadersGroup = 76;
+ }
+
+ /**
+ * Current SID revision level.
+ */
+ int SID_REVISION = 1;
+ int SID_MAX_SUB_AUTHORITIES = 15;
+ int SID_RECOMMENDED_SUB_AUTHORITIES = 1;
+
+ /**
+ * Maximum bytes used by a SID. (sizeof(SID) - sizeof(DWORD) +
+ * (SID_MAX_SUB_AUTHORITIES * sizeof(DWORD)))
+ */
+ int SECURITY_MAX_SID_SIZE = 68;
+
+ /**
+ * The OSVERSIONINFO data structure contains operating system version
+ * information. The information includes major and minor version numbers, a
+ * build number, a platform identifier, and descriptive text about the
+ * operating system. This structure is used with the GetVersionEx function.
+ */
+ public static class OSVERSIONINFO extends Structure {
+ /**
+ * Size of this data structure, in bytes. Set this member to
+ * sizeof(OSVERSIONINFO) before calling the GetVersionEx function.
+ */
+ public DWORD dwOSVersionInfoSize;
+
+ /**
+ * Major version number of the operating system.
+ */
+ public DWORD dwMajorVersion;
+
+ /**
+ * Minor version number of the operating system.
+ */
+ public DWORD dwMinorVersion;
+
+ /**
+ * Build number of the operating system.
+ */
+ public DWORD dwBuildNumber;
+
+ /**
+ * Operating system platform.
+ */
+ public DWORD dwPlatformId;
+
+ /**
+ * Pointer to a null-terminated string, such as "Service Pack 3", that
+ * indicates the latest Service Pack installed on the system.
+ */
+ public char szCSDVersion[];
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "dwOSVersionInfoSize", "dwMajorVersion", "dwMinorVersion", "dwBuildNumber", "dwPlatformId", "szCSDVersion" });
+ }
+
+ public OSVERSIONINFO() {
+ szCSDVersion = new char[128];
+ dwOSVersionInfoSize = new DWORD(size()); // sizeof(OSVERSIONINFO)
+ }
+
+ public OSVERSIONINFO(Pointer memory) {
+ super(memory);
+ read();
+ }
+ }
+
+ /**
+ * Contains operating system version information. The information includes
+ * major and minor version numbers, a build number, a platform identifier,
+ * and information about product suites and the latest Service Pack
+ * installed on the system.
+ */
+ public static class OSVERSIONINFOEX extends Structure {
+ /**
+ * The size of this data structure, in bytes.
+ */
+ public DWORD dwOSVersionInfoSize;
+
+ /**
+ * The major version number of the operating system.
+ */
+ public DWORD dwMajorVersion;
+
+ /**
+ * The minor version number of the operating system.
+ */
+ public DWORD dwMinorVersion;
+
+ /**
+ * The build number of the operating system.
+ */
+ public DWORD dwBuildNumber;
+
+ /**
+ * The operating system platform. This member can be
+ * VER_PLATFORM_WIN32_NT.
+ */
+ public DWORD dwPlatformId;
+
+ /**
+ * A null-terminated string, such as "Service Pack 3", that indicates
+ * the latest Service Pack installed on the system. If no Service Pack
+ * has been installed, the string is empty.
+ */
+ public char szCSDVersion[];
+
+ /**
+ * The major version number of the latest Service Pack installed on the
+ * system. For example, for Service Pack 3, the major version number is
+ * 3. If no Service Pack has been installed, the value is zero.
+ */
+ public WORD wServicePackMajor;
+
+ /**
+ * The minor version number of the latest Service Pack installed on the
+ * system. For example, for Service Pack 3, the minor version number is
+ * 0.
+ */
+ public WORD wServicePackMinor;
+
+ /**
+ * A bit mask that identifies the product suites available on the
+ * system.
+ */
+ public WORD wSuiteMask;
+
+ /**
+ * Any additional information about the system.
+ */
+ public byte wProductType;
+
+ /**
+ * Reserved for future use.
+ */
+ public byte wReserved;
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "dwOSVersionInfoSize", "dwMajorVersion", "dwMinorVersion", "dwBuildNumber", "dwPlatformId", "szCSDVersion", "wServicePackMajor", "wServicePackMinor", "wSuiteMask", "wProductType", "wReserved"});
+ }
+
+ public OSVERSIONINFOEX() {
+ szCSDVersion = new char[128];
+ dwOSVersionInfoSize = new DWORD(size()); // sizeof(OSVERSIONINFOEX)
+ }
+
+ public OSVERSIONINFOEX(Pointer memory) {
+ super(memory);
+ read();
+ }
+ }
+
+ int VER_EQUAL = 1;
+ int VER_GREATER = 2;
+ int VER_GREATER_EQUAL = 3;
+ int VER_LESS = 4;
+ int VER_LESS_EQUAL = 5;
+ int VER_AND = 6;
+ int VER_OR = 7;
+
+ int VER_CONDITION_MASK = 7;
+ int VER_NUM_BITS_PER_CONDITION_MASK = 3;
+
+ int VER_MINORVERSION = 0x0000001;
+ int VER_MAJORVERSION = 0x0000002;
+ int VER_BUILDNUMBER = 0x0000004;
+ int VER_PLATFORMID = 0x0000008;
+ int VER_SERVICEPACKMINOR = 0x0000010;
+ int VER_SERVICEPACKMAJOR = 0x0000020;
+ int VER_SUITENAME = 0x0000040;
+ int VER_PRODUCT_TYPE = 0x0000080;
+
+ int VER_NT_WORKSTATION = 0x0000001;
+ int VER_NT_DOMAIN_CONTROLLER = 0x0000002;
+ int VER_NT_SERVER = 0x0000003;
+
+ int VER_PLATFORM_WIN32s = 0;
+ int VER_PLATFORM_WIN32_WINDOWS = 1;
+ int VER_PLATFORM_WIN32_NT = 2;
+
+ /**
+ * Read the records sequentially. If this is the first read operation, the
+ * EVENTLOG_FORWARDS_READ EVENTLOG_BACKWARDS_READ flags determines which
+ * record is read first.
+ */
+ int EVENTLOG_SEQUENTIAL_READ = 0x0001;
+
+ /**
+ * Begin reading from the record specified in the dwRecordOffset parameter.
+ * This option may not work with large log files if the function cannot
+ * determine the log file's size. For details, see Knowledge Base article,
+ * 177199.
+ */
+ int EVENTLOG_SEEK_READ = 0x0002;
+
+ /**
+ * The log is read in chronological order (oldest to newest). The default.
+ */
+ int EVENTLOG_FORWARDS_READ = 0x0004;
+
+ /**
+ * The log is read in reverse chronological order (newest to oldest).
+ */
+ int EVENTLOG_BACKWARDS_READ = 0x0008;
+
+ /**
+ * Information event
+ */
+ int EVENTLOG_SUCCESS = 0x0000;
+
+ /**
+ * Error event
+ */
+ int EVENTLOG_ERROR_TYPE = 0x0001;
+
+ /**
+ * Warning event
+ */
+ int EVENTLOG_WARNING_TYPE = 0x0002;
+
+ /**
+ * Information event
+ */
+ int EVENTLOG_INFORMATION_TYPE = 0x0004;
+
+ /**
+ * Success Audit event
+ */
+ int EVENTLOG_AUDIT_SUCCESS = 0x0008;
+
+ /**
+ * Failure Audit event
+ */
+ int EVENTLOG_AUDIT_FAILURE = 0x0010;
+
+ /**
+ * The EVENTLOGRECORD structure contains information about an event record
+ * returned by the ReadEventLog function.
+ */
+ public static class EVENTLOGRECORD extends Structure {
+ /**
+ * Size of this event record, in bytes. Note that this value is stored
+ * at both ends of the entry to ease moving forward or backward through
+ * the log. The length includes any pad bytes inserted at the end of the
+ * record for DWORD alignment.
+ */
+ public DWORD Length;
+
+ /**
+ * Reserved.
+ */
+ public DWORD Reserved;
+
+ /**
+ * Record number of the record. This value can be used with the
+ * EVENTLOG_SEEK_READ flag in the ReadEventLog function to begin reading
+ * at a specified record.
+ */
+ public DWORD RecordNumber;
+
+ /**
+ * Time at which this entry was submitted. This time is measured in the
+ * number of seconds elapsed since 00:00:00 January 1, 1970, Universal
+ * Coordinated Time.
+ */
+ public DWORD TimeGenerated;
+
+ /**
+ * Time at which this entry was received by the service to be written to
+ * the log. This time is measured in the number of seconds elapsed since
+ * 00:00:00 January 1, 1970, Universal Coordinated Time.
+ */
+ public DWORD TimeWritten;
+
+ /**
+ * Event identifier. The value is specific to the event source for the
+ * event, and is used with source name to locate a description string in
+ * the message file for the event source.
+ */
+ public DWORD EventID;
+
+ /**
+ * Type of event.
+ */
+ public WORD EventType;
+
+ /**
+ * Number of strings present in the log (at the position indicated by
+ * StringOffset). These strings are merged into the message before it is
+ * displayed to the user.
+ */
+ public WORD NumStrings;
+
+ /**
+ * Category for this event. The meaning of this value depends on the
+ * event source.
+ */
+ public WORD EventCategory;
+
+ /**
+ * Reserved.
+ */
+ public WORD ReservedFlags;
+
+ /**
+ * Reserved.
+ */
+ public DWORD ClosingRecordNumber;
+
+ /**
+ * Offset of the description strings within this event log record.
+ */
+ public DWORD StringOffset;
+
+ /**
+ * Size of the UserSid member, in bytes. This value can be zero if no
+ * security identifier was provided.
+ */
+ public DWORD UserSidLength;
+
+ /**
+ * Offset of the security identifier (SID) within this event log record.
+ * To obtain the user name for this SID, use the LookupAccountSid
+ * function.
+ */
+ public DWORD UserSidOffset;
+
+ /**
+ * Size of the event-specific data (at the position indicated by
+ * DataOffset), in bytes.
+ */
+ public DWORD DataLength;
+
+ /**
+ * Offset of the event-specific information within this event log
+ * record, in bytes. This information could be something specific (a
+ * disk driver might log the number of retries, for example), followed
+ * by binary information specific to the event being logged and to the
+ * source that generated the entry.
+ */
+ public DWORD DataOffset;
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "Length", "Reserved", "RecordNumber", "TimeGenerated", "TimeWritten", "EventID", "EventType", "NumStrings", "EventCategory", "ReservedFlags", "ClosingRecordNumber", "StringOffset", "UserSidLength", "UserSidOffset", "DataLength", "DataOffset"});
+ }
+
+ public EVENTLOGRECORD() {
+ }
+
+ public EVENTLOGRECORD(Pointer p) {
+ super(p);
+ read();
+ }
+ }
+
+ //
+ // Service Types (Bit Mask)
+ //
+ int SERVICE_KERNEL_DRIVER = 0x00000001;
+ int SERVICE_FILE_SYSTEM_DRIVER = 0x00000002;
+ int SERVICE_ADAPTER = 0x00000004;
+ int SERVICE_RECOGNIZER_DRIVER = 0x00000008;
+ int SERVICE_DRIVER = SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER
+ | SERVICE_RECOGNIZER_DRIVER;
+ int SERVICE_WIN32_OWN_PROCESS = 0x00000010;
+ int SERVICE_WIN32_SHARE_PROCESS = 0x00000020;
+ int SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS;
+ int SERVICE_INTERACTIVE_PROCESS = 0x00000100;
+ int SERVICE_TYPE_ALL = SERVICE_WIN32 | SERVICE_ADAPTER | SERVICE_DRIVER
+ | SERVICE_INTERACTIVE_PROCESS;
+ int STATUS_PENDING = 0x00000103;
+
+ // Privilege Constants
+ String SE_CREATE_TOKEN_NAME = "SeCreateTokenPrivilege";
+ String SE_ASSIGNPRIMARYTOKEN_NAME = "SeAssignPrimaryTokenPrivilege";
+ String SE_LOCK_MEMORY_NAME = "SeLockMemoryPrivilege";
+ String SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege";
+ String SE_UNSOLICITED_INPUT_NAME = "SeUnsolicitedInputPrivilege";
+ String SE_MACHINE_ACCOUNT_NAME = "SeMachineAccountPrivilege";
+ String SE_TCB_NAME = "SeTcbPrivilege";
+ String SE_SECURITY_NAME = "SeSecurityPrivilege";
+ String SE_TAKE_OWNERSHIP_NAME = "SeTakeOwnershipPrivilege";
+ String SE_LOAD_DRIVER_NAME = "SeLoadDriverPrivilege";
+ String SE_SYSTEM_PROFILE_NAME = "SeSystemProfilePrivilege";
+ String SE_SYSTEMTIME_NAME = "SeSystemtimePrivilege";
+ String SE_PROF_SINGLE_PROCESS_NAME = "SeProfileSingleProcessPrivilege";
+ String SE_INC_BASE_PRIORITY_NAME = "SeIncreaseBasePriorityPrivilege";
+ String SE_CREATE_PAGEFILE_NAME = "SeCreatePagefilePrivilege";
+ String SE_CREATE_PERMANENT_NAME = "SeCreatePermanentPrivilege";
+ String SE_BACKUP_NAME = "SeBackupPrivilege";
+ String SE_RESTORE_NAME = "SeRestorePrivilege";
+ String SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
+ String SE_DEBUG_NAME = "SeDebugPrivilege";
+ String SE_AUDIT_NAME = "SeAuditPrivilege";
+ String SE_SYSTEM_ENVIRONMENT_NAME = "SeSystemEnvironmentPrivilege";
+ String SE_CHANGE_NOTIFY_NAME = "SeChangeNotifyPrivilege";
+ String SE_REMOTE_SHUTDOWN_NAME = "SeRemoteShutdownPrivilege";
+ String SE_UNDOCK_NAME = "SeUndockPrivilege";
+ String SE_SYNC_AGENT_NAME = "SeSyncAgentPrivilege";
+ String SE_ENABLE_DELEGATION_NAME = "SeEnableDelegationPrivilege";
+ String SE_MANAGE_VOLUME_NAME = "SeManageVolumePrivilege";
+ String SE_IMPERSONATE_NAME = "SeImpersonatePrivilege";
+ String SE_CREATE_GLOBAL_NAME = "SeCreateGlobalPrivilege";
+
+ int SE_PRIVILEGE_ENABLED_BY_DEFAULT = 0x00000001;
+ int SE_PRIVILEGE_ENABLED = 0x00000002;
+ int SE_PRIVILEGE_REMOVED = 0X00000004;
+ int SE_PRIVILEGE_USED_FOR_ACCESS = 0x80000000;
+
+ int PROCESS_TERMINATE = 0x00000001;
+ int PROCESS_SYNCHRONIZE = 0x00100000;
+
+ /* Security information types */
+ int OWNER_SECURITY_INFORMATION = 0x00000001;
+ int GROUP_SECURITY_INFORMATION = 0x00000002;
+ int DACL_SECURITY_INFORMATION = 0x00000004;
+ int SACL_SECURITY_INFORMATION = 0x00000008;
+ int LABEL_SECURITY_INFORMATION = 0x00000010;
+ int PROTECTED_DACL_SECURITY_INFORMATION = 0x80000000;
+ int PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000;
+ int UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000;
+ int UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000;
+
+ public static class SECURITY_DESCRIPTOR extends Structure {
+ public static class ByReference extends SECURITY_DESCRIPTOR implements
+ Structure.ByReference {
+ }
+
+ public SECURITY_DESCRIPTOR() {
+ }
+
+ public SECURITY_DESCRIPTOR(byte[] data) {
+ super();
+ this.data = data;
+ useMemory(new Memory(data.length));
+ }
+
+ public SECURITY_DESCRIPTOR(Pointer memory) {
+ super(memory);
+ read();
+ }
+
+ public byte[] data;
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "data" });
+ }
+ }
+
+ public static class ACL extends Structure {
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "AclRevision", "Sbz1", "AclSize", "AceCount", "Sbz2" });
+ }
+
+ public ACL() {
+ }
+
+ public ACL(Pointer pointer) {
+ super(pointer);
+ read();
+ ACEs = new ACCESS_ACEStructure[AceCount];
+ int offset = size();
+ for (int i = 0; i < AceCount; i++) {
+ Pointer share = pointer.share(offset);
+ // ACE_HEADER.AceType
+ final byte aceType = share.getByte(0);
+ ACCESS_ACEStructure ace = null;
+ switch (aceType) {
+ case ACCESS_ALLOWED_ACE_TYPE:
+ ace = new ACCESS_ALLOWED_ACE(share);
+ break;
+ case ACCESS_DENIED_ACE_TYPE:
+ ace = new ACCESS_DENIED_ACE(share);
+ break;
+ default:
+ throw new IllegalArgumentException("Unknwon ACE type "
+ + aceType);
+ }
+ ACEs[i] = ace;
+ offset += ace.AceSize;
+ }
+ }
+
+ public byte AclRevision;
+ public byte Sbz1;
+ public short AclSize;
+ public short AceCount;
+ public short Sbz2;
+
+ private ACCESS_ACEStructure[] ACEs;
+
+ public ACCESS_ACEStructure[] getACEStructures() {
+ return ACEs;
+ }
+ }
+
+ public static class SECURITY_DESCRIPTOR_RELATIVE extends Structure {
+ public static class ByReference extends SECURITY_DESCRIPTOR_RELATIVE
+ implements Structure.ByReference {
+ }
+
+ public byte Revision;
+ public byte Sbz1;
+ public short Control;
+ public int Owner;
+ public int Group;
+ public int Sacl;
+ public int Dacl;
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "Revision", "Sbz1", "Control", "Owner", "Group", "Sacl", "Dacl" });
+ }
+
+ private ACL DACL;
+
+ public SECURITY_DESCRIPTOR_RELATIVE() {
+ }
+
+ public SECURITY_DESCRIPTOR_RELATIVE(byte[] data) {
+ super(new Memory(data.length));
+ getPointer().write(0, data, 0, data.length);
+ setDacl();
+ }
+
+ public SECURITY_DESCRIPTOR_RELATIVE(Pointer p) {
+ super(p);
+ setDacl();
+ }
+
+ public ACL getDiscretionaryACL() {
+ return DACL;
+ }
+
+ private final void setDacl() {
+ read();
+ if (Dacl != 0) {
+ DACL = new ACL(getPointer().share(Dacl));
+ }
+ }
+ }
+
+ public static abstract class ACEStructure extends Structure {
+ public byte AceType;
+ public byte AceFlags;
+ public short AceSize;
+
+ PSID psid;
+
+ public ACEStructure() { }
+ public ACEStructure(Pointer p) {
+ super(p);
+ }
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "AceType", "AceFlags", "AceSize" });
+ }
+
+ public String getSidString() {
+ return Advapi32Util.convertSidToStringSid(psid);
+ }
+
+ public PSID getSID() {
+ return psid;
+ }
+ }
+
+ /* ACE header */
+ public static class ACE_HEADER extends ACEStructure {
+ public ACE_HEADER() { }
+ public ACE_HEADER(Pointer p) {
+ super(p);
+ read();
+ }
+ }
+
+ /**
+ * ACCESS_ALLOWED_ACE and ACCESS_DENIED_ACE have the same structure layout
+ */
+ public static abstract class ACCESS_ACEStructure extends ACEStructure {
+ protected List getFieldOrder() {
+ List list = new ArrayList(super.getFieldOrder());
+ list.addAll(Arrays.asList(new String[] { "Mask", "SidStart"}));
+ return list;
+ }
+ public ACCESS_ACEStructure() { }
+ public ACCESS_ACEStructure(Pointer p) {
+ super(p);
+ read();
+ // AceSize - size of public members of the structure + size of DWORD
+ // (SidStart)
+ int sizeOfSID = super.AceSize - size() + 4;
+ // ACE_HEADER + size of int (Mask)
+ int offsetOfSID = 4 + 4;
+ byte[] data = p.getByteArray(offsetOfSID, sizeOfSID);
+ psid = new PSID(data);
+ }
+
+ public int Mask;
+
+ /**
+ * first 4 bytes of the SID
+ */
+ public DWORD SidStart;
+ }
+
+ /* Access allowed ACE */
+ public static class ACCESS_ALLOWED_ACE extends ACCESS_ACEStructure {
+ public ACCESS_ALLOWED_ACE() { }
+ public ACCESS_ALLOWED_ACE(Pointer p) {
+ super(p);
+ }
+ }
+
+ /* Access denied ACE */
+ public static class ACCESS_DENIED_ACE extends ACCESS_ACEStructure {
+ public ACCESS_DENIED_ACE() { }
+ public ACCESS_DENIED_ACE(Pointer p) {
+ super(p);
+ }
+ }
+
+ /* ACE types */
+ byte ACCESS_ALLOWED_ACE_TYPE = 0x00;
+ byte ACCESS_DENIED_ACE_TYPE = 0x01;
+ byte SYSTEM_AUDIT_ACE_TYPE = 0x02;
+ byte SYSTEM_ALARM_ACE_TYPE = 0x03;
+ byte ACCESS_ALLOWED_COMPOUND_ACE_TYPE = 0x04;
+ byte ACCESS_ALLOWED_OBJECT_ACE_TYPE = 0x05;
+ byte ACCESS_DENIED_OBJECT_ACE_TYPE = 0x06;
+ byte SYSTEM_AUDIT_OBJECT_ACE_TYPE = 0x07;
+ byte SYSTEM_ALARM_OBJECT_ACE_TYPE = 0x08;
+ byte ACCESS_ALLOWED_CALLBACK_ACE_TYPE = 0x09;
+ byte ACCESS_DENIED_CALLBACK_ACE_TYPE = 0x0A;
+ byte ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE = 0x0B;
+ byte ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE = 0x0C;
+ byte SYSTEM_AUDIT_CALLBACK_ACE_TYPE = 0x0D;
+ byte SYSTEM_ALARM_CALLBACK_ACE_TYPE = 0x0E;
+ byte SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE = 0x0F;
+ byte SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE = 0x10;
+ byte SYSTEM_MANDATORY_LABEL_ACE_TYPE = 0x11;
+
+ /* ACE inherit flags */
+ byte OBJECT_INHERIT_ACE = 0x01;
+ byte CONTAINER_INHERIT_ACE = 0x02;
+ byte NO_PROPAGATE_INHERIT_ACE = 0x04;
+ byte INHERIT_ONLY_ACE = 0x08;
+ byte INHERITED_ACE = 0x10;
+ byte VALID_INHERIT_FLAGS = 0x1F;
+
+ // TODO: figure out how OVERLAPPED is used and apply an appropriate mapping
+ interface OVERLAPPED_COMPLETION_ROUTINE extends StdCallCallback {
+ void callback(int errorCode, int nBytesTransferred,
+ WinBase.OVERLAPPED overlapped);
+ }
+}
diff --git a/contrib/platform/test/com/sun/jna/platform/StructureFieldOrderTest.java b/contrib/platform/test/com/sun/jna/platform/StructureFieldOrderTest.java
new file mode 100644
index 0000000000..3790731f49
--- /dev/null
+++ b/contrib/platform/test/com/sun/jna/platform/StructureFieldOrderTest.java
@@ -0,0 +1,55 @@
+/* Copyright (c) 2007-2008 Timothy Wall, All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package com.sun.jna.platform;
+
+
+import com.sun.jna.Platform;
+import com.sun.jna.platform.unix.X11;
+import com.sun.jna.platform.win32.DBT;
+import junit.framework.TestCase;
+
+import com.sun.jna.StructureFieldOrderInspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class StructureFieldOrderTest extends TestCase {
+
+ public void testMethodGetFieldOrder() {
+ final List ignoreConstructorError = new ArrayList();
+
+ if (Platform.isWindows()) {
+ ignoreConstructorError.add(X11.class.getName() + "$");
+ }
+
+ ignoreConstructorError.add(DBT.DEV_BROADCAST_HANDLE.class.getName()); // manually validated by wolftobias
+ ignoreConstructorError.add(DBT.DEV_BROADCAST_PORT.class.getName()); // manually validated by wolftobias
+
+ StructureFieldOrderInspector.batchCheckStructureGetFieldOrder(FileUtils.class, ignoreConstructorError);
+ }
+
+// test below is helpful when investigating failure cause of a specific Structure class, it shows full causes and traces.
+/*
+ public void testMethodGetFieldOrderSingleClass() {
+ final List ignoreConstructorError = new ArrayList();
+
+ if (Platform.isWindows()) {
+ ignoreConstructorError.add(X11.class.getName() + "$");
+ }
+
+ StructureFieldOrderInspector.checkMethodGetFieldOrder(LMAccess.GROUP_INFO_3.class, ignoreConstructorError);
+ }
+//*/
+
+
+}
diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32Test.java
index 49e5d79be0..9b7bbb4e85 100644
--- a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32Test.java
+++ b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32Test.java
@@ -273,7 +273,10 @@ public void testImpersonateLoggedOnUser() {
userInfo.usri1_name = new WString("JNAAdvapi32TestImp");
userInfo.usri1_password = new WString("!JNAP$$Wrd0");
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
- assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null));
+ // ignore test if not able to add user (need to be administrator to do this).
+ if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null)) {
+ return;
+ }
try {
HANDLEByReference phUser = new HANDLEByReference();
try {
@@ -516,7 +519,16 @@ public void testReportEvent() {
String applicationEventLog = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application";
String jnaEventSource = "JNADevEventSource";
String jnaEventSourceRegistryPath = applicationEventLog + "\\" + jnaEventSource;
- Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, jnaEventSourceRegistryPath);
+ // ignore test if not able to create key (need to be administrator to do this).
+ try {
+ final boolean keyCreated = Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, jnaEventSourceRegistryPath);
+ if (!keyCreated) {
+ return;
+ }
+ } catch (Win32Exception e) {
+ return;
+ }
+
HANDLE h = Advapi32.INSTANCE.RegisterEventSource(null, jnaEventSource);
IntByReference before = new IntByReference();
assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, before));
diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java
index 4fbed4f75e..2411d7d166 100644
--- a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java
+++ b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java
@@ -109,10 +109,11 @@ public void testGetUserGroups() {
userInfo.usri1_name = new WString("JNANetapi32TestUser");
userInfo.usri1_password = new WString("!JNAP$$Wrd0");
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
+ // ignore test if not able to add user (need to be administrator to do this).
+ if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null)) {
+ return;
+ }
try {
- assertEquals("Error in NetUserAdd",
- LMErr.NERR_Success,
- Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null));
HANDLEByReference phUser = new HANDLEByReference();
try {
assertTrue(Advapi32.INSTANCE.LogonUser(userInfo.usri1_name.toString(),
@@ -142,9 +143,11 @@ public void testGetUserAccount() {
userInfo.usri1_name = new WString("JNANetapi32TestUser");
userInfo.usri1_password = new WString("!JNAP$$Wrd0");
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
+ // ignore test if not able to add user (need to be administrator to do this).
+ if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null)) {
+ return;
+ }
try {
- assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserAdd(
- null, 1, userInfo, null));
HANDLEByReference phUser = new HANDLEByReference();
try {
assertTrue(Advapi32.INSTANCE.LogonUser(userInfo.usri1_name.toString(),
diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Netapi32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/Netapi32Test.java
index 77a1d5a5ba..6521eb078c 100644
--- a/contrib/platform/test/com/sun/jna/platform/win32/Netapi32Test.java
+++ b/contrib/platform/test/com/sun/jna/platform/win32/Netapi32Test.java
@@ -21,7 +21,6 @@
import com.sun.jna.platform.win32.LMAccess.GROUP_USERS_INFO_0;
import com.sun.jna.platform.win32.LMAccess.LOCALGROUP_USERS_INFO_0;
import com.sun.jna.platform.win32.LMAccess.USER_INFO_1;
-import com.sun.jna.platform.win32.LMAccess.USER_INFO_10;
import com.sun.jna.platform.win32.NTSecApi.LSA_FOREST_TRUST_RECORD;
import com.sun.jna.platform.win32.NTSecApi.PLSA_FOREST_TRUST_INFORMATION;
import com.sun.jna.platform.win32.NTSecApi.PLSA_FOREST_TRUST_RECORD;
@@ -131,7 +130,7 @@ public void testNetGroupEnum() {
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
}
- public void testNetUserEnum1() {
+ public void testNetUserEnum() {
PointerByReference bufptr = new PointerByReference();
IntByReference entriesread = new IntByReference();
IntByReference totalentries = new IntByReference();
@@ -143,29 +142,17 @@ public void testNetUserEnum1() {
assertTrue(ui.usri1_name.length() > 0);
}
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
- }
-
- public void testNetUserEnum10() {
- PointerByReference bufptr = new PointerByReference();
- IntByReference entriesread = new IntByReference();
- IntByReference totalentries = new IntByReference();
- assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserEnum(
- null, 10, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries, null));
- USER_INFO_10 userinfo = new USER_INFO_10(bufptr.getValue());
- USER_INFO_10[] userinfos = (USER_INFO_10[]) userinfo.toArray(entriesread.getValue());
- for (USER_INFO_10 ui : userinfos) {
- assertTrue(ui.usri10_name.length() > 0);
- }
- assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
- }
+ }
public void testNetUserAdd() {
USER_INFO_1 userInfo = new USER_INFO_1();
userInfo.usri1_name = new WString("JNANetapi32TestUser");
userInfo.usri1_password = new WString("!JNAP$$Wrd0");
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
- assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserAdd(
- Kernel32Util.getComputerName(), 1, userInfo, null));
+ // ignore test if not able to add user (need to be administrator to do this).
+ if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(Kernel32Util.getComputerName(), 1, userInfo, null)) {
+ return;
+ }
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(
Kernel32Util.getComputerName(), userInfo.usri1_name.toString()));
}
@@ -175,8 +162,10 @@ public void testNetUserChangePassword() {
userInfo.usri1_name = new WString("JNANetapi32TestUser");
userInfo.usri1_password = new WString("!JNAP$$Wrd0");
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
- assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserAdd(
- Kernel32Util.getComputerName(), 1, userInfo, null));
+ // ignore test if not able to add user (need to be administrator to do this).
+ if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(Kernel32Util.getComputerName(), 1, userInfo, null)) {
+ return;
+ }
try {
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserChangePassword(
Kernel32Util.getComputerName(), userInfo.usri1_name.toString(), userInfo.usri1_password.toString(),
diff --git a/lib/test/dom4j-1.6.1.jar b/lib/test/dom4j-1.6.1.jar
new file mode 100644
index 0000000000..c8c4dbb92d
Binary files /dev/null and b/lib/test/dom4j-1.6.1.jar differ
diff --git a/lib/test/guava-11.0.2.jar b/lib/test/guava-11.0.2.jar
new file mode 100644
index 0000000000..c8c8d5dd6f
Binary files /dev/null and b/lib/test/guava-11.0.2.jar differ
diff --git a/lib/test/javassist-3.12.1.GA.jar b/lib/test/javassist-3.12.1.GA.jar
new file mode 100644
index 0000000000..aba1783b70
Binary files /dev/null and b/lib/test/javassist-3.12.1.GA.jar differ
diff --git a/lib/test/reflections-0.9.8.jar b/lib/test/reflections-0.9.8.jar
new file mode 100644
index 0000000000..d9b2b66edc
Binary files /dev/null and b/lib/test/reflections-0.9.8.jar differ
diff --git a/lib/test/slf4j-api-1.6.1.jar b/lib/test/slf4j-api-1.6.1.jar
new file mode 100644
index 0000000000..f1f4fdd214
Binary files /dev/null and b/lib/test/slf4j-api-1.6.1.jar differ
diff --git a/test/com/sun/jna/StructureFieldOrderInspector.java b/test/com/sun/jna/StructureFieldOrderInspector.java
new file mode 100644
index 0000000000..85918234bf
--- /dev/null
+++ b/test/com/sun/jna/StructureFieldOrderInspector.java
@@ -0,0 +1,196 @@
+package com.sun.jna;
+
+import org.reflections.Reflections;
+import org.reflections.scanners.ResourcesScanner;
+import org.reflections.scanners.SubTypesScanner;
+import org.reflections.util.ClasspathHelper;
+import org.reflections.util.ConfigurationBuilder;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Utility class for detecting missing {@link com.sun.jna.Structure#getFieldOrder()} methods.
+ *
+ * This class could be moved to the unit test tree, but them reusing it in the 'platform' project would require
+ * publishing this test tree.
+ *
+ * @author Dan Rollo
+ * Date: 1/17/13
+ * Time: 4:08 PM
+ */
+public final class StructureFieldOrderInspector {
+
+ private StructureFieldOrderInspector(){}
+
+ /**
+ * Search for Structure sub types in the source tree of the given class, and validate the getFieldOrder() method,
+ * and collects all errors into one exception.
+ *
+ * @param classDeclaredInSourceTreeToSearch a class who's source tree will be searched for Structure sub types.
+ * @param ignoreConstructorError list of classname prefixes for which to ignore construction errors.
+ */
+ public static void batchCheckStructureGetFieldOrder(final Class classDeclaredInSourceTreeToSearch,
+ final List ignoreConstructorError) {
+ final Set> classes = StructureFieldOrderInspector.findSubTypesOfStructure(classDeclaredInSourceTreeToSearch);
+
+ final List problems = new ArrayList();
+
+ for (final Class extends Structure> structureSubType : classes) {
+ try {
+ StructureFieldOrderInspector.checkMethodGetFieldOrder(structureSubType, ignoreConstructorError);
+ } catch (Throwable t) {
+ problems.add(t);
+ }
+ }
+
+ if (problems.size() > 0) {
+ String msg = "";
+ for (final Throwable t : problems) {
+ msg += t.getMessage() + "; \n";
+ }
+
+ throw new RuntimeException("Some Structure sub types (" + problems.size() + ") have problems with getFieldOrder(): \n" + msg);
+ }
+ }
+
+ /**
+ * Search for Structure sub types in the source tree of the given class, and validate the getFieldOrder() method.
+ *
+ * @param classDeclaredInSourceTreeToSearch a class who's source tree will be searched for Structure sub types.
+ * @param ignoreConstructorError list of classname prefixes for which to ignore construction errors.
+ */
+ public static void checkStructureGetFieldOrder(final Class classDeclaredInSourceTreeToSearch,
+ final List ignoreConstructorError) {
+ final Set> classes = StructureFieldOrderInspector.findSubTypesOfStructure(classDeclaredInSourceTreeToSearch);
+
+ for (final Class extends Structure> structureSubType : classes) {
+ StructureFieldOrderInspector.checkMethodGetFieldOrder(structureSubType, ignoreConstructorError);
+ }
+ }
+
+ /**
+ * Find all classes that extend {@link Structure}.
+ */
+ public static Set> findSubTypesOfStructure(final Class classDeclaredInSourceTreeToSearch) {
+
+ // use: http://code.google.com/p/reflections/
+
+ final Reflections reflections = new Reflections(new ConfigurationBuilder()
+ .setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
+ .setUrls(ClasspathHelper.forClass(classDeclaredInSourceTreeToSearch))
+ );
+
+ return reflections.getSubTypesOf(Structure.class);
+ }
+
+
+ public static void checkMethodGetFieldOrder(final Class extends Structure> structureSubType,
+ final List ignoreConstructorError) {
+
+ if (Structure.ByValue.class.isAssignableFrom(structureSubType)
+ || Structure.ByReference.class.isAssignableFrom(structureSubType)) {
+
+ // ignore tagging interfaces
+ return;
+ }
+
+ final Method methodGetFieldOrder = getMethodGetFieldOrder(structureSubType);
+
+
+ if (Modifier.isAbstract(structureSubType.getModifiers())) {
+ // do not try to construct abstract Structure sub types
+ return;
+ }
+ final Constructor extends Structure> structConstructor;
+ try {
+ structConstructor = structureSubType.getDeclaredConstructor();
+ } catch (NoSuchMethodException e) {
+ if (structureSubType == Structure.FFIType.class) {
+ // ignore this case
+ // @todo Allow user to pass in list of classes for which to skip construction?
+ return;
+ }
+ throw new RuntimeException("Parameterless constructor failed on Structure sub type: " + structureSubType.getName());
+ }
+
+ if (!structConstructor.isAccessible()) {
+ structConstructor.setAccessible(true);
+ }
+ final Structure structure;
+ try {
+ structure= structConstructor.newInstance();
+ } catch (InstantiationException e) {
+ throw new RuntimeException("Could not instantiate Structure sub type: " + structureSubType.getName(), e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Could not instantiate Structure sub type: " + structureSubType.getName(), e);
+ } catch (InvocationTargetException e) {
+ // this is triggered by checks in Structure.getFields(), and static loadlibrary() failures
+ if (ignoreConstructorError != null) {
+ final String structSubtypeName = structureSubType.getName();
+ for (final String classPrefix : ignoreConstructorError) {
+ if (structSubtypeName.startsWith(classPrefix)) {
+ return;
+ }
+ }
+ }
+ throw new RuntimeException("Could not instantiate Structure sub type: " + structureSubType.getName(), e);
+ }
+
+ if (!methodGetFieldOrder.isAccessible()) {
+ methodGetFieldOrder.setAccessible(true);
+ }
+ final List methodCallFieldList;
+ try {
+ methodCallFieldList = (List) methodGetFieldOrder.invoke(structure);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Could not invoke getFieldOrder() on Structure sub type: " + structureSubType.getName(), e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Could not invoke getFieldOrder() on Structure sub type: " + structureSubType.getName(), e);
+ }
+
+ final Field[] actualFields = structureSubType.getFields(); // include fields from super classes
+ final List actualFieldNames = new ArrayList(actualFields.length);
+ for (final Field field : actualFields) {
+ // ignore static fields
+ if (!Modifier.isStatic(field.getModifiers())) {
+ final String actualFieldName = field.getName();
+ if (!methodCallFieldList.contains(actualFieldName)) {
+ throw new IllegalArgumentException(structureSubType.getName() + ".getFieldOrder() [" + methodCallFieldList
+ + "] does not include declared field: " + actualFieldName);
+ }
+ actualFieldNames.add(actualFieldName);
+ }
+ }
+
+ for (final Object methodCallField : methodCallFieldList) {
+ if (!actualFieldNames.contains(methodCallField)) {
+ throw new IllegalArgumentException(structureSubType.getName() + ".getFieldOrder() [" + methodCallFieldList
+ + "] includes undeclared field: " + methodCallField);
+ }
+ }
+ }
+
+ /**
+ * Find the getFieldOrder() method in the given class, or any of it's parents.
+ * @param structureSubType a structure sub type
+ * @return the getFieldOrder() method found in the given class, or any of it's parents.
+ */
+ private static Method getMethodGetFieldOrder(Class extends Structure> structureSubType) {
+ final Method methodGetFieldOrder;
+ try {
+ methodGetFieldOrder = structureSubType.getDeclaredMethod("getFieldOrder", new Class[]{});
+ } catch (NoSuchMethodException e) {
+ if (structureSubType.getSuperclass() != null) {
+ // look for method in parent
+ return getMethodGetFieldOrder((Class extends Structure>) structureSubType.getSuperclass());
+ }
+ throw new IllegalArgumentException("The Structure sub type: " + structureSubType.getName()
+ + " must define the method: getFieldOrder()."
+ + " See the javadoc for Structure.getFieldOrder() for details.", e);
+ }
+ return methodGetFieldOrder;
+ }
+}
diff --git a/test/com/sun/jna/StructureFieldOrderInspectorTest.java b/test/com/sun/jna/StructureFieldOrderInspectorTest.java
new file mode 100644
index 0000000000..ee973c04cd
--- /dev/null
+++ b/test/com/sun/jna/StructureFieldOrderInspectorTest.java
@@ -0,0 +1,190 @@
+package com.sun.jna;
+
+import junit.framework.TestCase;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Test utility class for inspecting {@link com.sun.jna.Structure#getFieldOrder()} methods.
+ *
+ * @author Dan Rollo
+ * Date: 1/17/13
+ * Time: 4:29 PM
+ */
+public class StructureFieldOrderInspectorTest extends TestCase {
+
+ private String origPropJNANoSys;
+
+ protected void setUp() {
+ origPropJNANoSys = System.getProperty("jna.nosys");
+ System.setProperty("jna.nosys", "true"); // would be set by ant script, set here for IDE usage
+ }
+
+ protected void tearDown() {
+ if (origPropJNANoSys == null) {
+ System.getProperties().remove("jna.nosys");
+ } else {
+ System.setProperty("jna.nosys", origPropJNANoSys);
+ }
+ }
+
+
+ public void testFindStructureSubClasses() {
+
+ final Set> classes = StructureFieldOrderInspector.findSubTypesOfStructure(Platform.class);
+
+ assertTrue("Found no Structure sub types.", classes.size() > 0);
+
+ for (final Class extends Structure> structureSubType : classes) {
+ assertTrue(structureSubType.getName(), Structure.class.isAssignableFrom(structureSubType));
+ }
+ }
+
+ public void testCheckMethodGetFieldOrderExisting() {
+ StructureFieldOrderInspector.checkMethodGetFieldOrder(StructureByValueTest.TestNativeMappedInStructure.class, null);
+ }
+
+ public void testCheckMethodGetFieldOrderTagInterface() {
+ StructureFieldOrderInspector.checkMethodGetFieldOrder(StructureByValueTest.TestNativeMappedInStructure.ByValue.class, null);
+ }
+
+
+ private static final class MyStructMissingField extends Structure {
+ @SuppressWarnings("UnusedDeclaration")
+ public String missingDeclaredField;
+
+ @Override
+ protected List getFieldOrder() {
+ //noinspection unchecked
+ return Arrays.asList();
+ }
+ }
+ public void testCheckMethodGetFieldOrderMissingField() throws Exception {
+ try {
+ StructureFieldOrderInspector.checkMethodGetFieldOrder(MyStructMissingField.class, null);
+ fail("Expected Error: Structure.getFieldOrder()...");
+ } catch (RuntimeException e) {
+ assertTrue(e.getCause().getCause().getMessage().contains("not match declared field names"));
+ }
+ }
+
+ private static final class MyStructExtraField extends Structure {
+ @Override
+ protected List getFieldOrder() {
+ return Arrays.asList("extraField");
+ }
+ }
+ public void testCheckMethodGetFieldOrderExtraField() throws Exception {
+ try {
+ StructureFieldOrderInspector.checkMethodGetFieldOrder(MyStructExtraField.class, null);
+ fail("Expected Error: Structure.getFieldOrder()...");
+ } catch (RuntimeException e) {
+ assertTrue(e.getCause().getCause().getMessage().contains("not match declared field names"));
+ }
+ }
+
+ private static final class MyStructStaticFieldOnlyStatic extends Structure {
+ public static long myStaticField = -1;
+
+ @Override
+ protected List getFieldOrder() {
+ return Arrays.asList();
+ }
+ }
+ /**
+ * //@todo Seems this may be a bug. Error below occurs if Structure has no instance field (and only a static field), like: MyStructStaticFieldOnlyStatic.
+ java.lang.RuntimeException: Could not instantiate Structure sub type: com.sun.jna.StructureFieldOrderInspectorTest$MyStructStaticFieldOnlyStatic
+ at com.sun.jna.StructureFieldOrderInspector.checkMethodGetFieldOrder(StructureFieldOrderInspector.java:146)
+ at com.sun.jna.StructureFieldOrderInspectorTest.testCheckMethodGetFieldOrderStaticFieldOnlyStatic(StructureFieldOrderInspectorTest.java:111)
+ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
+ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
+ at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:139)
+ at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:52)
+ at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
+ at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
+ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
+ at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
+ Caused by: java.lang.reflect.InvocationTargetException
+ at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
+ at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
+ at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
+ at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
+ at com.sun.jna.StructureFieldOrderInspector.checkMethodGetFieldOrder(StructureFieldOrderInspector.java:131)
+ ... 22 more
+ Caused by: java.lang.IllegalArgumentException: Structure class com.sun.jna.StructureFieldOrderInspectorTest$MyStructStaticFieldOnlyStatic has unknown size (ensure all fields are public)
+ at com.sun.jna.Structure.deriveLayout(Structure.java:1108)
+ at com.sun.jna.Structure.calculateSize(Structure.java:908)
+ at com.sun.jna.Structure.calculateSize(Structure.java:896)
+ at com.sun.jna.Structure.allocateMemory(Structure.java:357)
+ at com.sun.jna.Structure.(Structure.java:191)
+ at com.sun.jna.Structure.(Structure.java:180)
+ at com.sun.jna.Structure.(Structure.java:167)
+ at com.sun.jna.Structure.(Structure.java:159)
+ at com.sun.jna.StructureFieldOrderInspectorTest$MyStructStaticFieldOnlyStatic.(StructureFieldOrderInspectorTest.java:89)
+ ... 27 more
+ */
+/*
+ public void testCheckMethodGetFieldOrderStaticFieldOnlyStatic() throws Exception {
+ StructureFieldOrderInspector.checkMethodGetFieldOrder(MyStructStaticFieldOnlyStatic.class, null);
+ }
+//*/
+
+ private static final class MyStructStaticField extends Structure {
+ public long instanceField; // @todo Why error if at least one instance field does not exist? see above:MyStructStaticFieldOnlyStatic
+ public static long myStaticField = -1;
+
+ @Override
+ protected List getFieldOrder() {
+ //return Arrays.asList();
+ return Arrays.asList("instanceField");
+ }
+ }
+ public void testCheckMethodGetFieldOrderStaticField() throws Exception {
+ StructureFieldOrderInspector.checkMethodGetFieldOrder(MyStructStaticField.class, null);
+ }
+
+
+ private static class MyStructSuper extends Structure {
+ public long instanceField;
+
+ @Override
+ protected List getFieldOrder() {
+ //return Arrays.asList();
+ return Arrays.asList("instanceField");
+ }
+ }
+ private static final class MyStructChildEmpty extends MyStructSuper {
+ }
+ public void testCheckMethodGetFieldOrderSuperImplOnly() throws Exception {
+ StructureFieldOrderInspector.checkMethodGetFieldOrder(MyStructChildEmpty.class, null);
+ }
+
+
+ public void testCheckMethodGetFieldOrderWithAbstractSubtype() throws Exception {
+ StructureFieldOrderInspector.checkMethodGetFieldOrder(Union.class, null);
+ }
+
+ public void testCheckMethodGetFieldOrderWithIgnoreCtorError() throws Exception {
+ final List ignoreConstructorError = new ArrayList();
+ ignoreConstructorError.add(StructureFieldOrderInspectorTest.class.getName());
+ StructureFieldOrderInspector.checkMethodGetFieldOrder(MyStructExtraField.class, ignoreConstructorError);
+ }
+
+ public void testCheckStructureGetFieldOrder() throws Exception {
+ StructureFieldOrderInspector.checkStructureGetFieldOrder(Platform.class, null);
+ }
+
+ public void testBatchCheckStructureGetFieldOrder() throws Exception {
+ try {
+ StructureFieldOrderInspector.batchCheckStructureGetFieldOrder(StructureTest.class, null);
+ fail("Expected structure failures");
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().startsWith("Some Structure sub types"));
+ }
+ }
+}