Comparar commits
410 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| 3727f9583b | |||
| 4a6bbf0b3c | |||
| 7513a7157f | |||
| e7dbdb6ead | |||
| db5f101bfc | |||
| 3c06e8b6fd | |||
| 28f94cbd0b | |||
| 6f37cbd946 | |||
| 396281263b | |||
| a00e8ac201 | |||
| b1772a89c1 | |||
| 58f07ff045 | |||
| 12f99d4fc7 | |||
| 05da0a6877 | |||
| 46ce871f34 | |||
| 4b22c2f044 | |||
| 4014828eff | |||
| bc87a62d59 | |||
| f6862442d3 | |||
| bff7f57eb8 | |||
| e19024ca0d | |||
| 73997e4799 | |||
| ffa97aa438 | |||
| d08244dfd8 | |||
| 2e0d367045 | |||
| 0f1fb2e6a1 | |||
| 672e362ed8 | |||
| bcae16c441 | |||
| 19b8f5cb59 | |||
| 68b37156d8 | |||
| d9237b64c0 | |||
| da037b38e3 | |||
| 62f864f4ab | |||
| bf89f1d37d | |||
| 3dc986e609 | |||
| 2f5e874201 | |||
| 05291932f8 | |||
| 72aa450ecb | |||
| 926ea21fe0 | |||
| 657a077cdb | |||
| 9a90f56845 | |||
| 7d36e0d63b | |||
| 865d5ed7a1 | |||
| 9dd91ee17e | |||
| 425ea821d7 | |||
| bea5049a2f | |||
| eae1e34696 | |||
| e63b6b00bc | |||
| e5b3ed226b | |||
| d5ce354c87 | |||
| e280838989 | |||
| 2309054b1f | |||
| 9dcc44a76b | |||
| 7a417c6d3b | |||
| 425ab15ae1 | |||
| c75ff4f118 | |||
| 75d3dd19ec | |||
| 4cd556555e | |||
| feebe921af | |||
| 92929308bd | |||
| ca4f14b555 | |||
| a7bcfacbd9 | |||
| e097b4820d | |||
| 566ec7974c | |||
| c735d6c420 | |||
| cf54ca9551 | |||
| 9f1da1b562 | |||
| f5a3dbf82b | |||
| 89f83e796a | |||
| 977a9e49c5 | |||
| 7ee0a4b39f | |||
| 4268e3a1d2 | |||
| 860b9a266a | |||
| c39d752ccb | |||
| 15db1cf385 | |||
| 38d684d1e6 | |||
| ccb1bc514b | |||
| 27c46a2c8e | |||
| ff2f1d237a | |||
| 402f4c162c | |||
| 81013a98b4 | |||
| 971dd622c7 | |||
| 0045d31e2d | |||
| caef8f4ebc | |||
| 6116c1ae71 | |||
| 03ecf2b0bb | |||
| d4a5005273 | |||
| 7522f29f0a | |||
| 09f0a2e4a6 | |||
| aa846929f3 | |||
| b378af7cb1 | |||
| 8b549a487f | |||
| 005f659eaa | |||
| a5aad94f24 | |||
| 52a6926da3 | |||
| b3c0f003bb | |||
| 3d2360bc56 | |||
| 1267f51d8c | |||
| e7328001a4 | |||
| fc7b53e809 | |||
| 50637cb3c2 | |||
| 11b4203874 | |||
| 60beb432eb | |||
| 64331c9cf0 | |||
| 00088d4093 | |||
| 472f3660e0 | |||
| 3c13cc8c4d | |||
| 0792ac8eee | |||
| 4952af4ffe | |||
| 3fcca7ef56 | |||
| e93244fef2 | |||
| acf75ce7fe | |||
| 7560b6e53d | |||
| f5346bbec2 | |||
| 41958889fb | |||
| d439a7811d | |||
| 4951c00d23 | |||
| 202cd0d45e | |||
| 1502db6095 | |||
| e8eea9e68e | |||
| 396eb9f283 | |||
| 378f400226 | |||
| 37e02dfbd5 | |||
| dce66ec8ec | |||
| 2fef67a08d | |||
| 50a17583c7 | |||
| bfe2c7df83 | |||
| b3186dde12 | |||
| 628a33eb76 | |||
| 4373e66b1e | |||
| 2e67b0ad9f | |||
| a4cbe0635f | |||
| 8563419280 | |||
| 0974bd4a90 | |||
| e1d47adc99 | |||
| e5e171d913 | |||
| 1e313227b8 | |||
| 8d45a9e0cd | |||
| 95568d76d3 | |||
| d4a3442468 | |||
| e262de22ea | |||
| 49243f1891 | |||
| 1a099ba549 | |||
| 2367133b4f | |||
| c648a1933d | |||
| 598acf08da | |||
| 208a8dee90 | |||
| e9fb299565 | |||
| 17a514ecd0 | |||
| 38ac62cedd | |||
| ce280731af | |||
| 751fb57f71 | |||
| be7d90abbf | |||
| d59585dd4f | |||
| 7a695707a2 | |||
| 4e590c9450 | |||
| b069d1c9e9 | |||
| 9fa1f7b981 | |||
| 4a68e4cd9d | |||
| 8320b6fd7c | |||
| e40cf0a1c4 | |||
| 19106985d7 | |||
| 3d817c54da | |||
| ca31877107 | |||
| f5f9afefb0 | |||
| d42863603e | |||
| 2c19cf3e31 | |||
| e7dc918c6a | |||
| 64c9e8212a | |||
| 499c39f13d | |||
| bccdae735b | |||
| 58120730a5 | |||
| 5b8db8a680 | |||
| 0acfd583c8 | |||
| 402b7ef67e | |||
| 6944871c42 | |||
| b60da35689 | |||
| 5204feddb1 | |||
| 68156df66b | |||
| a9e8b27285 | |||
| b8f470ddbd | |||
| 9d075dd1d1 | |||
| 4b802c6f60 | |||
| 8ce9344dd0 | |||
| cb2b386791 | |||
| 7ee4681c10 | |||
| 82c0ea9df2 | |||
| 9070d80880 | |||
| 45c53caf94 | |||
| c4947618c1 | |||
| 941ed59c37 | |||
| d76bbec1ab | |||
| f5a1d98cf9 | |||
| b0e6d837f0 | |||
| b1cfb1b733 | |||
| 26a1212546 | |||
| 03b05aaae9 | |||
| f41c87d7c9 | |||
| b74deb5e35 | |||
| 240e2db637 | |||
| 441947b6a4 | |||
| 194bdaffcd | |||
| db6e9ff4c6 | |||
| 57261a1164 | |||
| 0b116bb409 | |||
| a5ad2e5de2 | |||
| b6928ff6c0 | |||
| 4b03dd321c | |||
| f7eefbd3d7 | |||
| b23f7f9b27 | |||
| b95bc7e4c4 | |||
| 1593c0c347 | |||
| c154663455 | |||
| 13bc1901dc | |||
| 4f28322ac2 | |||
| 756e2ced8b | |||
| 1dc78b5209 | |||
| 3464093273 | |||
| 4487214494 | |||
| 6d7e222946 | |||
| d12a6a3178 | |||
| ed9d609c35 | |||
| b86f359d93 | |||
| 02080dfcf8 | |||
| 2768d25884 | |||
| 7bdf9896d2 | |||
| 3b4f84ded8 | |||
| 69abc52731 | |||
| 1671b1fb8b | |||
| 8735f4ef5c | |||
| 86967b5786 | |||
| ca8ceeb130 | |||
| 41d6f8eeea | |||
| 27b7805608 | |||
| fef39f7013 | |||
| b414b54c6b | |||
| ccdbb20ad0 | |||
| eb7e47bf29 | |||
| 53988c7184 | |||
| 9092b2bdc5 | |||
| 068353aa5b | |||
| 95a17ddbf0 | |||
| 6c8c455f5b | |||
| 282032e178 | |||
| af63e6a80d | |||
| a46ba0da29 | |||
| f7738bf65b | |||
| bb11d1fe37 | |||
| d02a2deb52 | |||
| 46105d849d | |||
| f16b6c3482 | |||
| a9cb497045 | |||
| d529a34ecb | |||
| 5394029dc5 | |||
| 28247737ca | |||
| 6448c2d8fb | |||
| 4460ccc8ec | |||
| 2b02a3c533 | |||
| 6705513b86 | |||
| 4bd8d12481 | |||
| ccaf3c283b | |||
| ce4276a0cb | |||
| 709e316e56 | |||
| e46635d6ab | |||
| 0af8677ba4 | |||
| 9ab13daf09 | |||
| 17977fbabc | |||
| 83854047b7 | |||
| 28e56fd587 | |||
| 29fc6308b8 | |||
| 14a7df128d | |||
| dd4ef89d0a | |||
| 830ec91cbf | |||
| aee2d55fab | |||
| 89ed7982e7 | |||
| 9f702c89ab | |||
| 2f76efd0f6 | |||
| fae18c72c3 | |||
| 1586f6ee2b | |||
| 4ce6214526 | |||
| e370e4b65e | |||
| 944de2d3f5 | |||
| f32146368d | |||
| 8d45e9b016 | |||
| 70227861ff | |||
| 20e542516b | |||
| 73ad21df73 | |||
| a67fe7e43d | |||
| a15ddd9f88 | |||
| b27f9bf930 | |||
| d5c28f98f1 | |||
| 16b283ed00 | |||
| 97b43889a1 | |||
| 05efa12411 | |||
| 3e60495232 | |||
| 45522b0710 | |||
| d67d25eb7b | |||
| 2538690fb4 | |||
| 4c23b2518e | |||
| 9daade9816 | |||
| 5f925f0070 | |||
| 38b0cd7780 | |||
| e46391042b | |||
| 553a03b05f | |||
| 24c1cc4efe | |||
| f6eabe7b58 | |||
| de2de1fdc7 | |||
| 8184ac8843 | |||
| a57d82d4cd | |||
| a266ef7337 | |||
| b30ca23180 | |||
| db5c8f00fc | |||
| d1bbacb06e | |||
| bff4e3b0fd | |||
| 14248ddbd9 | |||
| 391f39d291 | |||
| b4354efa8b | |||
| 686588a6e5 | |||
| 294267a605 | |||
| 7b53b9108b | |||
| 15be9ab501 | |||
| 7cfcd2daef | |||
| 6070429eec | |||
| b5f41ef6c7 | |||
| 716588a8fb | |||
| 95bc92f005 | |||
| 23425abe9d | |||
| 3bab5e1e78 | |||
| 79ed7e81b1 | |||
| a59e58cc94 | |||
| 72bd12e394 | |||
| 2c667ca016 | |||
| 209c4d724f | |||
| 95cf641f50 | |||
| 85750fd065 | |||
| 402b5c7f81 | |||
| be6f52b796 | |||
| f4e6c6ad94 | |||
| 99fe59cee9 | |||
| 0e80ba8b91 | |||
| 8965efdce1 | |||
| 1393a94804 | |||
| 52e558d877 | |||
| d9948105f1 | |||
| 87c91c1c04 | |||
| f15e471371 | |||
| fc0a83933d | |||
| f1cf2fe218 | |||
| 7a5679cb65 | |||
| 571b4604db | |||
| 29e15a40db | |||
| 6fb2286fa4 | |||
| ab2f78c7b4 | |||
| f9b918a05b | |||
| a46cde174a | |||
| 6eee0f8741 | |||
| 28d31bb9f6 | |||
| 23128be17f | |||
| 130885fda7 | |||
| c4fc42f8f4 | |||
| 21e73c5fb9 | |||
| b635bf5591 | |||
| be594bb1f6 | |||
| 543e3fca98 | |||
| b385d76dc6 | |||
| 2adc88fec3 | |||
| 2a9e2ceb61 | |||
| 47fa804469 | |||
| f70c01eee7 | |||
| eb4ea07a2d | |||
| 55cd72baaa | |||
| 940076d101 | |||
| 93ebb9f7a9 | |||
| 1a17ea52d8 | |||
| 68bc0c0c7c | |||
| 0e7dd6b350 | |||
| b3b0bf3845 | |||
| ddc32f1e43 | |||
| c9de508a2c | |||
| fac68bca4e | |||
| eaf250c3c6 | |||
| 8b99772d29 | |||
| 862a32e97e | |||
| 6cfb84d6ee | |||
| 2fda7ca6f6 | |||
| f2aecb53bc | |||
| 05fdc2f17a | |||
| b9868b993c | |||
| 573d8eefd1 | |||
| 51d64f29e6 | |||
| a39ab60ae5 | |||
| ba9671fae5 | |||
| a9340f354d | |||
| f9d6b069f7 | |||
| c363d5790d | |||
| 15a50d2a26 | |||
| bffc188151 | |||
| e78205430c | |||
| 4ef76d4f85 | |||
| 967da46793 | |||
| 46899503bd | |||
| 2dcf0f774c | |||
| d669db0cab | |||
| f8aabcc50a | |||
| 4bb3ece8dc | |||
| 495a7765d2 | |||
| 225296f253 | |||
| 52e6900e7a | |||
| 557bff1465 | |||
| add32ac107 |
+8
-8
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" output="build.eclipse/test-classes" path="test"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JDK 1.5"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||
<classpathentry kind="output" path="build.eclipse/classes"/>
|
||||
</classpath>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" output="build.eclipse/test-classes" path="test"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||
<classpathentry kind="output" path="build.eclipse/classes"/>
|
||||
</classpath>
|
||||
|
||||
+73
-53
@@ -18,40 +18,40 @@
|
||||
* get system process information, basic process control
|
||||
* additional file utilities (meta info, free space, etc)
|
||||
* enforce window minimum/maximum size (workaround java bug)
|
||||
* OSX ObjC access
|
||||
|
||||
# TODO
|
||||
|
||||
* write structure to contiguous Java array, then write all at once to minimize
|
||||
native calls. Otherwise, structs with lots of fields take a big performance
|
||||
hit making a native call for each field.
|
||||
* fix setFieldOrder to *always* apply if used
|
||||
* cache structure information
|
||||
|
||||
* parser (gluegen? swig? others?) to auto-generate JNA interfaces from headers;
|
||||
ideally get the native library build system to output preprocessed headers,
|
||||
otherwise CPP crap is a nightmare to get right.
|
||||
o write SWIG transformer to auto-generate interfaces from header files
|
||||
* make direct calls call back *once* to Java where conversion is required,
|
||||
and process all arguments from there (instead of potentially swapping back
|
||||
and forth multipel times). This also makes it easer to perform conversions
|
||||
(no native changes required).
|
||||
|
||||
* stdcall/w32 underscore prefix issue
|
||||
* direct/raw non-primitive array arguments (String[], Pointer[], NativeMapped[])
|
||||
|
||||
* should structure offsets be "long"?
|
||||
* ppc64 direct/raw failures (multiple)
|
||||
|
||||
* allow return of W/String[] or Pointer[], if array is NULL-terminated?
|
||||
* direct calls on ppc to varargs (callbacks) with FP args fail; avoid them for
|
||||
now
|
||||
|
||||
* Direct buffers should be used where
|
||||
hotspot inlining can improve performance.
|
||||
* combine direct and interface mapping calling code where possible
|
||||
|
||||
* make native dll extraction from jar public, to use with user dlls packaged
|
||||
in a jar
|
||||
|
||||
* (maybe) move all native functions into Native (limit header files, easier
|
||||
management)
|
||||
* Callback.PostCallWrite.write() cf PostCallRead
|
||||
|
||||
* Does it make sense to define Int16/UInt16, Int32/UInt32, etc? Probably not
|
||||
the signed versions, but maybe the unsigned ones, to facilitate generating
|
||||
unsigned values (maybe just provide utilities to pack an unsigned int into a
|
||||
signed int). What about size_t, off_t, et al.? Would either need a
|
||||
bunch of native lookup functions (more accurate) or java-side conditionals
|
||||
(less robust but easier to change).
|
||||
o bounds checking is handled by IntegerType (pass in a long, get an
|
||||
exception if the value is out of bounds).
|
||||
* GetPrimitiveArrayCritical: use this if flagged (by annotation? method name?)
|
||||
|
||||
* MethodArgument/ReturnMapper: per method mapping of arguments/return type.
|
||||
Can use annotations as shorthand to initialize a map, but basically set up a
|
||||
per-NativeLibrary (or per-Function?) map of methods to mappers.
|
||||
|
||||
Requires separate compilation of annotation handling.
|
||||
|
||||
* ditch type conversion context (?)
|
||||
|
||||
* packaging: 'types', 'convert/marshal' subpackages?
|
||||
note: marshal/unmarshal vs to/fromnative: to/fromnative is more
|
||||
@@ -61,12 +61,6 @@
|
||||
Pointer into a types subpackage (which would leave just a few top-level
|
||||
classes). Javadoc is cluttered by example classes anyway.
|
||||
|
||||
* Make a separate jar file for all OS-specific headers
|
||||
Maybe make interfaces per-header file (winbase, winnt, stdlib, etc),
|
||||
aggregated per-library (interface CLibrary extends stdlib, stdio, etc)
|
||||
(how useful would it really be, or is this just sorting legos?)
|
||||
o same for windowutils, fileutils, etc.
|
||||
|
||||
* support annotations of parameters and return values w/o breaking
|
||||
1.4 compatibility (retroweaver?), e.g.
|
||||
-- retroweaver (requires retroweaver runtime classes to provide annotation
|
||||
@@ -81,14 +75,6 @@
|
||||
this only really applies to NativeLong/IntegerType types that want to use a
|
||||
primitive value instead of creating an object instance.
|
||||
|
||||
* Allow Buffer in Structures (and callbacks) (auto-wrap in direct byte buffer)?
|
||||
o this gets tricky when reading structs from native memory; we don't know if
|
||||
the value is already mapped to a buffer (cf CallbackReference)
|
||||
|
||||
* standard types for various platforms: posix/types.h, w32 (DWORD, HANDLE)
|
||||
* StringBuffer/StringBuilder as mutable char*/wchar_t* argument
|
||||
NOTE: byte[]/char[] is probably better; it's trivial to convert to String
|
||||
and native code can't change the size anyway
|
||||
* flag string(/wstring)-returning methods which need to free their result
|
||||
to avoid leaking memory whan auto-creating strings from the result
|
||||
(since normally we don't take explicit ownership of any returned pointers)
|
||||
@@ -105,9 +91,26 @@
|
||||
"pointer-requiring-free" (which is just Memory). For now, leave it up to
|
||||
the user to manage the pointer, since they have to define the free method
|
||||
anyway. use could always put a finalizer on a PointerType-derived type.
|
||||
* provide library load/unload hooks (Runnables in options?). Examples:
|
||||
o GetLastError (no longer needed)
|
||||
o WSAInit?
|
||||
* universal GCC build w/cross-compile (needs cross compilers...)
|
||||
* return Pointer.SIZE/LONG_SIZE/WCHAR_SIZE in bits (for consistency with 1.5)
|
||||
Long.SIZE, Integer.SIZE, et al.
|
||||
* interface "lvalue", which can provide a pointer to itself (reference() or
|
||||
addressOf())?
|
||||
* bitfields for structs (how?)
|
||||
|
||||
|
||||
# DONE
|
||||
* Make a separate jar file for all OS-specific headers
|
||||
Maybe make interfaces per-header file (winbase, winnt, stdlib, etc),
|
||||
aggregated per-library (interface CLibrary extends stdlib, stdio, etc)
|
||||
(how useful would it really be, or is this just sorting legos?)
|
||||
o same for windowutils, fileutils, etc. (not useful)
|
||||
* check Structure "final" fields; should never write back to native memory
|
||||
* OSX ObjC access (see rococoa)
|
||||
* do Structure.write for any callback args
|
||||
* pointer.setValue(), to handle NativeMapped types and move read/writeValue
|
||||
methods out of Structure, to be used by Function w/NativeMapped[] parameter
|
||||
|
||||
* if method has "GetLastErrorException/ErrnoException" in its signature, use
|
||||
result codes + GetLastError/errno/errstr to auto-generate
|
||||
runtime exceptions? (cf P/Invoke; also useful for X11 return types)
|
||||
@@ -119,21 +122,13 @@
|
||||
if nonzero ?
|
||||
o otherwise, need an ExceptionOnZero, ExceptionOnNonZero runtime, from which
|
||||
derive GetLastError/ErrnoExceptionOnZero/NZ
|
||||
* determine X11 display name from current java program (if any); null is ok
|
||||
since it uses getenv(DISPLAY), which is what java would do
|
||||
note: DISPLAY may be available in GraphicsDevice->getIDstring
|
||||
* universal GCC build w/cross-compile (needs cross compilers...)
|
||||
* return Pointer.SIZE/LONG_SIZE/WCHAR_SIZE in bits (for consistency with 1.5)
|
||||
Long.SIZE, Integer.SIZE, et al.
|
||||
* interface "lvalue", which can provide a pointer to itself (reference() or
|
||||
addressOf())?
|
||||
* verify get/set methods vs read/write for performance (Pointer)?
|
||||
* bitfields for structs (how?)
|
||||
(see RawTest for performance comparisons)
|
||||
* Allow Buffer in Structures (and callbacks) (auto-wrap in direct byte buffer)?
|
||||
o this gets tricky when reading structs from native memory; we don't know if
|
||||
the value is already mapped to a buffer (cf CallbackReference)
|
||||
* standard types for various platforms: posix/types.h, w32 (DWORD, HANDLE)
|
||||
|
||||
|
||||
|
||||
|
||||
# DONE
|
||||
* embed version in DLL ('depends'-done)/so (symlink?)
|
||||
* use libffi closure allocation/deallocation
|
||||
|
||||
@@ -253,5 +248,30 @@ transient callbacks, and require callback+dispose for most callbacks?
|
||||
void setWindowMask(Window w, Shape clip);
|
||||
// needs:
|
||||
int findNativeWindow(Window w);
|
||||
|
||||
#MAYBE NOT
|
||||
* should structure offsets be 64-bit? technically yes, but in practice I don't
|
||||
think a structure that big actually works.
|
||||
* (maybe) move all native functions into Native (limit header files, easier
|
||||
management)
|
||||
* Does it make sense to define Int16/UInt16, Int32/UInt32, etc? Probably not
|
||||
the signed versions, but maybe the unsigned ones, to facilitate generating
|
||||
unsigned values (maybe just provide utilities to pack an unsigned int into a
|
||||
signed int). What about size_t, off_t, et al.? Would either need a
|
||||
bunch of native lookup functions (more accurate) or java-side conditionals
|
||||
(less robust but easier to change).
|
||||
o bounds checking is handled by IntegerType (pass in a long, get an
|
||||
exception if the value is out of bounds).
|
||||
o when used as struct fields, could allow detection of field order by order
|
||||
of initialization (requires all-or-nothing usage, though)
|
||||
* StringBuffer/StringBuilder as mutable char*/wchar_t* argument
|
||||
NOTE: byte[]/char[] is probably better; it's trivial to convert to String
|
||||
and native code can't change the size anyway
|
||||
* provide library load/unload hooks (Runnables in options?). Examples:
|
||||
o GetLastError (no longer needed)
|
||||
o WSAInit?
|
||||
* determine X11 display name from current java program (if any); null is ok
|
||||
since it uses getenv(DISPLAY), which is what java would do
|
||||
note: DISPLAY may be available in GraphicsDevice->getIDstring
|
||||
|
||||
|
||||
|
||||
+152
-66
@@ -15,12 +15,14 @@
|
||||
<!-- (all build-related props should go in -dynamic-properties) -->
|
||||
<property name="name" value="jna"/>
|
||||
<property name="jar" value="${name}.jar"/>
|
||||
<property name="testjar" value="${name}-test.jar"/>
|
||||
<property name="debug" value="true"/>
|
||||
<property name="debug.native" value="false"/>
|
||||
<property name="cflags_extra.native" value=""/>
|
||||
<property name="dynlink.native" value="false"/>
|
||||
<property name="native" location="native"/>
|
||||
<property name="src" location="src"/>
|
||||
<property name="contrib" location="contrib"/>
|
||||
<property name="dist" location="dist"/>
|
||||
<property name="test.src" location="test"/>
|
||||
<property name="doc" location="doc"/>
|
||||
@@ -28,27 +30,27 @@
|
||||
<property name="stylesheet" location="${javadoc}/doc/css/javadoc.css"/>
|
||||
<property name="vendor" value="JNA Development Team"/>
|
||||
<property name="copyright"
|
||||
value="Copyright &copy; 2007-2008 Timothy Wall. All Rights Reserved."/>
|
||||
value="Copyright &copy; 2007-2010 Timothy Wall. All Rights Reserved."/>
|
||||
<buildnumber/>
|
||||
<!-- JNA library release version -->
|
||||
<property name="jna.major" value="3"/>
|
||||
<property name="jna.minor" value="0"/>
|
||||
<property name="jna.revision" value="5"/>
|
||||
<property name="jna.minor" value="2"/>
|
||||
<property name="jna.revision" value="7"/>
|
||||
<property name="jna.build" value="${build.number}"/>
|
||||
<property name="jna.version" value="${jna.major}.${jna.minor}.${jna.revision}"/>
|
||||
<!-- jnidispatch library release version -->
|
||||
<property name="jni.major" value="3"/>
|
||||
<property name="jni.minor" value="0"/>
|
||||
<property name="jni.revision" value="4"/>
|
||||
<property name="jni.minor" value="2"/>
|
||||
<property name="jni.revision" value="2"/>
|
||||
<property name="jni.build" value="${build.number}"/>
|
||||
<property name="jni.version" value="${jni.major}.${jni.minor}.${jni.revision}"/>
|
||||
<property name="jni.md5" value="892beacd437514d23ed9b1cefeb2ead6"/>
|
||||
<property name="jni.md5" value="c870290c36c8d3fdf85db7c782febc3f"/>
|
||||
<property name="spec.title" value="Java Native Access (JNA)"/>
|
||||
<property name="spec.vendor" value="${vendor}"/>
|
||||
<property name="spec.version" value="${jna.major}"/>
|
||||
<property name="impl.title" value="com.sun.jna"/>
|
||||
<property name="impl.vendor" value="${spec.vendor}"/>
|
||||
<property name="impl.version" value="${jna.version} b${jna.build}"/>
|
||||
<property name="impl.version" value="${jna.version} (b${jna.build})"/>
|
||||
|
||||
<property name="compatibility" value="1.4"/>
|
||||
<property name="test.compatibility" value="1.5"/>
|
||||
@@ -58,18 +60,25 @@
|
||||
|
||||
<target name="default" depends="test" description="Build and Test."/>
|
||||
|
||||
<import file="nbproject/profiler-build-impl.xml"/>
|
||||
<!-- uncomment for netbeans profiling -->
|
||||
<!--<import file="nbproject/profiler-build-impl.xml"/>-->
|
||||
<target name="init" depends="-setup"/>
|
||||
<target name="compile-test-single" depends="compile-tests"/>
|
||||
<target name="compile-single" depends="compile"/>
|
||||
|
||||
<target name="-dynamic-properties">
|
||||
<echo>Java version: ${java.version}, compatibility: ${compatibility}</echo>
|
||||
<echo>JNA version ${jna.version}, native API version ${jni.version}</echo>
|
||||
<echo>Java version ${java.version}, compatibility: ${compatibility}</echo>
|
||||
<echo>JNA version ${jna.version}, native ${jni.version}</echo>
|
||||
<echo>${java.vm.name} (${java.vm.vendor}, ${java.vm.version})</echo>
|
||||
<echo>java.home=${java.home}</echo>
|
||||
<echo>java.library.path=${java.library.path}</echo>
|
||||
|
||||
<replaceregexp match="(<version>).*(</version>)"
|
||||
replace="\1${jna.version}\2"
|
||||
file="pom.xml"/>
|
||||
<replaceregexp match='VERSION = ".*";'
|
||||
replace='VERSION = "${jna.version}";'
|
||||
file="src/com/sun/jna/Native.java"/>
|
||||
|
||||
<condition property="jar.omitted" value="**/*jnidispatch*" else="jnilib-included">
|
||||
<isset property="omit-jnilib"/>
|
||||
@@ -77,12 +86,19 @@
|
||||
<condition property="vm.arch" value="-d64" else="">
|
||||
<or>
|
||||
<equals arg1="${sun.arch.data.model}" arg2="64" trim="true"/>
|
||||
<equals arg1="${com.ibm.vm.bitmode}" arg2="64" trim="true"/>
|
||||
<os arch="x86_64"/>
|
||||
<os arch="ppc64"/>
|
||||
<os arch="sparcv9"/>
|
||||
<os arch="amd64"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="ld.preload" value="LD_PRELOAD_64" else="LD_PRELOAD">
|
||||
<and>
|
||||
<os name="SunOS"/>
|
||||
<equals arg1="${vm.arch}" arg2="-d64"/>
|
||||
</and>
|
||||
</condition>
|
||||
<property name="build" value="build${vm.arch}"/>
|
||||
<property name="classes" location="${build}/classes"/>
|
||||
<property name="eclipse.classes" location="build.eclipse/classes"/>
|
||||
@@ -90,20 +106,19 @@
|
||||
<property name="reports" value="${build}/reports"/>
|
||||
|
||||
<!-- Add other supported platforms here -->
|
||||
<condition property="jre.arch" value="i386">
|
||||
<equals arg1="x86" arg2="${os.arch}"/>
|
||||
</condition>
|
||||
<condition property="jre.arch" value="amd64">
|
||||
<equals arg1="x86_64" arg2="${os.arch}"/>
|
||||
</condition>
|
||||
<property name="jre.arch" value="${os.arch}"/>
|
||||
<condition property="os.prefix" value="linux-${jre.arch}">
|
||||
<os name="Linux"/>
|
||||
</condition>
|
||||
<condition property="os.prefix" value="win32-${os.arch}">
|
||||
<os family="windows"/>
|
||||
</condition>
|
||||
<condition property="os.prefix" value="linux-i386">
|
||||
<!-- IBM's J9 reports 'x86' -->
|
||||
<and><os name="Linux"/><os arch="x86"/></and>
|
||||
</condition>
|
||||
<condition property="os.prefix" value="linux-amd64">
|
||||
<!-- Debian reports 'x86_64' -->
|
||||
<and><os name="Linux"/><os arch="x86_64"/></and>
|
||||
</condition>
|
||||
<condition property="os.prefix" value="linux-${os.arch}">
|
||||
<os name="Linux"/>
|
||||
</condition>
|
||||
<!-- Darwin builds are universal, no arch required -->
|
||||
<condition property="os.prefix" value="darwin">
|
||||
<os family="mac"/>
|
||||
@@ -124,8 +139,11 @@
|
||||
<condition property="jdk.home" value="${java.home}/..">
|
||||
<available file="${java.home}/../include"/>
|
||||
</condition>
|
||||
<fail unless="jdk.home" message="JAVA_HOME/java.home must be a JDK, not JRE"/>
|
||||
|
||||
<fail unless="jdk.home" message="Can't find JNI headers"/>
|
||||
<condition property="libjsig"
|
||||
value="${java.home}/lib/${jre.arch}/libjsig.so" else="">
|
||||
<available file="${java.home}/lib/${jre.arch}/libjsig.so"/>
|
||||
</condition>
|
||||
<property name="native.jar" value="${os.prefix}.jar"/>
|
||||
<property name="build.native" location="${build}/native"/>
|
||||
<property name="md5.file" location="${build.native}/sig"/>
|
||||
@@ -140,7 +158,7 @@
|
||||
</target>
|
||||
|
||||
<target name="-setup" depends="-dynamic-properties">
|
||||
<path id="compile-test.path">
|
||||
<path id="compile-test.path">
|
||||
<pathelement path="${test.src}"/>
|
||||
<path id="test.libs">
|
||||
<fileset dir="lib">
|
||||
@@ -152,12 +170,11 @@
|
||||
<path id="src.path">
|
||||
<pathelement location="${src}"/>
|
||||
</path>
|
||||
</path>
|
||||
</path>
|
||||
</path>
|
||||
|
||||
<path id="test.runpath">
|
||||
<pathelement path="${build}/${jar}"/>
|
||||
<pathelement path="${build}/examples.jar"/>
|
||||
<pathelement path="${test.classes}"/>
|
||||
<pathelement path="lib/clover.jar"/>
|
||||
<path refid="test.libs"/>
|
||||
@@ -181,8 +198,6 @@
|
||||
<patternset id="jar-compiled">
|
||||
<include name="com/sun/jna/*"/>
|
||||
<include name="com/sun/jna/**/*"/>
|
||||
<exclude name="com/sun/jna/examples/*"/>
|
||||
<exclude name="com/sun/jna/examples/**/*"/>
|
||||
</patternset>
|
||||
</srcfiles>
|
||||
</uptodate>
|
||||
@@ -193,12 +208,23 @@
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="com.sun.jna.Native"/>
|
||||
<section name="com/sun/jna/">
|
||||
<attribute name="Manifest-Version" value="1.0"/>
|
||||
<attribute name="Implementation-Title" value="${impl.title}"/>
|
||||
<attribute name="Implementation-Vendor" value="${vendor}"/>
|
||||
<attribute name="Implementation-Version" value="${impl.version}"/>
|
||||
<attribute name="Specification-Title" value="${spec.title}"/>
|
||||
<attribute name="Specification-Vendor" value="${spec.vendor}"/>
|
||||
<attribute name="Specification-Version" value="${spec.version}"/>
|
||||
<!-- OSGi Bundle attributes -->
|
||||
<attribute name="Bundle-ManifestVersion" value="2"/>
|
||||
<attribute name="Bundle-Name" value="jna"/>
|
||||
<attribute name="Bundle-Description" value="JNA Library"/>
|
||||
<attribute name="Bundle-SymbolicName" value="com.sun.jna"/>
|
||||
<attribute name="Bundle-Version" value="${spec.version}"/>
|
||||
<attribute name="Bundle-RequiredExecutionEnvironment" value="J2SE-1.4"/>
|
||||
<attribute name="Bundle-Vendor" value="${vendor}"/>
|
||||
<attribute name="Bundle-ActivationPolicy" value="lazy"/>
|
||||
<attribute name="Export-Package" value="com.sun.jna*"/>
|
||||
</section>
|
||||
</manifest>
|
||||
<fileset dir="${classes}" excludes="${jar.omitted}">
|
||||
@@ -206,16 +232,16 @@
|
||||
</fileset>
|
||||
</jar>
|
||||
</target>
|
||||
<target name="examples" depends="jar,native">
|
||||
<jar jarfile="${build}/examples.jar">
|
||||
<manifest>
|
||||
<attribute name="Class-Path" value="jna.jar"/>
|
||||
<attribute name="Main-Class" value="com.sun.jna.examples.ShapedWindowDemo"/>
|
||||
</manifest>
|
||||
<fileset dir="${src}" includes="**/examples/**/*.png"/>
|
||||
<fileset dir="${classes}" includes="**/examples/*,**/examples/**/*"/>
|
||||
<fileset dir="${classes}" includes="jnidispatch.dll"/>
|
||||
</jar>
|
||||
|
||||
<target name="contrib-jars" depends="jar" description="Build contrib jars">
|
||||
<subant target="jar">
|
||||
<property name="file.reference.jna.build" location="${build}"/>
|
||||
<property name="file.reference.jna.jar" location="${build}/${jar}"/>
|
||||
<property name="libs.junit.classpath" location="lib/junit.jar"/>
|
||||
<!-- platform.jar needs to be built first -->
|
||||
<fileset dir="${contrib}" includes="platform/build.xml" />
|
||||
<fileset dir="${contrib}" includes="*/build.xml" excludes="platform/build.xml"/>
|
||||
</subant>
|
||||
</target>
|
||||
|
||||
<target name="javah" depends="compile">
|
||||
@@ -244,7 +270,10 @@
|
||||
<fixcrlf srcdir="${build.native}" includes="sig" eol="unix"/>
|
||||
<checksum property="md5" file="${md5.file}" />
|
||||
<condition property="jni.valid" value="true">
|
||||
<equals arg1="${jni.md5}" arg2="${md5}" trim="true"/>
|
||||
<or>
|
||||
<equals arg1="${jni.md5}" arg2="${md5}" trim="true"/>
|
||||
<equals arg1="${jni.md5}" arg2=""/>
|
||||
</or>
|
||||
</condition>
|
||||
</target>
|
||||
|
||||
@@ -253,8 +282,10 @@
|
||||
<echo>Invalidating native code, new checksum is ${md5}</echo>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/darwin.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/win32-x86.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/win32-amd64.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/linux-i386.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/linux-amd64.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/linux-ia64.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/freebsd-i386.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/freebsd-amd64.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/openbsd-i386.jar" overwrite="true"/>
|
||||
@@ -297,8 +328,8 @@
|
||||
<target name="native" depends="-setup,javah,-native-api-check,rsrc"
|
||||
description="Build native libraries. Use 'ant -DCC=xxx' to build using a compiler other than gcc">
|
||||
<property name="comment" value="# auto-generated by ant"/>
|
||||
<replaceregexp match="^VERSION=.*"
|
||||
replace="VERSION=${jni.version} ${comment}"
|
||||
<replaceregexp match="^JNA_JNI_VERSION=.*"
|
||||
replace="JNA_JNI_VERSION=${jni.version} ${comment}"
|
||||
file="native/Makefile" byline="true"/>
|
||||
<replaceregexp match="^CHECKSUM=.*"
|
||||
replace="CHECKSUM=${jni.md5} ${comment}"
|
||||
@@ -315,6 +346,10 @@
|
||||
<condition property="make.SDKROOT" value="SDKROOT=${SDKROOT}">
|
||||
<isset property="SDKROOT"/>
|
||||
</condition>
|
||||
<condition property="make.SDKROOT"
|
||||
value="SDKROOT=/Developer/SDKs/MacOSX10.6.sdk">
|
||||
<available file="/Developer/SDKs/MacOSX10.6.sdk"/>
|
||||
</condition>
|
||||
<condition property="make.SDKROOT"
|
||||
value="SDKROOT=/Developer/SDKs/MacOSX10.5.sdk">
|
||||
<available file="/Developer/SDKs/MacOSX10.5.sdk"/>
|
||||
@@ -340,6 +375,7 @@
|
||||
<os name="OpenBSD"/>
|
||||
</or>
|
||||
</condition>
|
||||
|
||||
<!-- Default make program -->
|
||||
<property name="make" value="make"/>
|
||||
|
||||
@@ -354,7 +390,7 @@
|
||||
<arg value="${make.SDKROOT}"/>
|
||||
<arg value="${make.ARCH}"/>
|
||||
<arg value="${make.PATH}"/>
|
||||
<arg value="VERSION=${jni.version}"/>
|
||||
<arg value="JNA_JNI_VERSION=${jni.version}"/>
|
||||
<arg value="CHECKSUM=${jni.md5}"/>
|
||||
</exec>
|
||||
<mkdir dir="${classes}/com/sun/jna/${os.prefix}"/>
|
||||
@@ -379,8 +415,8 @@
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="compile-tests" depends="compile,native"
|
||||
description="Compile all test code">
|
||||
<target name="compile-tests" depends="compile,native,jar"
|
||||
description="Compile all test code">
|
||||
<javac classpathref="compile-test.path"
|
||||
source="${test.compatibility}"
|
||||
target="${test.compatibility}"
|
||||
@@ -388,20 +424,40 @@
|
||||
deprecation="on" debug="${debug}">
|
||||
<src path="${test.src}"/>
|
||||
</javac>
|
||||
<jar jarfile="${build}/${testjar}">
|
||||
<fileset dir="${test.classes}">
|
||||
<patternset refid="jar-compiled"/>
|
||||
</fileset>
|
||||
</jar>
|
||||
<mkdir dir="${build}/jws"/>
|
||||
<copy todir="${build}/jws" file="${build}/${jar}"/>
|
||||
<copy todir="${build}/jws" file="${build}/${testjar}"/>
|
||||
<copy todir="${build}/jws" file="lib/junit.jar"/>
|
||||
<copy todir="${build}/jws" file="lib/clover.jar"/>
|
||||
<jar jarfile="${build}/jws/jnidispatch.jar">
|
||||
<fileset dir="${build.native}" includes="*jnidispatch.*"/>
|
||||
</jar>
|
||||
<signjar alias="jna" keystore="jna.keystore" storepass="jnadev" lazy="true">
|
||||
<fileset dir="${build}/jws" includes="jna.jar,jna-test.jar,junit.jar,jnidispatch.jar,clover.jar"/>
|
||||
</signjar>
|
||||
</target>
|
||||
|
||||
|
||||
<!-- When running tests from an IDE, be sure to set jna.library.path -->
|
||||
<!-- to where the test library (testlib) is found. Also need to add -Ddir.build.suffix=-d64 for 64-bit JVMs. -->
|
||||
<target name="test" depends="jar,examples,compile-tests"
|
||||
<!-- to where the test library (testlib) is found. -->
|
||||
<target name="test" depends="jar,contrib-jars,compile-tests"
|
||||
description="Run all unit tests">
|
||||
<property name="test.fork" value="yes"/>
|
||||
<property name="reports.junit" location="${reports}/junit"/>
|
||||
<property name="results.junit" location="${build}/junit-results"/>
|
||||
<mkdir dir="${results.junit}"/>
|
||||
<echo>Saving test results in ${results.junit}</echo>
|
||||
<condition property="tests.platform" value="**/win32/*Test.java">
|
||||
<property name="tests.stdcall" value="**/win32/*StdCallTest.java"/>
|
||||
<condition property="tests.platform" value="**/win32/**/*Test.java">
|
||||
<os family="windows"/>
|
||||
</condition>
|
||||
<condition property="tests.exclude" value="**/win32/*StdCallTest.java">
|
||||
<and><os family="windows"/><not><os arch="x86"/></not></and>
|
||||
</condition>
|
||||
<condition property="tests.platform" value="**/unix/*Test.java">
|
||||
<and>
|
||||
<os family="unix"/>
|
||||
@@ -409,29 +465,35 @@
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="vmopt.arch" value="-d64" else="-Dignore">
|
||||
<equals arg1="${vm.arch}" arg2="-d64" trim="true"/>
|
||||
</condition>
|
||||
<condition property="dir.build.suffix" value="-d64" else="">
|
||||
<equals arg1="${vm.arch}" arg2="-d64" trim="true"/>
|
||||
<and>
|
||||
<!-- Sun 64-bit VM for windows doesn't support the -d64 switch -->
|
||||
<not><os family="windows"/></not>
|
||||
<equals arg1="${vm.arch}" arg2="-d64" trim="true"/>
|
||||
</and>
|
||||
</condition>
|
||||
<property name="tests.platform" value=""/>
|
||||
<property name="tests.exclude" value=""/>
|
||||
<junit printsummary="yes" fork="${test.fork}" failureproperty="testfailure">
|
||||
<!-- avoid VM conflicts with JNA protected mode -->
|
||||
<env key="${ld.preload}" file="${libjsig}"/>
|
||||
<jvmarg value="-Djna.library.path=${build.native}"/>
|
||||
<!-- Avoid VM crashes, if possible -->
|
||||
<jvmarg value="-Djna.protected=true"/>
|
||||
<jvmarg value="-Ddir.build.suffix=${dir.build.suffix}"/>
|
||||
<jvmarg value="-Djna.builddir=${build}"/>
|
||||
<jvmarg value="${vmopt.arch}"/>
|
||||
<classpath><path refid="test.runpath"/></classpath>
|
||||
<formatter type="xml"/>
|
||||
<batchtest todir="${results.junit}">
|
||||
<fileset dir="${test.src}">
|
||||
<include name="com/sun/jna/*Test.java"/>
|
||||
<include name="com/sun/jna/examples/*Test.java"/>
|
||||
<include name="${tests.platform}"/>
|
||||
<exclude name="${tests.exclude}"/>
|
||||
</fileset>
|
||||
</batchtest>
|
||||
</junit>
|
||||
<subant target="test">
|
||||
<fileset dir="${contrib}" includes="platform/build.xml"/>
|
||||
</subant>
|
||||
<junitreport todir="${results.junit}">
|
||||
<fileset dir="${results.junit}">
|
||||
<include name="TEST-*.xml"/>
|
||||
@@ -455,7 +517,7 @@
|
||||
<mkdir dir="${reports.clover}"/>
|
||||
<clover-report>
|
||||
<current outfile="${reports.clover}" title="clover">
|
||||
<fileset dir="." includes="**/*.java" excludes="**/examples/**/*.java"/>
|
||||
<fileset dir="." includes="**/*.java" />
|
||||
<testresults dir="${results.junit}" includes="TEST-*.xml"/>
|
||||
<format type="html"/>
|
||||
</current>
|
||||
@@ -475,7 +537,7 @@
|
||||
sourcepathref="src.path"
|
||||
classpathref="compile.path"
|
||||
maxmemory="256m"
|
||||
packagenames="com.sun.jna,com.sun.jna.ptr,com.sun.jna.types,com.sun.jna.examples,com.sun.jna.examples.win32,com.sun.jna.exmaples.unix"
|
||||
packagenames="com.sun.jna,com.sun.jna.ptr,com.sun.jna.types,com.sun.jna.platform,com.sun.jna.platform.win32,com.sun.jna.exmaples.unix"
|
||||
overview="${src}/com/sun/jna/overview.html"
|
||||
destdir="${javadoc}">
|
||||
<!-- stylesheetfile="${stylesheet}" -->
|
||||
@@ -491,15 +553,16 @@
|
||||
</packageset>
|
||||
|
||||
<group title="Java Native Access" packages="com.sun.jna,com.sun.jna.ptr,com.sun.jna.types,com.sun.jna.win32"/>
|
||||
<group title="Examples" packages="com.sun.jna.examples,com.sun.jna.examples.dnd"/>
|
||||
<group title="Unix Examples" packages="com.sun.jna.examples.unix"/>
|
||||
<group title="Windows Examples" packages="com.sun.jna.examples.win32"/>
|
||||
|
||||
<group title="Platform Specific" packages="com.sun.jna.platform"/>
|
||||
|
||||
<arg value="-notimestamp"/>
|
||||
</javadoc>
|
||||
<subant target="javadoc">
|
||||
<fileset dir="${contrib}" includes="platform/build.xml"/>
|
||||
</subant>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="jar,compile-tests,native,examples,javadoc"
|
||||
<target name="dist" depends="jar,contrib-jars,compile-tests,native,javadoc"
|
||||
description="Build distribution files">
|
||||
<jar jarfile="${dist}/jna.jar" duplicate="preserve">
|
||||
<manifest>
|
||||
@@ -526,6 +589,9 @@
|
||||
<zipfileset src="${dist}/linux-amd64.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/linux-amd64"/>
|
||||
<zipfileset src="${dist}/linux-ia64.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/linux-ia64"/>
|
||||
<zipfileset src="${dist}/sunos-x86.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/sunos-x86"/>
|
||||
@@ -547,31 +613,47 @@
|
||||
<zipfileset src="${dist}/openbsd-i386.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/openbsd-i386"/>
|
||||
<zipfileset src="${dist}/win32-amd64.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/win32-amd64"/>
|
||||
</jar>
|
||||
<copy todir="${dist}">
|
||||
<fileset dir="${build}">
|
||||
<include name="${native.jar}"/>
|
||||
<include name="examples.jar"/>
|
||||
</fileset>
|
||||
<fileset dir="${contrib}/platform/dist">
|
||||
<include name="platform.jar" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="${dist}/jnacontrib" flatten="true">
|
||||
<fileset dir="${contrib}">
|
||||
<include name="**/build/demo-*.jar" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<zip zipfile="${dist}/doc.zip">
|
||||
<zipfileset dir="${javadoc}" prefix="javadoc"/>
|
||||
<zipfileset dir="${contrib}/platform/dist/javadoc" prefix="platform/javadoc"/>
|
||||
</zip>
|
||||
<!-- JNA sources only, for use in Linux build from source -->
|
||||
<!-- JNA sources only, for use in Linux build from source/shared libffi -->
|
||||
<zip zipfile="${dist}/src.zip">
|
||||
<zipfileset dir="." includes="build.xml"/>
|
||||
<zipfileset dir="." includes="build.xml,LICENSE.txt"/>
|
||||
<zipfileset dir="${src}" includes="**/*.java" prefix="src"/>
|
||||
<zipfileset dir="${test.src}" includes="**/*.java" prefix="test"/>
|
||||
<zipfileset dir="${native}" excludes="libffi,libffi/**/*" prefix="native"/>
|
||||
<zipfileset dir="${native}" excludes="libffi,libffi/**/*,build,build/**/*" prefix="native"/>
|
||||
<zipfileset dir="${contrib}/platform" includes="**/*.java" prefix="contrib/platform"/>
|
||||
</zip>
|
||||
<!-- Full sources required to build and test everything -->
|
||||
<zip zipfile="${dist}/src-full.zip">
|
||||
<zipfileset src="${dist}/src.zip"/>
|
||||
<zipfileset dir="lib" includes="junit.jar" prefix="lib"/>
|
||||
<zipfileset dir="lib" includes="junit.jar,clover.jar" prefix="lib"/>
|
||||
<zipfileset dir="." includes=".classpath,.project"/>
|
||||
<zipfileset dir="nbproject" includes="**/*" prefix="nbproject"/>
|
||||
<zipfileset dir="${native}" includes="libffi,libffi/**/*" prefix="native"/>
|
||||
</zip>
|
||||
<!-- Sources package as required by maven -->
|
||||
<zip zipfile="${dist}/src-mvn.zip">
|
||||
<zipfileset dir="${src}" includes="**/*.java,**/*.html,**/*.png"/>
|
||||
</zip>
|
||||
</target>
|
||||
|
||||
<target name="clean" depends="-dynamic-properties">
|
||||
@@ -579,9 +661,13 @@
|
||||
<fileset dir="${build}"/>
|
||||
</delete>
|
||||
<delete quiet="true" includeEmptyDirs="true">
|
||||
<fileset dir=".clover"/>
|
||||
<fileset dir="${javadoc}"/>
|
||||
<fileset dir="." includes="*~,**/*~"/>
|
||||
</delete>
|
||||
<subant target="clean">
|
||||
<fileset dir="${contrib}" includes="*/build.xml"/>
|
||||
</subant>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/jna/dist/jna.jar"/>
|
||||
<classpathentry kind="src" path="/platform"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>alphamaskdemo</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="jnacontrib.alphamaskdemo" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project jnacontrib.alphamaskdemo.</description>
|
||||
<!-- Locations -->
|
||||
<property name="src" location="."/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="jna-dist" location="../../dist"/>
|
||||
|
||||
<property name="classes" location="${build}/classes"/>
|
||||
<property name="jar" location="${build}/demo-alphamask.jar"/>
|
||||
<property name="file.reference.jna.build" location="../../build"/>
|
||||
<property name="file.reference.jna.jar" location="../../build/jna.jar"/>
|
||||
<property name="main-class" value="com.sun.jna.contrib.demo.AlphaMaskDemo" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset file="${file.reference.jna.jar}"/>
|
||||
<fileset dir="../platform/dist" includes="platform.jar"/>
|
||||
</path>
|
||||
|
||||
<!-- Run Demo. -->
|
||||
<target name="run" depends="compile">
|
||||
<java classname="${main-class}" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${classes}" />
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Delete class and jar files. -->
|
||||
<target name="clean">
|
||||
<delete dir="${classes}"/>
|
||||
<delete file="${jar}"/>
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile all classes. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${classes}"/>
|
||||
|
||||
<!-- Compile the project. -->
|
||||
<javac srcdir="${src}" destdir="${classes}" target="1.5" source="1.5" encoding="UTF-8" debug="on">
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
<src>
|
||||
<dirset dir="${src}"/>
|
||||
</src>
|
||||
</javac>
|
||||
|
||||
<!-- Copy all non-java files to classes. -->
|
||||
<copy todir="${classes}/com">
|
||||
<fileset dir="${src}/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- platform -->
|
||||
<fileset dir="../platform/build/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- jna -->
|
||||
<fileset dir="${file.reference.jna.build}/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- Create jar-file. -->
|
||||
<target name="jar" depends="compile">
|
||||
<jar jarfile="${jar}" basedir="${classes}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
+35
-29
@@ -10,9 +10,9 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.examples;
|
||||
|
||||
import java.awt.event.*;
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
@@ -26,6 +26,7 @@ import java.awt.Window;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ImageObserver;
|
||||
@@ -38,6 +39,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
@@ -52,23 +54,26 @@ import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.MouseInputAdapter;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.NativeLong;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.examples.unix.X11;
|
||||
import com.sun.jna.examples.unix.X11.Display;
|
||||
import com.sun.jna.examples.unix.X11.GC;
|
||||
import com.sun.jna.examples.unix.X11.XSetWindowAttributes;
|
||||
import com.sun.jna.examples.win32.GDI32;
|
||||
import com.sun.jna.examples.win32.User32;
|
||||
import com.sun.jna.examples.win32.GDI32.BITMAPINFO;
|
||||
import com.sun.jna.examples.win32.User32.BLENDFUNCTION;
|
||||
import com.sun.jna.examples.win32.User32.POINT;
|
||||
import com.sun.jna.examples.win32.User32.SIZE;
|
||||
import com.sun.jna.examples.win32.W32API.HANDLE;
|
||||
import com.sun.jna.examples.win32.W32API.HBITMAP;
|
||||
import com.sun.jna.examples.win32.W32API.HDC;
|
||||
import com.sun.jna.examples.win32.W32API.HWND;
|
||||
import com.sun.jna.platform.WindowUtils;
|
||||
import com.sun.jna.platform.unix.X11;
|
||||
import com.sun.jna.platform.unix.X11.Display;
|
||||
import com.sun.jna.platform.unix.X11.GC;
|
||||
import com.sun.jna.platform.win32.GDI32;
|
||||
import com.sun.jna.platform.win32.User32;
|
||||
import com.sun.jna.platform.win32.WinGDI;
|
||||
import com.sun.jna.platform.win32.WinUser;
|
||||
import com.sun.jna.platform.win32.WinDef.HBITMAP;
|
||||
import com.sun.jna.platform.win32.WinDef.HDC;
|
||||
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||
import com.sun.jna.platform.win32.WinGDI.BITMAPINFO;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinUser.BLENDFUNCTION;
|
||||
import com.sun.jna.platform.win32.WinUser.POINT;
|
||||
import com.sun.jna.platform.win32.WinUser.SIZE;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
// TODO: put this into a reasonable API; right now this is pretty much
|
||||
@@ -124,7 +129,7 @@ public class AlphaMaskDemo implements Runnable {
|
||||
|
||||
private com.sun.jna.Memory buffer;
|
||||
private int[] pixels;
|
||||
private void updateX11(boolean a, boolean i) {
|
||||
private void updateX11(boolean a, boolean i) {
|
||||
X11 x11 = X11.INSTANCE;
|
||||
X11.Window win = X11.Window.None;
|
||||
Display dpy = x11.XOpenDisplay(null);
|
||||
@@ -227,9 +232,9 @@ public class AlphaMaskDemo implements Runnable {
|
||||
if (!alphaWindow.isDisplayable()) {
|
||||
alphaWindow.pack();
|
||||
hWnd = getHwnd(alphaWindow);
|
||||
int flags = user.GetWindowLong(hWnd, User32.GWL_EXSTYLE);
|
||||
flags |= User32.WS_EX_LAYERED;
|
||||
user.SetWindowLong(hWnd, User32.GWL_EXSTYLE, flags);
|
||||
int flags = user.GetWindowLong(hWnd, WinUser.GWL_EXSTYLE);
|
||||
flags |= WinUser.WS_EX_LAYERED;
|
||||
user.SetWindowLong(hWnd, WinUser.GWL_EXSTYLE, flags);
|
||||
Window parent = alphaWindow.getOwner();
|
||||
Point where = parent.getLocationOnScreen();
|
||||
where.translate(parent.getWidth(), 0);
|
||||
@@ -257,11 +262,11 @@ public class AlphaMaskDemo implements Runnable {
|
||||
bmi.bmiHeader.biHeight = h;
|
||||
bmi.bmiHeader.biPlanes = 1;
|
||||
bmi.bmiHeader.biBitCount = 32;
|
||||
bmi.bmiHeader.biCompression = GDI32.BI_RGB;
|
||||
bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
|
||||
bmi.bmiHeader.biSizeImage = w * h * 4;
|
||||
|
||||
PointerByReference ppbits = new PointerByReference();
|
||||
hBitmap = gdi.CreateDIBSection(memDC, bmi, GDI32.DIB_RGB_COLORS,
|
||||
hBitmap = gdi.CreateDIBSection(memDC, bmi, WinGDI.DIB_RGB_COLORS,
|
||||
ppbits, null, 0);
|
||||
oldBitmap = gdi.SelectObject(memDC, hBitmap);
|
||||
Pointer pbits = ppbits.getValue();
|
||||
@@ -290,9 +295,9 @@ public class AlphaMaskDemo implements Runnable {
|
||||
POINT srcLoc = new POINT();
|
||||
BLENDFUNCTION blend = new BLENDFUNCTION();
|
||||
blend.SourceConstantAlpha = (byte)(alpha * 255);
|
||||
blend.AlphaFormat = User32.AC_SRC_ALPHA;
|
||||
blend.AlphaFormat = WinUser.AC_SRC_ALPHA;
|
||||
user.UpdateLayeredWindow(hWnd, screenDC, loc, size, memDC, srcLoc,
|
||||
0, blend, User32.ULW_ALPHA);
|
||||
0, blend, WinUser.ULW_ALPHA);
|
||||
}
|
||||
finally {
|
||||
user.ReleaseDC(null, screenDC);
|
||||
@@ -306,9 +311,9 @@ public class AlphaMaskDemo implements Runnable {
|
||||
else if (a) {
|
||||
BLENDFUNCTION blend = new BLENDFUNCTION();
|
||||
blend.SourceConstantAlpha = (byte)(alpha * 255);
|
||||
blend.AlphaFormat = User32.AC_SRC_ALPHA;
|
||||
blend.AlphaFormat = WinUser.AC_SRC_ALPHA;
|
||||
user.UpdateLayeredWindow(hWnd, null, null, null, null, null,
|
||||
0, blend, User32.ULW_ALPHA);
|
||||
0, blend, WinUser.ULW_ALPHA);
|
||||
}
|
||||
|
||||
if (!alphaWindow.isVisible()) {
|
||||
@@ -383,8 +388,9 @@ public class AlphaMaskDemo implements Runnable {
|
||||
JPanel p = new JPanel(new BorderLayout(8, 8));
|
||||
p.setBorder(new EmptyBorder(8, 8, 8, 8));
|
||||
p.setTransferHandler(new TransferHandler() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
|
||||
List list = Arrays.asList(transferFlavors);
|
||||
List<DataFlavor> list = Arrays.asList(transferFlavors);
|
||||
if (list.contains(URL_FLAVOR)
|
||||
|| list.contains(URI_LIST_FLAVOR)
|
||||
|| list.contains(DataFlavor.imageFlavor)
|
||||
@@ -421,8 +427,8 @@ public class AlphaMaskDemo implements Runnable {
|
||||
return true;
|
||||
}
|
||||
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)){
|
||||
List files = (List)t.getTransferData(DataFlavor.javaFileListFlavor);
|
||||
File f = (File)files.get(0);
|
||||
List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
|
||||
File f = files.get(0);
|
||||
URL url = new URL("file://" + f.toURI().toURL().getPath());
|
||||
Image image = Toolkit.getDefaultToolkit().getImage(url);
|
||||
setImage(image);
|
||||
+9
-7
@@ -8,10 +8,10 @@
|
||||
* 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.examples;
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
@@ -52,6 +52,8 @@ import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.MouseInputAdapter;
|
||||
|
||||
import com.sun.jna.platform.WindowUtils;
|
||||
|
||||
public class AlphaMaskDemo2 implements Runnable {
|
||||
private static final DataFlavor URL_FLAVOR =
|
||||
new DataFlavor("application/x-java-url; class=java.net.URL", "URL");
|
||||
@@ -143,9 +145,10 @@ public class AlphaMaskDemo2 implements Runnable {
|
||||
JPanel p = new JPanel(new BorderLayout(8, 8));
|
||||
p.setBorder(new EmptyBorder(8, 8, 8, 8));
|
||||
p.setTransferHandler(new TransferHandler() {
|
||||
public boolean canImport(JComponent comp,
|
||||
private static final long serialVersionUID = 1L;
|
||||
public boolean canImport(JComponent comp,
|
||||
DataFlavor[] transferFlavors) {
|
||||
List list = Arrays.asList(transferFlavors);
|
||||
List<DataFlavor> list = Arrays.asList(transferFlavors);
|
||||
if (list.contains(URL_FLAVOR) || list.contains(URI_LIST_FLAVOR)
|
||||
|| list.contains(DataFlavor.imageFlavor)
|
||||
|| list.contains(DataFlavor.javaFileListFlavor)) {
|
||||
@@ -183,9 +186,8 @@ public class AlphaMaskDemo2 implements Runnable {
|
||||
return true;
|
||||
}
|
||||
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
|
||||
List files = (List)t
|
||||
.getTransferData(DataFlavor.javaFileListFlavor);
|
||||
File f = (File)files.get(0);
|
||||
List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
|
||||
File f = files.get(0);
|
||||
URL url = new URL("file://"
|
||||
+ f.toURI().toURL().getPath());
|
||||
Image image = Toolkit.getDefaultToolkit().getImage(url);
|
||||
|
Antes Largura: | Altura: | Tamanho: 18 KiB Depois Largura: | Altura: | Tamanho: 18 KiB |
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="/platform"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>balloonmanagerdemo</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="jnacontrib.balloonmanagerdemo" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project jnacontrib.balloonmanagerdemo.</description>
|
||||
<!-- Locations -->
|
||||
<property name="src" location="."/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="jna-dist" location="../../dist"/>
|
||||
|
||||
<property name="classes" location="${build}/classes"/>
|
||||
<property name="jar" location="${build}/demo-balloonmanager.jar"/>
|
||||
<property name="file.reference.jna.build" location="../../build"/>
|
||||
<property name="file.reference.jna.jar" location="../../build/jna.jar"/>
|
||||
<property name="main-class" value="com.sun.jna.contrib.demo.BalloonManagerDemo" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset file="${file.reference.jna.jar}"/>
|
||||
<fileset dir="../platform/dist" includes="platform.jar"/>
|
||||
</path>
|
||||
|
||||
<!-- Run Demo. -->
|
||||
<target name="run" depends="compile">
|
||||
<java classname="${main-class}" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${classes}" />
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Delete class and jar files. -->
|
||||
<target name="clean">
|
||||
<delete dir="${classes}"/>
|
||||
<delete file="${jar}"/>
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile all classes. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${classes}"/>
|
||||
|
||||
<!-- Compile the project. -->
|
||||
<javac srcdir="${src}" destdir="${classes}" target="1.5" source="1.5" encoding="UTF-8" debug="on">
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
<src>
|
||||
<dirset dir="${src}"/>
|
||||
</src>
|
||||
</javac>
|
||||
|
||||
<!-- Copy all non-java files to classes. -->
|
||||
<copy todir="${classes}/com">
|
||||
<fileset dir="${src}/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- platform -->
|
||||
<fileset dir="../platform/build/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- jna -->
|
||||
<fileset dir="${file.reference.jna.build}/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- Create jar-file. -->
|
||||
<target name="jar" depends="compile">
|
||||
<jar jarfile="${jar}" basedir="${classes}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
+6
-1
@@ -10,7 +10,7 @@
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
||||
* more details.
|
||||
*/
|
||||
package com.sun.jna.examples;
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
@@ -31,11 +31,14 @@ import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.JWindow;
|
||||
import javax.swing.Popup;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import com.sun.jna.platform.WindowUtils;
|
||||
|
||||
/**
|
||||
* Provides a popup balloon containing an arbitrary component. This provides
|
||||
* a form of content-specific decoration less transient than a tooltip, and less
|
||||
@@ -54,6 +57,7 @@ public class BalloonManager {
|
||||
}
|
||||
|
||||
private static class DropShadow extends JWindow {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final float SHADOW_ALPHA = .25f;
|
||||
private static final float YSCALE = .80f;
|
||||
private static final double ANGLE = 2*Math.PI/24;
|
||||
@@ -146,6 +150,7 @@ public class BalloonManager {
|
||||
}
|
||||
|
||||
private static final class BubbleWindow extends JWindow {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final int Y_OFFSET = 50;
|
||||
private static final int ARC = 25;
|
||||
|
||||
+4
-1
@@ -10,7 +10,7 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.examples;
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
@@ -24,6 +24,7 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
@@ -35,6 +36,8 @@ import javax.swing.SwingConstants;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import com.sun.jna.platform.WindowUtils;
|
||||
|
||||
/** Demonstration of BalloonManager. */
|
||||
public class BalloonManagerDemo {
|
||||
private static final int ICON_SIZE = 48;
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="/platform"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>balloontips</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="jnacontrib.balloontipsdemo" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project jnacontrib.balloontipsdemo.</description>
|
||||
<!-- Locations -->
|
||||
<property name="src" location="."/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="jna-dist" location="../../dist"/>
|
||||
|
||||
<property name="classes" location="${build}/classes"/>
|
||||
<property name="jar" location="${build}/demo-balloontips.jar"/>
|
||||
<property name="file.reference.jna.build" location="../../build"/>
|
||||
<property name="file.reference.jna.jar" location="../../build/jna.jar"/>
|
||||
<property name="main-class" value="com.sun.jna.contrib.demo.FilteredTextField" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset file="${file.reference.jna.jar}"/>
|
||||
<fileset dir="../platform/dist" includes="platform.jar"/>
|
||||
</path>
|
||||
|
||||
<!-- Run Demo. -->
|
||||
<target name="run" depends="compile">
|
||||
<java classname="${main-class}" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${classes}" />
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Delete class and jar files. -->
|
||||
<target name="clean">
|
||||
<delete dir="${classes}"/>
|
||||
<delete file="${jar}"/>
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile all classes. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${classes}"/>
|
||||
|
||||
<!-- Compile the project. -->
|
||||
<javac srcdir="${src}" destdir="${classes}" target="1.5" source="1.5" encoding="UTF-8" debug="on">
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
<src>
|
||||
<dirset dir="${src}"/>
|
||||
</src>
|
||||
</javac>
|
||||
|
||||
<!-- Copy all non-java files to classes. -->
|
||||
<copy todir="${classes}/com">
|
||||
<fileset dir="${src}/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- platform -->
|
||||
<fileset dir="../platform/build/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- jna -->
|
||||
<fileset dir="${file.reference.jna.build}/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- Create jar-file. -->
|
||||
<target name="jar" depends="compile">
|
||||
<jar jarfile="${jar}" basedir="${classes}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
+3
-6
@@ -1,4 +1,4 @@
|
||||
//package bms.ui.widgets;
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
@@ -30,7 +30,7 @@ import javax.swing.Popup;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import com.sun.jna.examples.WindowUtils;
|
||||
import com.sun.jna.platform.WindowUtils;
|
||||
|
||||
/**
|
||||
* The BalloonTipManager class handles creation and disposal of balloon style
|
||||
@@ -61,8 +61,8 @@ public class BalloonTipManager {
|
||||
/*
|
||||
* The BalloonTip class defines the look of the BalloonTip object.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
private static final class BalloonTip extends JWindow {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Integer HMARGIN = 10;
|
||||
private static final Integer VMARGIN = 6;
|
||||
private static final Integer VSPACER = 4;
|
||||
@@ -476,7 +476,6 @@ public class BalloonTipManager {
|
||||
/*
|
||||
* This class handles events spawned from moving the component.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
final class ComponentEar extends ComponentAdapter {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -491,7 +490,6 @@ public class BalloonTipManager {
|
||||
/*
|
||||
* This class handles events spawned when a mouse button is pressed.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
final class MouseEar extends MouseAdapter {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -506,7 +504,6 @@ public class BalloonTipManager {
|
||||
/*
|
||||
* This class handles events spawned when the component loses focus.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
final class FocusEar extends FocusAdapter {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
//package bms.ui.widgets;
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/jna/dist/jna.jar"/>
|
||||
<classpathentry kind="src" path="/platform"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>dnddemo</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="jnacontrib.dnddemo" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project jnacontrib.dnddemo.</description>
|
||||
<!-- Locations -->
|
||||
<property name="src" location="."/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="jna-dist" location="../../dist"/>
|
||||
|
||||
<property name="classes" location="${build}/classes"/>
|
||||
<property name="jar" location="${build}/demo-dnd.jar"/>
|
||||
<property name="file.reference.jna.build" location="../../build"/>
|
||||
<property name="file.reference.jna.jar" location="../../build/jna.jar"/>
|
||||
<property name="main-class" value="com.sun.jna.contrib.demo.GhostedDragImageDemo" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset file="${file.reference.jna.jar}"/>
|
||||
<fileset dir="../platform/dist" includes="platform.jar"/>
|
||||
</path>
|
||||
|
||||
<!-- Run Demo. -->
|
||||
<target name="run" depends="compile">
|
||||
<java classname="${main-class}" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${classes}" />
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Delete class and jar files. -->
|
||||
<target name="clean">
|
||||
<delete dir="${classes}"/>
|
||||
<delete file="${jar}"/>
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile all classes. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${classes}"/>
|
||||
|
||||
<!-- Compile the project. -->
|
||||
<javac srcdir="${src}" destdir="${classes}" target="1.5" source="1.5" encoding="UTF-8" debug="on">
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
<src>
|
||||
<dirset dir="${src}"/>
|
||||
</src>
|
||||
</javac>
|
||||
|
||||
<!-- Copy all non-java files to classes. -->
|
||||
<copy todir="${classes}/com">
|
||||
<fileset dir="${src}/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- platform -->
|
||||
<fileset dir="../platform/build/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- jna -->
|
||||
<fileset dir="${file.reference.jna.build}/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- Create jar-file. -->
|
||||
<target name="jar" depends="compile">
|
||||
<jar jarfile="${jar}" basedir="${classes}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
+7
-2
@@ -10,7 +10,7 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.examples.dnd;
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
@@ -32,6 +32,10 @@ import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import com.sun.jna.platform.dnd.DragHandler;
|
||||
import com.sun.jna.platform.dnd.DropHandler;
|
||||
|
||||
|
||||
/** Demonstrate ghosted drag images. Unfortunately, Swing drag support hides
|
||||
* the hooks we need to move the drag image around, so we don't use it and
|
||||
* roll our own.
|
||||
@@ -59,7 +63,8 @@ public class GhostedDragImageDemo {
|
||||
}
|
||||
|
||||
public static class DragLabel extends JLabel {
|
||||
private boolean dragging;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private boolean dragging;
|
||||
public DragLabel(Icon icon) {
|
||||
super(icon);
|
||||
new DragHandler(this, DnDConstants.ACTION_COPY_OR_MOVE) {
|
||||
Arquivo executável → Arquivo normal
|
Antes Largura: | Altura: | Tamanho: 28 KiB Depois Largura: | Altura: | Tamanho: 28 KiB |
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" output="build.eclipse/contrib-test-classes" path="test"/>
|
||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/jna"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||
<classpathentry kind="lib" path="/jna/dist/jna.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ntservice</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
Arquivo binário não exibido.
@@ -19,7 +19,7 @@ is divided into following sections:
|
||||
- cleanup
|
||||
|
||||
-->
|
||||
<project name="JnaContrib-impl" default="default" basedir=".." xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:j2seproject2="http://www.netbeans.org/ns/j2se-project/2" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:jaxws="http://www.netbeans.org/ns/jax-ws/1">
|
||||
<project name="ntservice-impl" default="default" basedir=".." xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:j2seproject2="http://www.netbeans.org/ns/j2se-project/2" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:jaxws="http://www.netbeans.org/ns/jax-ws/1">
|
||||
<target name="default" depends="test,jar,javadoc" description="Build and test whole project."/>
|
||||
<!--
|
||||
======================
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
application.args=
|
||||
file.reference.jna.jar=D:\\temp\\JnaContrib\\lib\\jna.jar
|
||||
javac.debug=true
|
||||
javadoc.preview=true
|
||||
jaxws.endorsed.dir=D:\\Program Files\\netbeans551\\ide7\\modules\\ext\\jaxws21\\api
|
||||
user.properties.file=C:\\Users\\tb\\.netbeans\\5.5.1\\build.properties
|
||||
@@ -14,12 +14,13 @@ debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/JnaContrib.jar
|
||||
dist.jar=${dist.dir}/contrib-ntservice.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
file.reference.jna.jar=lib/jna.jar
|
||||
file.reference.jna.jar=../../build/jna.jar
|
||||
libs.junit.classpath=../../lib/junit.jar
|
||||
jar.compress=false
|
||||
javac.classpath=\
|
||||
${file.reference.jna.jar}
|
||||
${file.reference.jna.jar};
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>JnaContrib</name>
|
||||
<name>ntservice</name>
|
||||
<minimum-ant-version>1.6.5</minimum-ant-version>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
|
||||
@@ -9,10 +9,14 @@
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
import static com.sun.jna.Library.*;
|
||||
import com.sun.jna.TypeMapper;
|
||||
import com.sun.jna.win32.*;
|
||||
import java.util.*;
|
||||
import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER;
|
||||
import static com.sun.jna.Library.OPTION_TYPE_MAPPER;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.jna.win32.W32APIFunctionMapper;
|
||||
import com.sun.jna.win32.W32APITypeMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -24,5 +28,6 @@ public interface Options {
|
||||
put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
|
||||
put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
|
||||
}
|
||||
private static final long serialVersionUID = 1L;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -9,11 +9,6 @@
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary.StdCallCallback;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -19,8 +19,6 @@ import java.util.*;
|
||||
* @author TB
|
||||
*/
|
||||
public class Accounts {
|
||||
private static Object userInfoLock = new Object();
|
||||
private static Object groupInfoLock = new Object();
|
||||
|
||||
/** Creates a new instance of Accounts */
|
||||
private Accounts() {
|
||||
@@ -290,7 +288,6 @@ public class Accounts {
|
||||
IntByReference cbSid;
|
||||
IntByReference cchReferencedDomainName;
|
||||
PointerByReference peUse;
|
||||
String sidString = null;
|
||||
byte[] sid;
|
||||
char[] referencedDomainName;
|
||||
|
||||
|
||||
@@ -9,17 +9,20 @@
|
||||
|
||||
package jnacontrib.win32;
|
||||
|
||||
import jnacontrib.jna.*;
|
||||
import com.sun.jna.ptr.ByteByReference;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import jnacontrib.jna.Advapi32;
|
||||
import jnacontrib.jna.WINBASE;
|
||||
import jnacontrib.jna.WINERROR;
|
||||
import jnacontrib.jna.WINNT;
|
||||
import jnacontrib.jna.WINREG;
|
||||
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
/**
|
||||
* Methods for accessing the Windows Registry. Only String and DWORD values supported at the moment.
|
||||
*/
|
||||
|
||||
@@ -180,7 +180,6 @@ public abstract class Win32Service {
|
||||
*/
|
||||
public void init() {
|
||||
Advapi32 advapi32;
|
||||
Advapi32.SERVICE_TABLE_ENTRY[] entries = new Advapi32.SERVICE_TABLE_ENTRY[2];
|
||||
Advapi32.SERVICE_TABLE_ENTRY entry;
|
||||
|
||||
serviceMain = new ServiceMain();
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" output="build.eclipse/contrib-test-classes" path="test"/>
|
||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/jna"/>
|
||||
<classpathentry kind="lib" path="/jna/dist/jna.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>platform</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="platform" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project platform.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar-with-manifest: JAR building (if you are using a manifest)
|
||||
-do-jar-without-manifest: JAR building (if you are not using a manifest)
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="JnaContrib-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
<condition property="tests.platform" value="test-win32">
|
||||
<os family="windows"/>
|
||||
</condition>
|
||||
<target name="test" description="Run unit tests." if="tests.platform">
|
||||
<antcall target="${tests.platform}" />
|
||||
</target>
|
||||
<target name="test-win32" depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" />
|
||||
</project>
|
||||
@@ -0,0 +1,541 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
*** GENERATED FROM project.xml - DO NOT EDIT ***
|
||||
*** EDIT ../build.xml INSTEAD ***
|
||||
|
||||
For the purpose of easier reading the script
|
||||
is divided into following sections:
|
||||
|
||||
- initialization
|
||||
- compilation
|
||||
- jar
|
||||
- execution
|
||||
- debugging
|
||||
- javadoc
|
||||
- junit compilation
|
||||
- junit execution
|
||||
- junit debugging
|
||||
- applet
|
||||
- cleanup
|
||||
|
||||
-->
|
||||
<project name="platform-impl" default="default" basedir=".." xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:j2seproject2="http://www.netbeans.org/ns/j2se-project/2" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:jaxws="http://www.netbeans.org/ns/jax-ws/1">
|
||||
<target name="default" depends="test,jar,javadoc" description="Build and test whole project."/>
|
||||
<!--
|
||||
======================
|
||||
INITIALIZATION SECTION
|
||||
======================
|
||||
-->
|
||||
<target name="-pre-init">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-init-private" depends="-pre-init">
|
||||
<property file="nbproject/private/private.properties"/>
|
||||
</target>
|
||||
<target name="-init-user" depends="-pre-init,-init-private">
|
||||
<property file="${user.properties.file}"/>
|
||||
<!-- The two properties below are usually overridden -->
|
||||
<!-- by the active platform. Just a fallback. -->
|
||||
<property name="default.javac.source" value="1.4"/>
|
||||
<property name="default.javac.target" value="1.4"/>
|
||||
</target>
|
||||
<target name="-init-project" depends="-pre-init,-init-private,-init-user">
|
||||
<property file="nbproject/project.properties"/>
|
||||
</target>
|
||||
<target name="-do-init" depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property">
|
||||
<available file="${manifest.file}" property="manifest.available"/>
|
||||
<condition property="manifest.available+main.class">
|
||||
<and>
|
||||
<isset property="manifest.available"/>
|
||||
<isset property="main.class"/>
|
||||
<not>
|
||||
<equals arg1="${main.class}" arg2="" trim="true"/>
|
||||
</not>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="manifest.available+main.class+mkdist.available">
|
||||
<and>
|
||||
<istrue value="${manifest.available+main.class}"/>
|
||||
<isset property="libs.CopyLibs.classpath"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="have.tests">
|
||||
<or>
|
||||
<available file="${test.src.dir}"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="have.sources">
|
||||
<or>
|
||||
<available file="${src.dir}"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="netbeans.home+have.tests">
|
||||
<and>
|
||||
<isset property="netbeans.home"/>
|
||||
<isset property="have.tests"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="no.javadoc.preview">
|
||||
<isfalse value="${javadoc.preview}"/>
|
||||
</condition>
|
||||
<property name="run.jvmargs" value=""/>
|
||||
<property name="javac.compilerargs" value=""/>
|
||||
<property name="work.dir" value="${basedir}"/>
|
||||
<condition property="no.deps">
|
||||
<and>
|
||||
<istrue value="${no.dependencies}"/>
|
||||
</and>
|
||||
</condition>
|
||||
<property name="javac.debug" value="true"/>
|
||||
<property name="javadoc.preview" value="true"/>
|
||||
</target>
|
||||
<target name="-post-init">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-init-check" depends="-pre-init,-init-private,-init-user,-init-project,-do-init">
|
||||
<fail unless="src.dir">Must set src.dir</fail>
|
||||
<fail unless="test.src.dir">Must set test.src.dir</fail>
|
||||
<fail unless="build.dir">Must set build.dir</fail>
|
||||
<fail unless="dist.dir">Must set dist.dir</fail>
|
||||
<fail unless="build.classes.dir">Must set build.classes.dir</fail>
|
||||
<fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
|
||||
<fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
|
||||
<fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
|
||||
<fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
|
||||
<fail unless="dist.jar">Must set dist.jar</fail>
|
||||
</target>
|
||||
<target name="-init-macrodef-property">
|
||||
<macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="name"/>
|
||||
<attribute name="value"/>
|
||||
<sequential>
|
||||
<property name="@{name}" value="${@{value}}"/>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-javac">
|
||||
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute name="srcdir" default="${src.dir}"/>
|
||||
<attribute name="destdir" default="${build.classes.dir}"/>
|
||||
<attribute name="classpath" default="${javac.classpath}"/>
|
||||
<attribute name="debug" default="${javac.debug}"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<javac srcdir="@{srcdir}" destdir="@{destdir}" debug="@{debug}" deprecation="${javac.deprecation}" source="${javac.source}" target="${javac.target}" includeantruntime="false">
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
<compilerarg line="${javac.compilerargs}"/>
|
||||
<customize/>
|
||||
</javac>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-junit">
|
||||
<macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute name="includes" default="**/*Test.java"/>
|
||||
<sequential>
|
||||
<junit showoutput="true" fork="true" dir="${basedir}" failureproperty="tests.failed" errorproperty="tests.failed">
|
||||
<batchtest todir="${build.test.results.dir}">
|
||||
<fileset dir="${test.src.dir}" includes="@{includes}"/>
|
||||
</batchtest>
|
||||
<classpath>
|
||||
<path path="${run.test.classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper type="glob" from="test-sys-prop.*" to="*"/>
|
||||
</syspropertyset>
|
||||
<formatter type="brief" usefile="false"/>
|
||||
<formatter type="xml"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
</junit>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-nbjpda">
|
||||
<macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="name" default="${main.class}"/>
|
||||
<attribute name="classpath" default="${debug.classpath}"/>
|
||||
<attribute name="stopclassname" default=""/>
|
||||
<sequential>
|
||||
<nbjpdastart transport="dt_socket" addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}">
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
</nbjpdastart>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
<macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="dir" default="${build.classes.dir}"/>
|
||||
<sequential>
|
||||
<nbjpdareload>
|
||||
<fileset includes="${fix.includes}*.class" dir="@{dir}"/>
|
||||
</nbjpdareload>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-debug">
|
||||
<macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute name="classname" default="${main.class}"/>
|
||||
<attribute name="classpath" default="${debug.classpath}"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<java fork="true" classname="@{classname}" dir="${work.dir}">
|
||||
<jvmarg value="-Xdebug"/>
|
||||
<jvmarg value="-Xnoagent"/>
|
||||
<jvmarg value="-Djava.compiler=none"/>
|
||||
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="run-sys-prop."/>
|
||||
<mapper type="glob" from="run-sys-prop.*" to="*"/>
|
||||
</syspropertyset>
|
||||
<customize/>
|
||||
</java>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-java">
|
||||
<macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="classname" default="${main.class}"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<java fork="true" classname="@{classname}" dir="${work.dir}">
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<classpath>
|
||||
<path path="${run.classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="run-sys-prop."/>
|
||||
<mapper type="glob" from="run-sys-prop.*" to="*"/>
|
||||
</syspropertyset>
|
||||
<customize/>
|
||||
</java>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-presetdef-jar">
|
||||
<presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<jar jarfile="${dist.jar}" compress="${jar.compress}">
|
||||
<j2seproject1:fileset dir="${build.classes.dir}"/>
|
||||
</jar>
|
||||
</presetdef>
|
||||
</target>
|
||||
<target name="init" depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar"/>
|
||||
<!--
|
||||
===================
|
||||
COMPILATION SECTION
|
||||
===================
|
||||
-->
|
||||
<target name="deps-jar" depends="init" unless="no.deps"/>
|
||||
<target name="-pre-pre-compile" depends="init,deps-jar">
|
||||
<mkdir dir="${build.classes.dir}"/>
|
||||
</target>
|
||||
<target name="-pre-compile">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile" depends="init,deps-jar,-pre-pre-compile,-pre-compile" if="have.sources">
|
||||
<j2seproject3:javac/>
|
||||
<copy todir="${build.classes.dir}">
|
||||
<fileset dir="${src.dir}" excludes="${build.classes.excludes}"/>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-post-compile">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile" depends="init,deps-jar,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project."/>
|
||||
<target name="-pre-compile-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile-single" depends="init,deps-jar,-pre-pre-compile">
|
||||
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
|
||||
<j2seproject3:javac>
|
||||
<customize>
|
||||
<patternset includes="${javac.includes}"/>
|
||||
</customize>
|
||||
</j2seproject3:javac>
|
||||
</target>
|
||||
<target name="-post-compile-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile-single" depends="init,deps-jar,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single"/>
|
||||
<!--
|
||||
====================
|
||||
JAR BUILDING SECTION
|
||||
====================
|
||||
-->
|
||||
<target name="-pre-pre-jar" depends="init">
|
||||
<dirname property="dist.jar.dir" file="${dist.jar}"/>
|
||||
<mkdir dir="${dist.jar.dir}"/>
|
||||
</target>
|
||||
<target name="-pre-jar">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-jar-without-manifest" depends="init,compile,-pre-pre-jar,-pre-jar" unless="manifest.available">
|
||||
<j2seproject1:jar/>
|
||||
</target>
|
||||
<target name="-do-jar-with-manifest" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available" unless="manifest.available+main.class">
|
||||
<j2seproject1:jar manifest="${manifest.file}"/>
|
||||
</target>
|
||||
<target name="-do-jar-with-mainclass" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class" unless="manifest.available+main.class+mkdist.available">
|
||||
<j2seproject1:jar manifest="${manifest.file}">
|
||||
<j2seproject1:manifest>
|
||||
<j2seproject1:attribute name="Main-Class" value="${main.class}"/>
|
||||
</j2seproject1:manifest>
|
||||
</j2seproject1:jar>
|
||||
<echo>To run this application from the command line without Ant, try:</echo>
|
||||
<property name="build.classes.dir.resolved" location="${build.classes.dir}"/>
|
||||
<property name="dist.jar.resolved" location="${dist.jar}"/>
|
||||
<pathconvert property="run.classpath.with.dist.jar">
|
||||
<path path="${run.classpath}"/>
|
||||
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
|
||||
</pathconvert>
|
||||
<echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
|
||||
</target>
|
||||
<target name="-do-jar-with-libraries" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class+mkdist.available">
|
||||
<property name="build.classes.dir.resolved" location="${build.classes.dir}"/>
|
||||
<pathconvert property="run.classpath.without.build.classes.dir">
|
||||
<path path="${run.classpath}"/>
|
||||
<map from="${build.classes.dir.resolved}" to=""/>
|
||||
</pathconvert>
|
||||
<pathconvert property="jar.classpath" pathsep=" ">
|
||||
<path path="${run.classpath.without.build.classes.dir}"/>
|
||||
<chainedmapper>
|
||||
<flattenmapper/>
|
||||
<globmapper from="*" to="lib/*"/>
|
||||
</chainedmapper>
|
||||
</pathconvert>
|
||||
<taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" name="copylibs" classpath="${libs.CopyLibs.classpath}"/>
|
||||
<copylibs manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}" jarfile="${dist.jar}" compress="${jar.compress}">
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main.class}"/>
|
||||
<attribute name="Class-Path" value="${jar.classpath}"/>
|
||||
</manifest>
|
||||
</copylibs>
|
||||
<echo>To run this application from the command line without Ant, try:</echo>
|
||||
<property name="dist.jar.resolved" location="${dist.jar}"/>
|
||||
<echo>java -jar "${dist.jar.resolved}"</echo>
|
||||
</target>
|
||||
<target name="-post-jar">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="jar" depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR."/>
|
||||
<!--
|
||||
=================
|
||||
EXECUTION SECTION
|
||||
=================
|
||||
-->
|
||||
<target name="run" depends="init,compile" description="Run a main class.">
|
||||
<j2seproject1:java>
|
||||
<customize>
|
||||
<arg line="${application.args}"/>
|
||||
</customize>
|
||||
</j2seproject1:java>
|
||||
</target>
|
||||
<target name="run-single" depends="init,compile-single">
|
||||
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
|
||||
<j2seproject1:java classname="${run.class}"/>
|
||||
</target>
|
||||
<!--
|
||||
=================
|
||||
DEBUGGING SECTION
|
||||
=================
|
||||
-->
|
||||
<target name="-debug-start-debugger" if="netbeans.home" depends="init">
|
||||
<j2seproject1:nbjpdastart name="${debug.class}"/>
|
||||
</target>
|
||||
<target name="-debug-start-debuggee" depends="init,compile">
|
||||
<j2seproject3:debug>
|
||||
<customize>
|
||||
<arg line="${application.args}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</target>
|
||||
<target name="debug" if="netbeans.home" depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE."/>
|
||||
<target name="-debug-start-debugger-stepinto" if="netbeans.home" depends="init">
|
||||
<j2seproject1:nbjpdastart stopclassname="${main.class}"/>
|
||||
</target>
|
||||
<target name="debug-stepinto" if="netbeans.home" depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee"/>
|
||||
<target name="-debug-start-debuggee-single" if="netbeans.home" depends="init,compile-single">
|
||||
<fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
|
||||
<j2seproject3:debug classname="${debug.class}"/>
|
||||
</target>
|
||||
<target name="debug-single" if="netbeans.home" depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single"/>
|
||||
<target name="-pre-debug-fix" depends="init">
|
||||
<fail unless="fix.includes">Must set fix.includes</fail>
|
||||
<property name="javac.includes" value="${fix.includes}.java"/>
|
||||
</target>
|
||||
<target name="-do-debug-fix" if="netbeans.home" depends="init,-pre-debug-fix,compile-single">
|
||||
<j2seproject1:nbjpdareload/>
|
||||
</target>
|
||||
<target name="debug-fix" if="netbeans.home" depends="init,-pre-debug-fix,-do-debug-fix"/>
|
||||
<!--
|
||||
===============
|
||||
JAVADOC SECTION
|
||||
===============
|
||||
-->
|
||||
<target name="-javadoc-build" depends="init">
|
||||
<mkdir dir="${dist.javadoc.dir}"/>
|
||||
<javadoc destdir="${dist.javadoc.dir}" source="${javac.source}" notree="${javadoc.notree}" use="${javadoc.use}" nonavbar="${javadoc.nonavbar}" noindex="${javadoc.noindex}" splitindex="${javadoc.splitindex}" author="${javadoc.author}" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}" private="${javadoc.private}" additionalparam="${javadoc.additionalparam}" failonerror="true" useexternalfile="true">
|
||||
<classpath>
|
||||
<path path="${javac.classpath}"/>
|
||||
</classpath>
|
||||
<sourcepath>
|
||||
<pathelement location="${src.dir}"/>
|
||||
</sourcepath>
|
||||
<packageset dir="${src.dir}" includes="*/**"/>
|
||||
<fileset dir="${src.dir}" includes="*.java"/>
|
||||
</javadoc>
|
||||
</target>
|
||||
<target name="-javadoc-browse" if="netbeans.home" unless="no.javadoc.preview" depends="init,-javadoc-build">
|
||||
<nbbrowse file="${dist.javadoc.dir}/index.html"/>
|
||||
</target>
|
||||
<target name="javadoc" depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc."/>
|
||||
<!--
|
||||
=========================
|
||||
JUNIT COMPILATION SECTION
|
||||
=========================
|
||||
-->
|
||||
<target name="-pre-pre-compile-test" if="have.tests" depends="init,compile">
|
||||
<mkdir dir="${build.test.classes.dir}"/>
|
||||
</target>
|
||||
<target name="-pre-compile-test">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile-test" if="have.tests" depends="init,compile,-pre-pre-compile-test,-pre-compile-test">
|
||||
<j2seproject3:javac srcdir="${test.src.dir}" destdir="${build.test.classes.dir}" debug="true" classpath="${javac.test.classpath}"/>
|
||||
<copy todir="${build.test.classes.dir}">
|
||||
<fileset dir="${test.src.dir}" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-post-compile-test">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile-test" depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test"/>
|
||||
<target name="-pre-compile-test-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile-test-single" if="have.tests" depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single">
|
||||
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
|
||||
<j2seproject3:javac srcdir="${test.src.dir}" destdir="${build.test.classes.dir}" debug="true" classpath="${javac.test.classpath}">
|
||||
<customize>
|
||||
<patternset includes="${javac.includes}"/>
|
||||
</customize>
|
||||
</j2seproject3:javac>
|
||||
<copy todir="${build.test.classes.dir}">
|
||||
<fileset dir="${test.src.dir}" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-post-compile-test-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile-test-single" depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single"/>
|
||||
<!--
|
||||
=======================
|
||||
JUNIT EXECUTION SECTION
|
||||
=======================
|
||||
-->
|
||||
<target name="-pre-test-run" if="have.tests" depends="init">
|
||||
<mkdir dir="${build.test.results.dir}"/>
|
||||
</target>
|
||||
<target name="-do-test-run" if="have.tests" depends="init,compile-test,-pre-test-run">
|
||||
<j2seproject3:junit/>
|
||||
</target>
|
||||
<target name="-post-test-run" if="have.tests" depends="init,compile-test,-pre-test-run,-do-test-run">
|
||||
<fail if="tests.failed">Some tests failed; see details above.</fail>
|
||||
</target>
|
||||
<target name="test-report" if="have.tests" depends="init"/>
|
||||
<target name="-test-browse" if="netbeans.home+have.tests" depends="init"/>
|
||||
<target name="test" depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests."/>
|
||||
<target name="-pre-test-run-single" if="have.tests" depends="init">
|
||||
<mkdir dir="${build.test.results.dir}"/>
|
||||
</target>
|
||||
<target name="-do-test-run-single" if="have.tests" depends="init,compile-test-single,-pre-test-run-single">
|
||||
<fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
|
||||
<j2seproject3:junit includes="${test.includes}"/>
|
||||
</target>
|
||||
<target name="-post-test-run-single" if="have.tests" depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single">
|
||||
<fail if="tests.failed">Some tests failed; see details above.</fail>
|
||||
</target>
|
||||
<target name="test-single" depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test."/>
|
||||
<!--
|
||||
=======================
|
||||
JUNIT DEBUGGING SECTION
|
||||
=======================
|
||||
-->
|
||||
<target name="-debug-start-debuggee-test" if="have.tests" depends="init,compile-test">
|
||||
<fail unless="test.class">Must select one file in the IDE or set test.class</fail>
|
||||
<j2seproject3:debug classname="junit.textui.TestRunner" classpath="${debug.test.classpath}">
|
||||
<customize>
|
||||
<arg line="${test.class}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</target>
|
||||
<target name="-debug-start-debugger-test" if="netbeans.home+have.tests" depends="init,compile-test">
|
||||
<j2seproject1:nbjpdastart name="${test.class}" classpath="${debug.test.classpath}"/>
|
||||
</target>
|
||||
<target name="debug-test" depends="init,compile-test,-debug-start-debugger-test,-debug-start-debuggee-test"/>
|
||||
<target name="-do-debug-fix-test" if="netbeans.home" depends="init,-pre-debug-fix,compile-test-single">
|
||||
<j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
|
||||
</target>
|
||||
<target name="debug-fix-test" if="netbeans.home" depends="init,-pre-debug-fix,-do-debug-fix-test"/>
|
||||
<!--
|
||||
=========================
|
||||
APPLET EXECUTION SECTION
|
||||
=========================
|
||||
-->
|
||||
<target name="run-applet" depends="init,compile-single">
|
||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
||||
<j2seproject1:java classname="sun.applet.AppletViewer">
|
||||
<customize>
|
||||
<arg value="${applet.url}"/>
|
||||
</customize>
|
||||
</j2seproject1:java>
|
||||
</target>
|
||||
<!--
|
||||
=========================
|
||||
APPLET DEBUGGING SECTION
|
||||
=========================
|
||||
-->
|
||||
<target name="-debug-start-debuggee-applet" if="netbeans.home" depends="init,compile-single">
|
||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
||||
<j2seproject3:debug classname="sun.applet.AppletViewer">
|
||||
<customize>
|
||||
<arg value="${applet.url}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</target>
|
||||
<target name="debug-applet" if="netbeans.home" depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet"/>
|
||||
<!--
|
||||
===============
|
||||
CLEANUP SECTION
|
||||
===============
|
||||
-->
|
||||
<target name="deps-clean" depends="init" unless="no.deps"/>
|
||||
<target name="-do-clean" depends="init">
|
||||
<delete dir="${build.dir}"/>
|
||||
<delete dir="${dist.dir}"/>
|
||||
</target>
|
||||
<target name="-post-clean">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="clean" depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products."/>
|
||||
</project>
|
||||
@@ -0,0 +1,59 @@
|
||||
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
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>platform</name>
|
||||
<minimum-ant-version>1.6.5</minimum-ant-version>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
@@ -0,0 +1,135 @@
|
||||
/* 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.
|
||||
* <p/>
|
||||
* 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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.jna.platform.win32.W32FileMonitor;
|
||||
|
||||
/** Provides notification of file system changes. Actual capabilities may
|
||||
* vary slightly by platform.
|
||||
* <p>
|
||||
* Watched files which are removed from the filesystem are no longer watched.
|
||||
* @author twall
|
||||
*/
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class FileMonitor {
|
||||
|
||||
public static final int FILE_CREATED = 0x1;
|
||||
public static final int FILE_DELETED = 0x2;
|
||||
public static final int FILE_MODIFIED = 0x4;
|
||||
public static final int FILE_ACCESSED = 0x8;
|
||||
public static final int FILE_NAME_CHANGED_OLD = 0x10;
|
||||
public static final int FILE_NAME_CHANGED_NEW = 0x20;
|
||||
public static final int FILE_RENAMED = FILE_NAME_CHANGED_OLD|FILE_NAME_CHANGED_NEW;
|
||||
public static final int FILE_SIZE_CHANGED = 0x40;
|
||||
public static final int FILE_ATTRIBUTES_CHANGED = 0x80;
|
||||
public static final int FILE_SECURITY_CHANGED = 0x100;
|
||||
public static final int FILE_ANY = 0x1FF;
|
||||
|
||||
public interface FileListener {
|
||||
public void fileChanged(FileEvent e);
|
||||
}
|
||||
|
||||
public class FileEvent extends EventObject {
|
||||
private final File file;
|
||||
private final int type;
|
||||
public FileEvent(File file, int type) {
|
||||
super(FileMonitor.this);
|
||||
this.file = file;
|
||||
this.type = type;
|
||||
}
|
||||
public File getFile() { return file; }
|
||||
public int getType() { return type; }
|
||||
public String toString() {
|
||||
return "FileEvent: " + file + ":" + type;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<File, Integer> watched = new HashMap<File, Integer>();
|
||||
private List<FileListener> listeners = new ArrayList<FileListener>();
|
||||
|
||||
protected abstract void watch(File file, int mask, boolean recursive) throws IOException ;
|
||||
protected abstract void unwatch(File file);
|
||||
public abstract void dispose();
|
||||
|
||||
public void addWatch(File dir) throws IOException {
|
||||
addWatch(dir, FILE_ANY);
|
||||
}
|
||||
|
||||
public void addWatch(File dir, int mask) throws IOException {
|
||||
addWatch(dir, mask, dir.isDirectory());
|
||||
}
|
||||
|
||||
public void addWatch(File dir, int mask, boolean recursive) throws IOException {
|
||||
watched.put(dir, new Integer(mask));
|
||||
watch(dir, mask, recursive);
|
||||
}
|
||||
|
||||
public void removeWatch(File file) {
|
||||
if (watched.remove(file) != null) {
|
||||
unwatch(file);
|
||||
}
|
||||
}
|
||||
|
||||
protected void notify(FileEvent e) {
|
||||
for (FileListener listener : listeners) {
|
||||
listener.fileChanged(e);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addFileListener(FileListener listener) {
|
||||
List<FileListener> list = new ArrayList<FileListener>(listeners);
|
||||
list.add(listener);
|
||||
listeners = list;
|
||||
}
|
||||
|
||||
public synchronized void removeFileListener(FileListener x) {
|
||||
List<FileListener> list = new ArrayList<FileListener>(listeners);
|
||||
list.remove(x);
|
||||
listeners = list;
|
||||
}
|
||||
|
||||
protected void finalize() {
|
||||
for (File watchedFile : watched.keySet()) {
|
||||
removeWatch(watchedFile);
|
||||
}
|
||||
|
||||
dispose();
|
||||
}
|
||||
|
||||
/** Canonical lazy loading of a singleton. */
|
||||
private static class Holder {
|
||||
public static final FileMonitor INSTANCE;
|
||||
static {
|
||||
String os = System.getProperty("os.name");
|
||||
if (os.startsWith("Windows")) {
|
||||
INSTANCE = new W32FileMonitor();
|
||||
}
|
||||
else {
|
||||
throw new Error("FileMonitor not implemented for " + os);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static FileMonitor getInstance() {
|
||||
return Holder.INSTANCE;
|
||||
}
|
||||
}
|
||||
+27
-58
@@ -10,11 +10,15 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.examples;
|
||||
package com.sun.jna.platform;
|
||||
|
||||
import java.io.File;
|
||||
import com.sun.jna.examples.win32.Shell32;
|
||||
import com.sun.jna.examples.win32.Shell32.SHFILEOPSTRUCT;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.platform.mac.MacFileUtils;
|
||||
import com.sun.jna.platform.win32.W32FileUtils;
|
||||
|
||||
/** Miscellaneous file utils not provided for by Java. */
|
||||
public abstract class FileUtils {
|
||||
@@ -24,9 +28,9 @@ public abstract class FileUtils {
|
||||
}
|
||||
|
||||
/** Move the given file to the system trash, if one is available.
|
||||
Returns whether the operation was successful.
|
||||
Throws an exception on failure.
|
||||
*/
|
||||
public abstract boolean moveToTrash(File[] files);
|
||||
public abstract void moveToTrash(File[] files) throws IOException;
|
||||
|
||||
/** Canonical lazy loading of a singleton. */
|
||||
private static class Holder {
|
||||
@@ -47,48 +51,7 @@ public abstract class FileUtils {
|
||||
|
||||
public static FileUtils getInstance() {
|
||||
return Holder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class W32FileUtils extends FileUtils {
|
||||
|
||||
public boolean hasTrash() { return true; }
|
||||
|
||||
public boolean moveToTrash(File[] files) {
|
||||
Shell32 shell = Shell32.INSTANCE;
|
||||
SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT();
|
||||
fileop.wFunc = Shell32.FO_DELETE;
|
||||
String[] paths = new String[files.length];
|
||||
for (int i=0;i < paths.length;i++) {
|
||||
paths[i] = files[i].getAbsolutePath();
|
||||
}
|
||||
fileop.pFrom = fileop.encodePaths(paths);
|
||||
fileop.fFlags = Shell32.FOF_ALLOWUNDO|Shell32.FOF_NOCONFIRMATION|Shell32.FOF_SILENT;
|
||||
return shell.SHFileOperation(fileop) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MacFileUtils extends FileUtils {
|
||||
|
||||
public boolean hasTrash() { return true; }
|
||||
|
||||
public boolean moveToTrash(File[] files) {
|
||||
// TODO: use native API for moving to trash (if any)
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
File trash = new File(home, ".Trash");
|
||||
if (trash.exists()) {
|
||||
boolean success = true;
|
||||
for (int i=0;i < files.length;i++) {
|
||||
File src = files[i];
|
||||
File target = new File(trash, src.getName());
|
||||
if (!src.renameTo(target)) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class DefaultFileUtils extends FileUtils {
|
||||
|
||||
@@ -105,6 +68,9 @@ public abstract class FileUtils {
|
||||
trash = new File(desktop, ".Trash");
|
||||
if (!trash.exists()) {
|
||||
trash = new File(desktop, "Trash");
|
||||
if (!trash.exists()) {
|
||||
trash = new File(System.getProperty("fileutils.trash", "Trash"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,19 +85,22 @@ public abstract class FileUtils {
|
||||
/** The default implementation attempts to move the file to
|
||||
* the desktop "Trash" folder.
|
||||
*/
|
||||
public boolean moveToTrash(File[] files) {
|
||||
public void moveToTrash(File[] files) throws IOException {
|
||||
File trash = getTrashDirectory();
|
||||
if (trash.exists()) {
|
||||
boolean success = true;
|
||||
for (int i=0;i < files.length;i++) {
|
||||
File src = files[i];
|
||||
File target = new File(trash, src.getName());
|
||||
if (!src.renameTo(target))
|
||||
success = false;
|
||||
}
|
||||
return success;
|
||||
if (!trash.exists()) {
|
||||
throw new IOException("No trash location found (define fileutils.trash to be the path to the trash)");
|
||||
}
|
||||
List<File> failed = new ArrayList<File>();
|
||||
for (int i=0;i < files.length;i++) {
|
||||
File src = files[i];
|
||||
File target = new File(trash, src.getName());
|
||||
if (!src.renameTo(target)) {
|
||||
failed.add(src);
|
||||
}
|
||||
}
|
||||
if (failed.size() > 0) {
|
||||
throw new IOException("The following files could not be trashed: " + failed);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-14
@@ -10,16 +10,17 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.examples;
|
||||
package com.sun.jna.platform;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import com.sun.jna.Platform;
|
||||
import com.sun.jna.examples.unix.X11;
|
||||
import com.sun.jna.examples.unix.X11.Display;
|
||||
import com.sun.jna.examples.win32.User32;
|
||||
import com.sun.jna.platform.unix.X11;
|
||||
import com.sun.jna.platform.unix.X11.Display;
|
||||
import com.sun.jna.platform.win32.User32;
|
||||
import com.sun.jna.platform.win32.WinUser;
|
||||
|
||||
/** Provide access to the local keyboard state. Note that this is meaningless
|
||||
* on a headless system and some VNC setups.
|
||||
@@ -71,30 +72,30 @@ public class KeyboardUtils {
|
||||
}
|
||||
if (code == KeyEvent.VK_SHIFT) {
|
||||
if ((loc & KeyEvent.KEY_LOCATION_RIGHT) != 0) {
|
||||
return User32.VK_RSHIFT;
|
||||
return WinUser.VK_RSHIFT;
|
||||
}
|
||||
if ((loc & KeyEvent.KEY_LOCATION_LEFT) != 0) {
|
||||
return User32.VK_LSHIFT;
|
||||
return WinUser.VK_LSHIFT;
|
||||
}
|
||||
return User32.VK_SHIFT;
|
||||
return WinUser.VK_SHIFT;
|
||||
}
|
||||
if (code == KeyEvent.VK_CONTROL) {
|
||||
if ((loc & KeyEvent.KEY_LOCATION_RIGHT) != 0) {
|
||||
return User32.VK_RCONTROL;
|
||||
return WinUser.VK_RCONTROL;
|
||||
}
|
||||
if ((loc & KeyEvent.KEY_LOCATION_LEFT) != 0) {
|
||||
return User32.VK_LCONTROL;
|
||||
return WinUser.VK_LCONTROL;
|
||||
}
|
||||
return User32.VK_CONTROL;
|
||||
return WinUser.VK_CONTROL;
|
||||
}
|
||||
if (code == KeyEvent.VK_ALT) {
|
||||
if ((loc & KeyEvent.KEY_LOCATION_RIGHT) != 0) {
|
||||
return User32.VK_RMENU;
|
||||
return WinUser.VK_RMENU;
|
||||
}
|
||||
if ((loc & KeyEvent.KEY_LOCATION_LEFT) != 0) {
|
||||
return User32.VK_LMENU;
|
||||
return WinUser.VK_LMENU;
|
||||
}
|
||||
return User32.VK_MENU;
|
||||
return WinUser.VK_MENU;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -153,7 +154,7 @@ public class KeyboardUtils {
|
||||
int idx = code / 8;
|
||||
int shift = code % 8;
|
||||
if ((keys[idx] & (1 << shift)) != 0) {
|
||||
int sym = lib.XKeycodeToKeysym(dpy, (byte)code, 0);
|
||||
int sym = lib.XKeycodeToKeysym(dpy, (byte)code, 0).intValue();
|
||||
if (sym == keysym)
|
||||
return true;
|
||||
}
|
||||
+18
-18
@@ -11,7 +11,7 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.examples;
|
||||
package com.sun.jna.platform;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.DataBuffer;
|
||||
@@ -44,7 +44,7 @@ public class RasterRangesUtils {
|
||||
0x0008, 0x0004, 0x0002, 0x0001
|
||||
};
|
||||
|
||||
private static final Comparator COMPARATOR = new Comparator() {
|
||||
private static final Comparator<Object> COMPARATOR = new Comparator<Object>() {
|
||||
public int compare(Object o1, Object o2) {
|
||||
return ((Rectangle)o1).x - ((Rectangle)o2).x;
|
||||
}
|
||||
@@ -116,11 +116,11 @@ public class RasterRangesUtils {
|
||||
* @return true if the output succeeded, false otherwise
|
||||
*/
|
||||
public static boolean outputOccupiedRangesOfBinaryPixels(byte[] binaryBits, int w, int h, RangesOutput out) {
|
||||
Set rects = new HashSet();
|
||||
Set prevLine = Collections.EMPTY_SET;
|
||||
Set<Rectangle> rects = new HashSet<Rectangle>();
|
||||
Set<Rectangle> prevLine = Collections.EMPTY_SET;
|
||||
int scanlineBytes = binaryBits.length / h;
|
||||
for (int row = 0; row < h; row++) {
|
||||
Set curLine = new TreeSet(COMPARATOR);
|
||||
Set<Rectangle> curLine = new TreeSet<Rectangle>(COMPARATOR);
|
||||
int rowOffsetBytes = row * scanlineBytes;
|
||||
int startCol = -1;
|
||||
// Look at each batch of 8 columns in this row
|
||||
@@ -163,14 +163,14 @@ public class RasterRangesUtils {
|
||||
// end of last region
|
||||
curLine.add(new Rectangle(startCol, row, w - startCol, 1));
|
||||
}
|
||||
Set unmerged = mergeRects(prevLine, curLine);
|
||||
Set<Rectangle> unmerged = mergeRects(prevLine, curLine);
|
||||
rects.addAll(unmerged);
|
||||
prevLine = curLine;
|
||||
}
|
||||
// Add anything left over
|
||||
rects.addAll(prevLine);
|
||||
for (Iterator i=rects.iterator();i.hasNext();) {
|
||||
Rectangle r = (Rectangle)i.next();
|
||||
for (Iterator<Rectangle> i=rects.iterator();i.hasNext();) {
|
||||
Rectangle r = i.next();
|
||||
if (!out.outputRange(r.x, r.y, r.width, r.height)) {
|
||||
return false;
|
||||
}
|
||||
@@ -189,10 +189,10 @@ public class RasterRangesUtils {
|
||||
* @return true if the output succeeded, false otherwise
|
||||
*/
|
||||
public static boolean outputOccupiedRanges(int[] pixels, int w, int h, int occupationMask, RangesOutput out) {
|
||||
Set rects = new HashSet();
|
||||
Set prevLine = Collections.EMPTY_SET;
|
||||
Set<Rectangle> rects = new HashSet<Rectangle>();
|
||||
Set<Rectangle> prevLine = Collections.EMPTY_SET;
|
||||
for (int row = 0; row < h; row++) {
|
||||
Set curLine = new TreeSet(COMPARATOR);
|
||||
Set<Rectangle> curLine = new TreeSet<Rectangle>(COMPARATOR);
|
||||
int idxOffset = row * w;
|
||||
int startCol = -1;
|
||||
|
||||
@@ -213,14 +213,14 @@ public class RasterRangesUtils {
|
||||
// end of last region of current row
|
||||
curLine.add(new Rectangle(startCol, row, w-startCol, 1));
|
||||
}
|
||||
Set unmerged = mergeRects(prevLine, curLine);
|
||||
Set<Rectangle> unmerged = mergeRects(prevLine, curLine);
|
||||
rects.addAll(unmerged);
|
||||
prevLine = curLine;
|
||||
}
|
||||
// Add anything left over
|
||||
rects.addAll(prevLine);
|
||||
for (Iterator i=rects.iterator();i.hasNext();) {
|
||||
Rectangle r = (Rectangle)i.next();
|
||||
for (Iterator<Rectangle> i=rects.iterator();i.hasNext();) {
|
||||
Rectangle r = i.next();
|
||||
if (!out.outputRange(r.x, r.y, r.width, r.height)) {
|
||||
return false;
|
||||
}
|
||||
@@ -228,11 +228,11 @@ public class RasterRangesUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Set mergeRects(Set prev, Set current) {
|
||||
Set unmerged = new HashSet(prev);
|
||||
private static Set<Rectangle> mergeRects(Set<Rectangle> prev, Set<Rectangle> current) {
|
||||
Set<Rectangle> unmerged = new HashSet<Rectangle>(prev);
|
||||
if (!prev.isEmpty() && !current.isEmpty()) {
|
||||
Rectangle[] pr = (Rectangle[])prev.toArray(new Rectangle[prev.size()]);
|
||||
Rectangle[] cr = (Rectangle[])current.toArray(new Rectangle[current.size()]);
|
||||
Rectangle[] pr = prev.toArray(new Rectangle[prev.size()]);
|
||||
Rectangle[] cr = current.toArray(new Rectangle[current.size()]);
|
||||
int ipr = 0;
|
||||
int icr = 0;
|
||||
while (ipr < pr.length && icr < cr.length) {
|
||||
+205
-110
@@ -11,12 +11,12 @@
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.examples;
|
||||
package com.sun.jna.platform;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dialog;
|
||||
@@ -31,14 +31,14 @@ import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.AWTEventListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.AWTEventListener;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.ContainerEvent;
|
||||
import java.awt.event.HierarchyEvent;
|
||||
import java.awt.event.HierarchyListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.geom.Area;
|
||||
@@ -62,24 +62,26 @@ import com.sun.jna.Native;
|
||||
import com.sun.jna.NativeLong;
|
||||
import com.sun.jna.Platform;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.examples.unix.X11;
|
||||
import com.sun.jna.examples.unix.X11.Display;
|
||||
import com.sun.jna.examples.unix.X11.GC;
|
||||
import com.sun.jna.examples.unix.X11.Pixmap;
|
||||
import com.sun.jna.examples.unix.X11.XVisualInfo;
|
||||
import com.sun.jna.examples.unix.X11.Xext;
|
||||
import com.sun.jna.examples.unix.X11.Xrender.XRenderPictFormat;
|
||||
import com.sun.jna.examples.win32.GDI32;
|
||||
import com.sun.jna.examples.win32.User32;
|
||||
import com.sun.jna.examples.win32.GDI32.BITMAPINFO;
|
||||
import com.sun.jna.examples.win32.User32.BLENDFUNCTION;
|
||||
import com.sun.jna.examples.win32.User32.POINT;
|
||||
import com.sun.jna.examples.win32.User32.SIZE;
|
||||
import com.sun.jna.examples.win32.W32API.HANDLE;
|
||||
import com.sun.jna.examples.win32.W32API.HBITMAP;
|
||||
import com.sun.jna.examples.win32.W32API.HDC;
|
||||
import com.sun.jna.examples.win32.W32API.HRGN;
|
||||
import com.sun.jna.examples.win32.W32API.HWND;
|
||||
import com.sun.jna.platform.unix.X11;
|
||||
import com.sun.jna.platform.unix.X11.Display;
|
||||
import com.sun.jna.platform.unix.X11.GC;
|
||||
import com.sun.jna.platform.unix.X11.Pixmap;
|
||||
import com.sun.jna.platform.unix.X11.XVisualInfo;
|
||||
import com.sun.jna.platform.unix.X11.Xext;
|
||||
import com.sun.jna.platform.unix.X11.Xrender.XRenderPictFormat;
|
||||
import com.sun.jna.platform.win32.GDI32;
|
||||
import com.sun.jna.platform.win32.User32;
|
||||
import com.sun.jna.platform.win32.WinGDI;
|
||||
import com.sun.jna.platform.win32.WinUser;
|
||||
import com.sun.jna.platform.win32.WinDef.HBITMAP;
|
||||
import com.sun.jna.platform.win32.WinDef.HDC;
|
||||
import com.sun.jna.platform.win32.WinDef.HRGN;
|
||||
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||
import com.sun.jna.platform.win32.WinGDI.BITMAPINFO;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinUser.BLENDFUNCTION;
|
||||
import com.sun.jna.platform.win32.WinUser.POINT;
|
||||
import com.sun.jna.platform.win32.WinUser.SIZE;
|
||||
import com.sun.jna.ptr.ByteByReference;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
@@ -112,7 +114,15 @@ import com.sun.jna.ptr.PointerByReference;
|
||||
* Window#paint(Graphics)} on OS X, you'll need to explicitly set the clip
|
||||
* mask on the <code>Graphics</code> object with the window mask; only the
|
||||
* content pane of the window and below have the window mask automatically
|
||||
* applied.
|
||||
* applied.<p>
|
||||
* NOTE: On OSX, the property
|
||||
* <code>apple.awt.draggableWindowBackground</code> is set automatically when
|
||||
* a window's background color has an alpha component. That property must be
|
||||
* set to its final value <em>before</em> the heavyweight peer for the Window
|
||||
* is created. Once {@link Component#addNotify} has been called on the
|
||||
* component, causing creation of the heavyweight peer, changing this
|
||||
* property has no effect.
|
||||
* @see <a href="http://developer.apple.com/technotes/tn2007/tn2196.html#APPLE_AWT_DRAGGABLEWINDOWBACKGROUND">Apple Technote 2007</a>
|
||||
*/
|
||||
// TODO: setWindowMask() should accept a threshold; some cases want a
|
||||
// 50% threshold, some might want zero/non-zero
|
||||
@@ -141,6 +151,7 @@ public class WindowUtils {
|
||||
* </pre></code>
|
||||
*/
|
||||
private static class HeavyweightForcer extends Window {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final boolean packed;
|
||||
|
||||
public HeavyweightForcer(Window parent) {
|
||||
@@ -166,6 +177,7 @@ public class WindowUtils {
|
||||
* invoked whenever any part of the ancestor window is repainted.
|
||||
*/
|
||||
protected static class RepaintTrigger extends JComponent {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected class Listener
|
||||
extends WindowAdapter
|
||||
@@ -192,13 +204,18 @@ public class WindowUtils {
|
||||
}
|
||||
|
||||
public void eventDispatched(AWTEvent e) {
|
||||
Component src = (Component)e.getSource();
|
||||
MouseEvent me = SwingUtilities.convertMouseEvent(src, (MouseEvent)e, content);
|
||||
Component c = SwingUtilities.getDeepestComponentAt(content, me.getX(), me.getY());
|
||||
if (c != null) {
|
||||
setCursor(c.getCursor());
|
||||
if (e instanceof MouseEvent) {
|
||||
Component src = ((MouseEvent)e).getComponent();
|
||||
if (src != null
|
||||
&& SwingUtilities.isDescendingFrom(src, content)) {
|
||||
MouseEvent me = SwingUtilities.convertMouseEvent(src, (MouseEvent)e, content);
|
||||
Component c = SwingUtilities.getDeepestComponentAt(content, me.getX(), me.getY());
|
||||
if (c != null) {
|
||||
setCursor(c.getCursor());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private final Listener listener = createListener();
|
||||
@@ -249,9 +266,11 @@ public class WindowUtils {
|
||||
|
||||
/** Window utilities with differing native implementations. */
|
||||
public static abstract class NativeWindowUtils {
|
||||
protected abstract class TransparentContent extends JPanel {
|
||||
protected abstract class TransparentContentPane
|
||||
extends JPanel implements AWTEventListener {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private boolean transparent;
|
||||
public TransparentContent(Container oldContent) {
|
||||
public TransparentContentPane(Container oldContent) {
|
||||
super(new BorderLayout());
|
||||
add(oldContent, BorderLayout.CENTER);
|
||||
setTransparent(true);
|
||||
@@ -259,12 +278,27 @@ public class WindowUtils {
|
||||
((JComponent)oldContent).setOpaque(false);
|
||||
}
|
||||
}
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.CONTAINER_EVENT_MASK);
|
||||
}
|
||||
public void removeNotify() {
|
||||
Toolkit.getDefaultToolkit().removeAWTEventListener(this);
|
||||
super.removeNotify();
|
||||
}
|
||||
public void setTransparent(boolean transparent) {
|
||||
this.transparent = transparent;
|
||||
setOpaque(!transparent);
|
||||
setDoubleBuffered(!transparent);
|
||||
repaint();
|
||||
}
|
||||
public void eventDispatched(AWTEvent e) {
|
||||
if (e.getID() == ContainerEvent.COMPONENT_ADDED
|
||||
&& SwingUtilities.isDescendingFrom(((ContainerEvent)e).getChild(), this)) {
|
||||
Component child = ((ContainerEvent)e).getChild();
|
||||
NativeWindowUtils.this.setDoubleBuffered(child, false);
|
||||
}
|
||||
}
|
||||
public void paint(Graphics gr) {
|
||||
if (transparent) {
|
||||
Rectangle r = gr.getClipBounds();
|
||||
@@ -430,6 +464,7 @@ public class WindowUtils {
|
||||
}
|
||||
|
||||
protected void setLayersTransparent(Window w, boolean transparent) {
|
||||
|
||||
Color bg = transparent ? new Color(0, 0, 0, 0) : null;
|
||||
if (w instanceof RootPaneContainer) {
|
||||
RootPaneContainer rpc = (RootPaneContainer)w;
|
||||
@@ -455,11 +490,15 @@ public class WindowUtils {
|
||||
}
|
||||
else {
|
||||
lp.setOpaque(Boolean.TRUE.equals(lp.getClientProperty(TRANSPARENT_OLD_OPAQUE)));
|
||||
lp.putClientProperty(TRANSPARENT_OLD_OPAQUE, null);
|
||||
root.setOpaque(Boolean.TRUE.equals(root.getClientProperty(TRANSPARENT_OLD_OPAQUE)));
|
||||
root.putClientProperty(TRANSPARENT_OLD_OPAQUE, null);
|
||||
if (content != null) {
|
||||
content.setOpaque(Boolean.TRUE.equals(content.getClientProperty(TRANSPARENT_OLD_OPAQUE)));
|
||||
content.putClientProperty(TRANSPARENT_OLD_OPAQUE, null);
|
||||
}
|
||||
bg = (Color)root.getClientProperty(TRANSPARENT_OLD_BG);
|
||||
root.putClientProperty(TRANSPARENT_OLD_BG, null);
|
||||
}
|
||||
}
|
||||
w.setBackground(bg);
|
||||
@@ -605,27 +644,27 @@ public class WindowUtils {
|
||||
public void run() {
|
||||
HWND hWnd = getHWnd(w);
|
||||
User32 user = User32.INSTANCE;
|
||||
int flags = user.GetWindowLong(hWnd, User32.GWL_EXSTYLE);
|
||||
int flags = user.GetWindowLong(hWnd, WinUser.GWL_EXSTYLE);
|
||||
byte level = (byte)((int)(255 * alpha) & 0xFF);
|
||||
if (usingUpdateLayeredWindow(w)) {
|
||||
// If already using UpdateLayeredWindow, continue to
|
||||
// do so
|
||||
BLENDFUNCTION blend = new BLENDFUNCTION();
|
||||
blend.SourceConstantAlpha = level;
|
||||
blend.AlphaFormat = User32.AC_SRC_ALPHA;
|
||||
blend.AlphaFormat = WinUser.AC_SRC_ALPHA;
|
||||
user.UpdateLayeredWindow(hWnd, null, null, null, null,
|
||||
null, 0, blend,
|
||||
User32.ULW_ALPHA);
|
||||
WinUser.ULW_ALPHA);
|
||||
}
|
||||
else if (alpha == 1f) {
|
||||
flags &= ~User32.WS_EX_LAYERED;
|
||||
user.SetWindowLong(hWnd, User32.GWL_EXSTYLE, flags);
|
||||
flags &= ~WinUser.WS_EX_LAYERED;
|
||||
user.SetWindowLong(hWnd, WinUser.GWL_EXSTYLE, flags);
|
||||
}
|
||||
else {
|
||||
flags |= User32.WS_EX_LAYERED;
|
||||
user.SetWindowLong(hWnd, User32.GWL_EXSTYLE, flags);
|
||||
flags |= WinUser.WS_EX_LAYERED;
|
||||
user.SetWindowLong(hWnd, WinUser.GWL_EXSTYLE, flags);
|
||||
user.SetLayeredWindowAttributes(hWnd, 0, level,
|
||||
User32.LWA_ALPHA);
|
||||
WinUser.LWA_ALPHA);
|
||||
}
|
||||
setForceHeavyweightPopups(w, alpha != 1f);
|
||||
storeAlpha(w, level);
|
||||
@@ -637,12 +676,13 @@ public class WindowUtils {
|
||||
* window on any change. It also does not paint window decorations
|
||||
* when the window is transparent.
|
||||
*/
|
||||
private class W32TransparentContent extends TransparentContent {
|
||||
private class W32TransparentContentPane extends TransparentContentPane {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private HDC memDC;
|
||||
private HBITMAP hBitmap;
|
||||
private Pointer pbits;
|
||||
private Dimension bitmapSize;
|
||||
public W32TransparentContent(Container content) {
|
||||
public W32TransparentContentPane(Container content) {
|
||||
super(content);
|
||||
}
|
||||
private void disposeBackingStore() {
|
||||
@@ -694,12 +734,12 @@ public class WindowUtils {
|
||||
bmi.bmiHeader.biHeight = wh;
|
||||
bmi.bmiHeader.biPlanes = 1;
|
||||
bmi.bmiHeader.biBitCount = 32;
|
||||
bmi.bmiHeader.biCompression = GDI32.BI_RGB;
|
||||
bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
|
||||
bmi.bmiHeader.biSizeImage = ww * wh * 4;
|
||||
PointerByReference ppbits = new PointerByReference();
|
||||
hBitmap = gdi.CreateDIBSection(memDC, bmi,
|
||||
GDI32.DIB_RGB_COLORS,
|
||||
ppbits, null, 0);
|
||||
WinGDI.DIB_RGB_COLORS,
|
||||
ppbits, null, 0);
|
||||
pbits = ppbits.getValue();
|
||||
bitmapSize = new Dimension(ww, wh);
|
||||
}
|
||||
@@ -732,16 +772,20 @@ public class WindowUtils {
|
||||
ByteByReference bref = new ByteByReference();
|
||||
IntByReference iref = new IntByReference();
|
||||
byte level = getAlpha(win);
|
||||
if (user.GetLayeredWindowAttributes(hWnd, null, bref, iref)
|
||||
&& (iref.getValue() & User32.LWA_ALPHA) != 0) {
|
||||
level = bref.getValue();
|
||||
try {
|
||||
// GetLayeredwindowAttributes supported WinXP and later
|
||||
if (user.GetLayeredWindowAttributes(hWnd, null, bref, iref)
|
||||
&& (iref.getValue() & WinUser.LWA_ALPHA) != 0) {
|
||||
level = bref.getValue();
|
||||
}
|
||||
}
|
||||
catch(UnsatisfiedLinkError e) {
|
||||
}
|
||||
blend.SourceConstantAlpha = level;
|
||||
blend.AlphaFormat = User32.AC_SRC_ALPHA;
|
||||
blend.AlphaFormat = WinUser.AC_SRC_ALPHA;
|
||||
user.UpdateLayeredWindow(hWnd, screenDC, winLoc, winSize, memDC,
|
||||
srcLoc, 0, blend, User32.ULW_ALPHA);
|
||||
}
|
||||
finally {
|
||||
srcLoc, 0, blend, WinUser.ULW_ALPHA);
|
||||
} finally {
|
||||
user.ReleaseDC(null, screenDC);
|
||||
if (memDC != null && oldBitmap != null) {
|
||||
gdi.SelectObject(memDC, oldBitmap);
|
||||
@@ -769,27 +813,27 @@ public class WindowUtils {
|
||||
public void run() {
|
||||
User32 user = User32.INSTANCE;
|
||||
HWND hWnd = getHWnd(w);
|
||||
int flags = user.GetWindowLong(hWnd, User32.GWL_EXSTYLE);
|
||||
int flags = user.GetWindowLong(hWnd, WinUser.GWL_EXSTYLE);
|
||||
JRootPane root = ((RootPaneContainer)w).getRootPane();
|
||||
JLayeredPane lp = root.getLayeredPane();
|
||||
Container content = root.getContentPane();
|
||||
if (content instanceof W32TransparentContent) {
|
||||
((W32TransparentContent)content).setTransparent(transparent);
|
||||
if (content instanceof W32TransparentContentPane) {
|
||||
((W32TransparentContentPane)content).setTransparent(transparent);
|
||||
}
|
||||
else if (transparent) {
|
||||
W32TransparentContent w32content =
|
||||
new W32TransparentContent(content);
|
||||
W32TransparentContentPane w32content =
|
||||
new W32TransparentContentPane(content);
|
||||
root.setContentPane(w32content);
|
||||
lp.add(new RepaintTrigger(w32content),
|
||||
JLayeredPane.DRAG_LAYER);
|
||||
}
|
||||
if (transparent && !usingUpdateLayeredWindow(w)) {
|
||||
flags |= User32.WS_EX_LAYERED;
|
||||
user.SetWindowLong(hWnd, User32.GWL_EXSTYLE, flags);
|
||||
flags |= WinUser.WS_EX_LAYERED;
|
||||
user.SetWindowLong(hWnd, WinUser.GWL_EXSTYLE, flags);
|
||||
}
|
||||
else if (!transparent && usingUpdateLayeredWindow(w)) {
|
||||
flags &= ~User32.WS_EX_LAYERED;
|
||||
user.SetWindowLong(hWnd, User32.GWL_EXSTYLE, flags);
|
||||
flags &= ~WinUser.WS_EX_LAYERED;
|
||||
user.SetWindowLong(hWnd, WinUser.GWL_EXSTYLE, flags);
|
||||
}
|
||||
setLayersTransparent(w, transparent);
|
||||
setForceHeavyweightPopups(w, transparent);
|
||||
@@ -830,11 +874,11 @@ public class WindowUtils {
|
||||
GDI32 gdi = GDI32.INSTANCE;
|
||||
PathIterator pi = area.getPathIterator(null);
|
||||
int mode = pi.getWindingRule() == PathIterator.WIND_NON_ZERO
|
||||
? GDI32.WINDING: GDI32.ALTERNATE;
|
||||
? WinGDI.WINDING: WinGDI.ALTERNATE;
|
||||
float[] coords = new float[6];
|
||||
List points = new ArrayList();
|
||||
List<POINT> points = new ArrayList<POINT>();
|
||||
int size = 0;
|
||||
List sizes = new ArrayList();
|
||||
List<Integer> sizes = new ArrayList<Integer>();
|
||||
while (!pi.isDone()) {
|
||||
int type = pi.currentSegment(coords);
|
||||
if (type == PathIterator.SEG_MOVETO) {
|
||||
@@ -878,7 +922,7 @@ public class WindowUtils {
|
||||
public boolean outputRange(int x, int y, int w, int h) {
|
||||
GDI32 gdi = GDI32.INSTANCE;
|
||||
gdi.SetRectRgn(tempRgn, x, y, x + w, y + h);
|
||||
return gdi.CombineRgn(region, region, tempRgn, GDI32.RGN_OR) != GDI32.ERROR;
|
||||
return gdi.CombineRgn(region, region, tempRgn, WinGDI.RGN_OR) != WinGDI.ERROR;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -895,55 +939,81 @@ public class WindowUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
private OSXTransparentContent installTransparentContent(Window w) {
|
||||
OSXTransparentContent content;
|
||||
private OSXMaskingContentPane installMaskingPane(Window w) {
|
||||
OSXMaskingContentPane content;
|
||||
if (w instanceof RootPaneContainer) {
|
||||
// TODO: replace layered pane instead?
|
||||
final RootPaneContainer rpc = (RootPaneContainer)w;
|
||||
Container oldContent = rpc.getContentPane();
|
||||
if (oldContent instanceof OSXTransparentContent) {
|
||||
content = (OSXTransparentContent)oldContent;
|
||||
if (oldContent instanceof OSXMaskingContentPane) {
|
||||
content = (OSXMaskingContentPane)oldContent;
|
||||
}
|
||||
else {
|
||||
content = new OSXTransparentContent(oldContent);
|
||||
content = new OSXMaskingContentPane(oldContent);
|
||||
// TODO: listen for content pane changes
|
||||
rpc.setContentPane(content);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Component oldContent = w.getComponentCount() > 0 ? w.getComponent(0) : null;
|
||||
if (oldContent instanceof OSXTransparentContent) {
|
||||
content = (OSXTransparentContent)oldContent;
|
||||
if (oldContent instanceof OSXMaskingContentPane) {
|
||||
content = (OSXMaskingContentPane)oldContent;
|
||||
}
|
||||
else {
|
||||
content = new OSXTransparentContent(oldContent);
|
||||
content = new OSXMaskingContentPane(oldContent);
|
||||
w.add(content);
|
||||
}
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
/** Note that the property
|
||||
* <code>apple.awt.draggableWindowBackground</code> must be set to its
|
||||
* final value <em>before</em> the heavyweight peer for the Window is
|
||||
* created. Once {@link Component#addNotify} has been called on the
|
||||
* component, causing creation of the heavyweight peer, changing this
|
||||
* property has no effect.
|
||||
* @see <a href="http://developer.apple.com/technotes/tn2007/tn2196.html#APPLE_AWT_DRAGGABLEWINDOWBACKGROUND">Apple Technote 2007</a>
|
||||
*/
|
||||
public void setWindowTransparent(Window w, boolean transparent) {
|
||||
boolean isTransparent = w.getBackground() != null
|
||||
&& w.getBackground().getAlpha() == 0;
|
||||
if (transparent != isTransparent) {
|
||||
installTransparentContent(w);
|
||||
setBackgroundTransparent(w, transparent);
|
||||
setLayersTransparent(w, transparent);
|
||||
setBackgroundTransparent(w, transparent, "setWindowTransparent");
|
||||
}
|
||||
}
|
||||
|
||||
/** Setting this false restores the original setting. */
|
||||
private static final String WDRAG = "apple.awt.draggableWindowBackground";
|
||||
private void fixWindowDragging(Window w, String context) {
|
||||
if (w instanceof RootPaneContainer) {
|
||||
JRootPane p = ((RootPaneContainer)w).getRootPane();
|
||||
Boolean oldDraggable = (Boolean)p.getClientProperty(WDRAG);
|
||||
if (oldDraggable == null) {
|
||||
p.putClientProperty(WDRAG, Boolean.FALSE);
|
||||
if (w.isDisplayable()) {
|
||||
System.err.println(context + "(): To avoid content dragging, " + context + "() must be called before the window is realized, or " + WDRAG + " must be set to Boolean.FALSE before the window is realized. If you really want content dragging, set " + WDRAG + " on the window's root pane to Boolean.TRUE before calling " + context + "() to hide this message.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Note that the property
|
||||
* <code>apple.awt.draggableWindowBackground</code> must be set to its
|
||||
* final value <em>before</em> the heavyweight peer for the Window is
|
||||
* created. Once {@link Component#addNotify} has been called on the
|
||||
* component, causing creation of the heavyweight peer, changing this
|
||||
* property has no effect.
|
||||
* @see <a href="http://developer.apple.com/technotes/tn2007/tn2196.html#APPLE_AWT_DRAGGABLEWINDOWBACKGROUND">Apple Technote 2007</a>
|
||||
*/
|
||||
public void setWindowAlpha(final Window w, final float alpha) {
|
||||
if (w instanceof RootPaneContainer) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
JRootPane p = ((RootPaneContainer)w).getRootPane();
|
||||
p.putClientProperty("Window.alpha", new Float(alpha));
|
||||
}
|
||||
});
|
||||
JRootPane p = ((RootPaneContainer)w).getRootPane();
|
||||
p.putClientProperty("Window.alpha", new Float(alpha));
|
||||
fixWindowDragging(w, "setWindowAlpha");
|
||||
}
|
||||
whenDisplayable(w, new Runnable() {
|
||||
public void run() {
|
||||
public void run() {
|
||||
Object peer = w.getPeer();
|
||||
try {
|
||||
peer.getClass().getMethod("setAlpha", new Class[]{
|
||||
@@ -971,9 +1041,9 @@ public class WindowUtils {
|
||||
public void setWindowMask(Component c, final Shape shape) {
|
||||
if (c instanceof Window) {
|
||||
Window w = (Window)c;
|
||||
OSXTransparentContent content = installTransparentContent(w);
|
||||
OSXMaskingContentPane content = installMaskingPane(w);
|
||||
content.setMask(shape);
|
||||
setBackgroundTransparent(w, shape != MASK_NONE);
|
||||
setBackgroundTransparent(w, shape != MASK_NONE, "setWindowMask");
|
||||
}
|
||||
else {
|
||||
// not yet implemented
|
||||
@@ -983,10 +1053,11 @@ public class WindowUtils {
|
||||
/** Mask out unwanted pixels and ensure background gets cleared.
|
||||
* @author Olivier Chafik
|
||||
*/
|
||||
private static class OSXTransparentContent extends JPanel {
|
||||
private static class OSXMaskingContentPane extends JPanel {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Shape shape;
|
||||
|
||||
public OSXTransparentContent(Component oldContent) {
|
||||
public OSXMaskingContentPane(Component oldContent) {
|
||||
super(new BorderLayout());
|
||||
if (oldContent != null) {
|
||||
add(oldContent, BorderLayout.CENTER);
|
||||
@@ -1015,31 +1086,32 @@ public class WindowUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private void setBackgroundTransparent(Window w, boolean transparent) {
|
||||
private void setBackgroundTransparent(Window w, boolean transparent, String context) {
|
||||
JRootPane rp = w instanceof RootPaneContainer
|
||||
? ((RootPaneContainer)w).getRootPane() : null;
|
||||
if (transparent) {
|
||||
if (rp != null) {
|
||||
rp.putClientProperty("bg.old", w.getBackground());
|
||||
rp.putClientProperty("draggable.old",
|
||||
rp.getClientProperty("apple.awt.draggableWindowBackground"));
|
||||
rp.putClientProperty(TRANSPARENT_OLD_BG, w.getBackground());
|
||||
}
|
||||
w.setBackground(new Color(0,0,0,0));
|
||||
}
|
||||
else {
|
||||
if (rp != null) {
|
||||
w.setBackground((Color)rp.getClientProperty("bg.old"));
|
||||
Color bg = (Color)rp.getClientProperty(TRANSPARENT_OLD_BG);
|
||||
// If the old bg is a
|
||||
// apple.laf.CColorPaintUIResource, the window's
|
||||
// transparent state will not change
|
||||
if (bg != null) {
|
||||
bg = new Color(bg.getRed(), bg.getGreen(), bg.getBlue(), bg.getAlpha());
|
||||
}
|
||||
w.setBackground(bg);
|
||||
rp.putClientProperty(TRANSPARENT_OLD_BG, null);
|
||||
}
|
||||
else {
|
||||
w.setBackground(null);
|
||||
}
|
||||
}
|
||||
if (rp != null) {
|
||||
// disable dragging by content
|
||||
Boolean old = (Boolean)rp.getClientProperty("apple.awt.draggableWindowBackground");
|
||||
rp.putClientProperty("apple.awt.draggableWindowBackground",
|
||||
transparent ? Boolean.FALSE : old);
|
||||
}
|
||||
fixWindowDragging(w, context);
|
||||
}
|
||||
}
|
||||
private static class X11WindowUtils extends NativeWindowUtils {
|
||||
@@ -1057,7 +1129,7 @@ public class WindowUtils {
|
||||
}
|
||||
x11.XSetForeground(dpy, gc, new NativeLong(0));
|
||||
x11.XFillRectangle(dpy, pm, gc, 0, 0, width, height);
|
||||
final List rlist = new ArrayList();
|
||||
final List<Rectangle> rlist = new ArrayList<Rectangle>();
|
||||
try {
|
||||
RasterRangesUtils.outputOccupiedRanges(raster, new RasterRangesUtils.RangesOutput() {
|
||||
public boolean outputRange(int x, int y, int w, int h) {
|
||||
@@ -1073,6 +1145,14 @@ public class WindowUtils {
|
||||
rects[i].y = (short)r.y;
|
||||
rects[i].width = (short)r.width;
|
||||
rects[i].height = (short)r.height;
|
||||
// Optimization: write directly to native memory
|
||||
Pointer p = rects[i].getPointer();
|
||||
p.setShort(0, (short)r.x);
|
||||
p.setShort(2, (short)r.y);
|
||||
p.setShort(4, (short)r.width);
|
||||
p.setShort(6, (short)r.height);
|
||||
rects[i].setAutoSynch(false);
|
||||
// End optimization
|
||||
}
|
||||
final int UNMASKED = 1;
|
||||
x11.XSetForeground(dpy, gc, new NativeLong(UNMASKED));
|
||||
@@ -1155,7 +1235,7 @@ public class WindowUtils {
|
||||
IntByReference pcount = new IntByReference();
|
||||
info = x11.XGetVisualInfo(dpy, mask, template, pcount);
|
||||
if (info != null) {
|
||||
List list = new ArrayList();
|
||||
List<X11.VisualID> list = new ArrayList<X11.VisualID>();
|
||||
XVisualInfo[] infos =
|
||||
(XVisualInfo[])info.toArray(pcount.getValue());
|
||||
for (int i = 0; i < infos.length; i++) {
|
||||
@@ -1195,9 +1275,9 @@ public class WindowUtils {
|
||||
x11.XQueryTree(dpy, win, rootp, parentp, childrenp, countp);
|
||||
Pointer p = childrenp.getValue();
|
||||
int[] ids = p.getIntArray(0, countp.getValue());
|
||||
for (int i=0;i < ids.length;i++) {
|
||||
for (int id : ids) {
|
||||
// TODO: more verification of correct window?
|
||||
X11.Window child = new X11.Window(ids[i]);
|
||||
X11.Window child = new X11.Window(id);
|
||||
X11.XWindowAttributes xwa = new X11.XWindowAttributes();
|
||||
x11.XGetWindowAttributes(dpy, child, xwa);
|
||||
offset.x = -xwa.x;
|
||||
@@ -1258,9 +1338,10 @@ public class WindowUtils {
|
||||
whenDisplayable(w, action);
|
||||
}
|
||||
|
||||
private class X11TransparentContent extends TransparentContent {
|
||||
private class X11TransparentContentPane extends TransparentContentPane {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public X11TransparentContent(Container oldContent) {
|
||||
public X11TransparentContentPane(Container oldContent) {
|
||||
super(oldContent);
|
||||
}
|
||||
|
||||
@@ -1270,7 +1351,7 @@ public class WindowUtils {
|
||||
// Painting directly to the original Graphics
|
||||
// fails to properly composite unless the destination
|
||||
// is pure black. Too bad.
|
||||
protected void paintDirect(BufferedImage buf, Rectangle bounds) {
|
||||
protected void paintDirect(BufferedImage buf, Rectangle bounds) {
|
||||
Window window = SwingUtilities.getWindowAncestor(this);
|
||||
X11 x11 = X11.INSTANCE;
|
||||
X11.Display dpy = x11.XOpenDisplay(null);
|
||||
@@ -1335,12 +1416,12 @@ public class WindowUtils {
|
||||
JRootPane root = ((RootPaneContainer)w).getRootPane();
|
||||
JLayeredPane lp = root.getLayeredPane();
|
||||
Container content = root.getContentPane();
|
||||
if (content instanceof X11TransparentContent) {
|
||||
((X11TransparentContent)content).setTransparent(transparent);
|
||||
if (content instanceof X11TransparentContentPane) {
|
||||
((X11TransparentContentPane)content).setTransparent(transparent);
|
||||
}
|
||||
else if (transparent) {
|
||||
X11TransparentContent x11content =
|
||||
new X11TransparentContent(content);
|
||||
X11TransparentContentPane x11content =
|
||||
new X11TransparentContentPane(content);
|
||||
root.setContentPane(x11content);
|
||||
lp.add(new RepaintTrigger(x11content),
|
||||
JLayeredPane.DRAG_LAYER);
|
||||
@@ -1439,7 +1520,14 @@ public class WindowUtils {
|
||||
* opaque, 0.0 fully transparent. The alpha level is applied equally
|
||||
* to all window pixels.<p>
|
||||
* NOTE: Windows requires that <code>sun.java2d.noddraw=true</code>
|
||||
* in order for alpha to work.
|
||||
* in order for alpha to work.<p>
|
||||
* NOTE: On OSX, the property
|
||||
* <code>apple.awt.draggableWindowBackground</code> must be set to its
|
||||
* final value <em>before</em> the heavyweight peer for the Window is
|
||||
* created. Once {@link Component#addNotify} has been called on the
|
||||
* component, causing creation of the heavyweight peer, changing this
|
||||
* property has no effect.
|
||||
* @see <a href="http://developer.apple.com/technotes/tn2007/tn2196.html#APPLE_AWT_DRAGGABLEWINDOWBACKGROUND">Apple Technote 2007</a>
|
||||
*/
|
||||
public static void setWindowAlpha(Window w, float alpha) {
|
||||
getInstance().setWindowAlpha(w, Math.max(0f, Math.min(alpha, 1f)));
|
||||
@@ -1449,6 +1537,13 @@ public class WindowUtils {
|
||||
* Set the window to be transparent. Only explicitly painted pixels
|
||||
* will be non-transparent. All pixels will be composited with
|
||||
* whatever is under the window using their alpha values.
|
||||
*
|
||||
* On OSX, the property <code>apple.awt.draggableWindowBackground</code>
|
||||
* must be set to its final value <em>before</em> the heavyweight peer for
|
||||
* the Window is created. Once {@link Component#addNotify} has been
|
||||
* called on the component, causing creation of the heavyweight peer,
|
||||
* changing this property has no effect.
|
||||
* @see <a href="http://developer.apple.com/technotes/tn2007/tn2196.html#APPLE_AWT_DRAGGABLEWINDOWBACKGROUND">Apple Technote 2007</a>
|
||||
*/
|
||||
public static void setWindowTransparent(Window w, boolean transparent) {
|
||||
getInstance().setWindowTransparent(w, transparent);
|
||||
+5
-4
@@ -10,7 +10,7 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.examples.dnd;
|
||||
package com.sun.jna.platform.dnd;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Component;
|
||||
@@ -38,6 +38,7 @@ import java.awt.dnd.DropTargetEvent;
|
||||
import java.awt.dnd.InvalidDnDOperationException;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JColorChooser;
|
||||
import javax.swing.JFileChooser;
|
||||
@@ -162,7 +163,7 @@ public abstract class DragHandler
|
||||
try {
|
||||
// getTransferable is available during drag only on 1.5+
|
||||
return (Transferable)
|
||||
e.getClass().getMethod("getTransferable", null).invoke(e, null);
|
||||
e.getClass().getMethod("getTransferable", (Class[])null).invoke(e, (Object[])null);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
// Method not available
|
||||
@@ -179,7 +180,7 @@ public abstract class DragHandler
|
||||
private Component dragSource;
|
||||
private GhostedDragImage ghost;
|
||||
private Point imageOffset;
|
||||
private Dimension maxGhostSize = MAX_GHOST_SIZE;
|
||||
private Dimension maxGhostSize = MAX_GHOST_SIZE;
|
||||
private float ghostAlpha = DEFAULT_GHOST_ALPHA;
|
||||
|
||||
/** Enable drags from the given component, supporting the actions in
|
||||
@@ -529,4 +530,4 @@ public abstract class DragHandler
|
||||
}
|
||||
updateCursor(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -10,7 +10,7 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.examples.dnd;
|
||||
package com.sun.jna.platform.dnd;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Point;
|
||||
@@ -88,7 +88,7 @@ import java.util.Set;
|
||||
public abstract class DropHandler implements DropTargetListener {
|
||||
|
||||
private int acceptedActions;
|
||||
private List acceptedFlavors;
|
||||
private List<DataFlavor> acceptedFlavors;
|
||||
private DropTarget dropTarget;
|
||||
private boolean active = true;
|
||||
private DropTargetPainter painter;
|
||||
@@ -347,7 +347,7 @@ public abstract class DropHandler implements DropTargetListener {
|
||||
* constructor.
|
||||
*/
|
||||
protected boolean isSupported(DataFlavor[] flavors) {
|
||||
Set set = new HashSet(Arrays.asList(flavors));
|
||||
Set<DataFlavor> set = new HashSet<DataFlavor>(Arrays.asList(flavors));
|
||||
set.retainAll(acceptedFlavors);
|
||||
return !set.isEmpty();
|
||||
}
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.examples.dnd;
|
||||
package com.sun.jna.platform.dnd;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.dnd.DropTargetEvent;
|
||||
+3
-2
@@ -10,7 +10,7 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.examples.dnd;
|
||||
package com.sun.jna.platform.dnd;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
@@ -29,7 +29,7 @@ import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import com.sun.jna.examples.WindowUtils;
|
||||
import com.sun.jna.platform.WindowUtils;
|
||||
|
||||
/** Provide a ghosted drag image for use during drags where
|
||||
* {@link DragSource#isDragImageSupported} returns false.<p>
|
||||
@@ -56,6 +56,7 @@ public class GhostedDragImage {
|
||||
// FIXME ensure gc is compatible (X11)
|
||||
GraphicsConfiguration gc = parent.getGraphicsConfiguration();
|
||||
dragImage = new Window(JOptionPane.getRootFrame(), gc) {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public void paint(Graphics g) {
|
||||
icon.paintIcon(this, g, 0, 0);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/* 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.mac;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.platform.FileUtils;
|
||||
|
||||
public class MacFileUtils extends FileUtils {
|
||||
|
||||
public boolean hasTrash() { return true; }
|
||||
|
||||
public void moveToTrash(File[] files) throws IOException {
|
||||
// TODO: use native API for moving to trash (if any)
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
File trash = new File(home, ".Trash");
|
||||
if (!trash.exists()) {
|
||||
throw new IOException("The Trash was not found in its expected location (" + trash + ")");
|
||||
}
|
||||
List<File> failed = new ArrayList<File>();
|
||||
for (int i=0;i < files.length;i++) {
|
||||
File src = files[i];
|
||||
File target = new File(trash, src.getName());
|
||||
if (!src.renameTo(target)) {
|
||||
failed.add(src);
|
||||
}
|
||||
}
|
||||
if (failed.size() > 0) {
|
||||
throw new IOException("The following files could not be trashed: " + failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -0,0 +1,659 @@
|
||||
/* 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 com.sun.jna.Native;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.platform.win32.WinNT.PSIDByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.SECURITY_ATTRIBUTES;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEY;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEYByReference;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Advapi32.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Advapi32 extends StdCallLibrary {
|
||||
Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32",
|
||||
Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* Retrieves the name of the user associated with the current thread.
|
||||
* http://msdn.microsoft.com/en-us/library/ms724432(VS.85).aspx
|
||||
*
|
||||
* @param buffer
|
||||
* Buffer to receive the user's logon name.
|
||||
* @param len
|
||||
* On input, the size of the buffer, on output the number of
|
||||
* characters copied into the buffer, including the terminating
|
||||
* null character.
|
||||
* @return
|
||||
* True if succeeded.
|
||||
*/
|
||||
public boolean GetUserNameW(char[] buffer, IntByReference len);
|
||||
|
||||
/**
|
||||
* Accepts the name of a system and anaccount as input and retrieves a security
|
||||
* identifier (SID) for the account and the name of the domain on which the
|
||||
* account was found.
|
||||
* http://msdn.microsoft.com/en-us/library/aa379159(VS.85).aspx
|
||||
*
|
||||
* @param lpSystemName
|
||||
* Specifies the name of the system.
|
||||
* @param lpAccountName
|
||||
* Specifies the account name.
|
||||
* @param Sid
|
||||
* Receives the SID structure that corresponds to the account
|
||||
* name pointed to by the lpAccountName parameter.
|
||||
* @param cbSid
|
||||
* On input, this value specifies the size, in bytes, of the Sid
|
||||
* buffer. If the function fails because the buffer is too small
|
||||
* or if cbSid is zero, this variable receives the required
|
||||
* buffer size.
|
||||
* @param ReferencedDomainName
|
||||
* Receives the name of the domain where the account name is found.
|
||||
* @param cchReferencedDomainName
|
||||
* On input, this value specifies the size, in TCHARs, of the
|
||||
* ReferencedDomainName buffer. If the function fails because the
|
||||
* buffer is too small, this variable receives the required
|
||||
* buffer size, including the terminating null character.
|
||||
* @param peUse
|
||||
* SID_NAME_USE enumerated type that indicates the type of the
|
||||
* account when the function returns.
|
||||
* @return
|
||||
* True if the function was successful, False otherwise.
|
||||
*/
|
||||
public boolean LookupAccountName(String lpSystemName,
|
||||
String lpAccountName, PSID Sid, IntByReference cbSid,
|
||||
char[] ReferencedDomainName,
|
||||
IntByReference cchReferencedDomainName, PointerByReference peUse);
|
||||
|
||||
/**
|
||||
* Retrieves the name of the account for this SID and the name of the first domain
|
||||
* on which this SID is found.
|
||||
*
|
||||
* @param lpSystemName Specifies the target computer.
|
||||
* @param Sid The SID to look up.
|
||||
* @param lpName
|
||||
* Buffer that receives a null-terminated string that contains the
|
||||
* account name that corresponds to the lpSid parameter.
|
||||
* @param cchName
|
||||
* On input, specifies the size, in TCHARs, of the lpName buffer. If the function fails
|
||||
* because the buffer is too small or if cchName is zero, cchName receives the required
|
||||
* buffer size, including the terminating null character.
|
||||
* @param ReferencedDomainName
|
||||
* Pointer to a buffer that receives a null-terminated string that contains the name of
|
||||
* the domain where the account name was found.
|
||||
* @param cchReferencedDomainName
|
||||
* On input, specifies the size, in TCHARs, of the lpReferencedDomainName buffer. If the
|
||||
* function fails because the buffer is too small or if cchReferencedDomainName is zero,
|
||||
* cchReferencedDomainName receives the required buffer size, including the terminating
|
||||
* null character.
|
||||
* @param peUse
|
||||
* Pointer to a variable that receives a SID_NAME_USE value that indicates the type of
|
||||
* the account.
|
||||
* @return
|
||||
* If the function succeeds, the function returns nonzero.
|
||||
* If the function fails, it returns zero. To get extended error information, call
|
||||
* GetLastError.
|
||||
*/
|
||||
public boolean LookupAccountSid(String lpSystemName, PSID Sid,
|
||||
char[] lpName, IntByReference cchName, char[] ReferencedDomainName,
|
||||
IntByReference cchReferencedDomainName, PointerByReference peUse);
|
||||
|
||||
/**
|
||||
* Convert a security identifier (SID) to a string format suitable for display,
|
||||
* storage, or transmission.
|
||||
* http://msdn.microsoft.com/en-us/library/aa376399(VS.85).aspx
|
||||
*
|
||||
* @param Sid
|
||||
* The SID structure to be converted.
|
||||
* @param StringSid
|
||||
* Pointer to a variable that receives a pointer to a
|
||||
* null-terminated SID string. To free the returned buffer, call
|
||||
* the LocalFree function.
|
||||
* @return True if the function was successful, False otherwise.
|
||||
*/
|
||||
public boolean ConvertSidToStringSid(PSID Sid,
|
||||
PointerByReference StringSid);
|
||||
|
||||
/**
|
||||
* Convert a string-format security identifier (SID) into a valid, functional SID.
|
||||
* http://msdn.microsoft.com/en-us/library/aa376402(VS.85).aspx
|
||||
*
|
||||
* @param StringSid The string-format SID to convert.
|
||||
* @param Sid Receives a pointer to the converted SID.
|
||||
* @return True if the function was successful, False otherwise.
|
||||
*/
|
||||
public boolean ConvertStringSidToSid(String StringSid,
|
||||
PSIDByReference Sid);
|
||||
|
||||
/**
|
||||
* Returns the length, in bytes, of a valid security identifier (SID).
|
||||
* http://msdn.microsoft.com/en-us/library/aa446642(VS.85).aspx
|
||||
*
|
||||
* @param pSid A pointer to the SID structure whose length is returned.
|
||||
* @return Length of the SID.
|
||||
*/
|
||||
public int GetLengthSid(PSID pSid);
|
||||
|
||||
/**
|
||||
* The IsValidSid function validates a security identifier (SID) by verifying that
|
||||
* the revision number is within a known range, and that the number of subauthorities
|
||||
* is less than the maximum.
|
||||
* @param pSid
|
||||
* Pointer to the SID structure to validate. This parameter cannot be NULL.
|
||||
* @return
|
||||
* If the SID structure is valid, the return value is nonzero.
|
||||
* If the SID structure is not valid, the return value is zero. There is no extended
|
||||
* error information for this function; do not call GetLastError.
|
||||
*/
|
||||
public boolean IsValidSid(PSID pSid);
|
||||
|
||||
/**
|
||||
* Compares a SID to a well known SID and returns TRUE if they match.
|
||||
* @param pSid
|
||||
* SID to test.
|
||||
* @param wellKnownSidType
|
||||
* Member of the WELL_KNOWN_SID_TYPE enumeration to compare with the SID at pSid.
|
||||
* @return
|
||||
* True if the SID is of a given well known type, false otherwise.
|
||||
*/
|
||||
public boolean IsWellKnownSid(PSID pSid, int wellKnownSidType);
|
||||
|
||||
|
||||
/**
|
||||
* The CreateWellKnownSid function creates a SID for predefined aliases.
|
||||
* @param wellKnownSidType
|
||||
* Member of the WELL_KNOWN_SID_TYPE enumeration that specifies what the SID will identify.
|
||||
* @param domainSid
|
||||
* Pointer to a SID that identifies the domain control to use when creating the SID.
|
||||
* Pass NULL to use the local computer.
|
||||
* @param pSid
|
||||
* Pointer to memory where CreateWellKnownSid will store the new SID.
|
||||
* @param cbSid
|
||||
* Pointer to a DWORD that contains the number of bytes available at pSid.
|
||||
* The CreateWellKnownSid function stores the number of bytes actually used
|
||||
* at this location.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
* If the function fails, the return value is zero. For extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
public boolean CreateWellKnownSid(int wellKnownSidType,
|
||||
PSID domainSid, PSID pSid, IntByReference cbSid);
|
||||
|
||||
/**
|
||||
* The LogonUser function attempts to log a user on to the local computer. The local computer is
|
||||
* the computer from which LogonUser was called. You cannot use LogonUser to log on to a remote
|
||||
* computer. You specify the user with a user name and domain, and authenticate the user with a
|
||||
* plaintext password. If the function succeeds, you receive a handle to a token that represents
|
||||
* the logged-on user. You can then use this token handle to impersonate the specified user or,
|
||||
* in most cases, to create a process that runs in the context of the specified user.
|
||||
* @param lpszUsername
|
||||
* A pointer to a null-terminated string that specifies the name of the user. This is the name of
|
||||
* the user account to log on to. If you use the user principal name (UPN) format,
|
||||
* user@DNS_domain_name, the lpszDomain parameter must be NULL.
|
||||
* @param lpszDomain
|
||||
* A pointer to a null-terminated string that specifies the name of the domain or server whose
|
||||
* account database contains the lpszUsername account. If this parameter is NULL, the user name
|
||||
* must be specified in UPN format. If this parameter is ".", the function validates the account
|
||||
* using only the local account database.
|
||||
* @param lpszPassword
|
||||
* A pointer to a null-terminated string that specifies the plaintext password for the user
|
||||
* account specified by lpszUsername.
|
||||
* @param logonType
|
||||
* The type of logon operation to perform.
|
||||
* @param logonProvider
|
||||
* Specifies the logon provider.
|
||||
* @param phToken
|
||||
* A pointer to a handle variable that receives a handle to a token that represents the specified user.
|
||||
* @return
|
||||
* If the function succeeds, the function returns nonzero.
|
||||
* If the function fails, it returns zero. To get extended error information, call GetLastError.
|
||||
*/
|
||||
public boolean LogonUser(
|
||||
String lpszUsername,
|
||||
String lpszDomain,
|
||||
String lpszPassword,
|
||||
int logonType,
|
||||
int logonProvider,
|
||||
HANDLEByReference phToken);
|
||||
|
||||
/**
|
||||
* The OpenThreadToken function opens the access token associated with a thread.
|
||||
* @param ThreadHandle
|
||||
* Handle to the thread whose access token is opened.
|
||||
* @param DesiredAccess
|
||||
* Specifies an access mask that specifies the requested types of access to the access token.
|
||||
* These requested access types are reconciled against the token's discretionary access
|
||||
* control list (DACL) to determine which accesses are granted or denied.
|
||||
* @param OpenAsSelf
|
||||
* Indicates whether the access check is to be made against the security context of the
|
||||
* thread calling the OpenThreadToken function or against the security context of the
|
||||
* process for the calling thread.
|
||||
* @param TokenHandle
|
||||
* Pointer to a variable that receives the handle to the newly opened access token.
|
||||
* @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.
|
||||
*/
|
||||
public boolean OpenThreadToken(
|
||||
HANDLE ThreadHandle,
|
||||
int DesiredAccess,
|
||||
boolean OpenAsSelf,
|
||||
HANDLEByReference TokenHandle);
|
||||
|
||||
/**
|
||||
* The OpenProcessToken function opens the access token associated with a process.
|
||||
* @param ProcessHandle
|
||||
* Handle to the process whose access token is opened. The process must have the
|
||||
* PROCESS_QUERY_INFORMATION access permission.
|
||||
* @param DesiredAccess
|
||||
* Specifies an access mask that specifies the requested types of access to the access
|
||||
* token. These requested access types are compared with the discretionary access
|
||||
* control list (DACL) of the token to determine which accesses are granted or denied.
|
||||
* @param TokenHandle
|
||||
* Pointer to a handle that identifies the newly opened access token when the function returns.
|
||||
* @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.
|
||||
*/
|
||||
public boolean OpenProcessToken(
|
||||
HANDLE ProcessHandle,
|
||||
int DesiredAccess,
|
||||
HANDLEByReference TokenHandle);
|
||||
|
||||
/**
|
||||
* The DuplicateToken function creates a new access token that duplicates
|
||||
* one already in existence.
|
||||
*
|
||||
* @param ExistingTokenHandle
|
||||
* Handle to an access token opened with TOKEN_DUPLICATE access.
|
||||
* @param ImpersonationLevel
|
||||
* Specifies a SECURITY_IMPERSONATION_LEVEL enumerated type that supplies
|
||||
* the impersonation level of the new token.
|
||||
* @param DuplicateTokenHandle
|
||||
* Pointer to a variable that receives a handle to the duplicate token.
|
||||
* This handle has TOKEN_IMPERSONATE and TOKEN_QUERY access to the new token.
|
||||
* @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.
|
||||
*/
|
||||
public boolean DuplicateToken(
|
||||
HANDLE ExistingTokenHandle,
|
||||
int ImpersonationLevel,
|
||||
HANDLEByReference DuplicateTokenHandle);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a specified type of information about an access token.
|
||||
* The calling process must have appropriate access rights to obtain the information.
|
||||
|
||||
* @param tokenHandle
|
||||
* Handle to an access token from which information is retrieved. If TokenInformationClass
|
||||
* specifies TokenSource, the handle must have TOKEN_QUERY_SOURCE access. For all other
|
||||
* TokenInformationClass values, the handle must have TOKEN_QUERY access.
|
||||
* @param tokenInformationClass
|
||||
* Specifies a value from the TOKEN_INFORMATION_CLASS enumerated type to identify the type of
|
||||
* information the function retrieves.
|
||||
* @param tokenInformation
|
||||
* Pointer to a buffer the function fills with the requested information. The structure put
|
||||
* into this buffer depends upon the type of information specified by the TokenInformationClass
|
||||
* parameter.
|
||||
* @param tokenInformationLength
|
||||
* Specifies the size, in bytes, of the buffer pointed to by the TokenInformation parameter.
|
||||
* If TokenInformation is NULL, this parameter must be zero.
|
||||
* @param returnLength
|
||||
* Pointer to a variable that receives the number of bytes needed for the buffer pointed to by
|
||||
* the TokenInformation parameter. If this value is larger than the value specified in the
|
||||
* TokenInformationLength parameter, the function fails and stores no data in the buffer.
|
||||
* @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.
|
||||
*/
|
||||
public boolean GetTokenInformation(
|
||||
HANDLE tokenHandle,
|
||||
int tokenInformationClass,
|
||||
Structure tokenInformation,
|
||||
int tokenInformationLength,
|
||||
IntByReference returnLength);
|
||||
|
||||
/**
|
||||
* The ImpersonateLoggedOnUser function lets the calling thread impersonate the
|
||||
* security context of a logged-on user. The user is represented by a token
|
||||
* handle.
|
||||
* @param hToken
|
||||
* Handle to a primary or impersonation access token that represents a logged-on
|
||||
* user. This can be a token handle returned by a call to LogonUser,
|
||||
* CreateRestrictedToken, DuplicateToken, DuplicateTokenEx, OpenProcessToken,
|
||||
* or OpenThreadToken functions. If hToken is a primary token, it must have
|
||||
* TOKEN_QUERY and TOKEN_DUPLICATE access. If hToken is an impersonation token,
|
||||
* it must have TOKEN_QUERY and TOKEN_IMPERSONATE access.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
*/
|
||||
public boolean ImpersonateLoggedOnUser(
|
||||
HANDLE hToken);
|
||||
|
||||
/**
|
||||
* The RevertToSelf function terminates the impersonation of a client application.
|
||||
* @return If the function succeeds, the return value is nonzero.
|
||||
*/
|
||||
public boolean RevertToSelf();
|
||||
|
||||
|
||||
/**
|
||||
* The RegOpenKeyEx function opens the specified registry key.
|
||||
* Note that key names are not case sensitive.
|
||||
* @param hKey
|
||||
* Handle to an open key.
|
||||
* @param lpSubKey
|
||||
* Pointer to a null-terminated string containing the name of the subkey to open.
|
||||
* @param ulOptions
|
||||
* Reserved; must be zero.
|
||||
* @param samDesired
|
||||
* Access mask that specifies the desired access rights to the key. The function
|
||||
* fails if the security descriptor of the key does not permit the requested access
|
||||
* for the calling process.
|
||||
* @param phkResult
|
||||
* Pointer to a variable that receives a handle to the opened key. If the key is
|
||||
* not one of the predefined registry keys, call the RegCloseKey function after
|
||||
* you have finished using the handle.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS.
|
||||
* If the function fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegOpenKeyEx(HKEY hKey, String lpSubKey, int ulOptions, int samDesired,
|
||||
HKEYByReference phkResult);
|
||||
|
||||
/**
|
||||
* The RegQueryValueEx function retrieves the type and data for a specified value name
|
||||
* associated with an open registry key.
|
||||
* @param hKey
|
||||
* Handle to an open key. The key must have been opened with the
|
||||
* KEY_QUERY_VALUE access right.
|
||||
* @param lpValueName
|
||||
* Pointer to a null-terminated string containing the name of the value to query.
|
||||
* If lpValueName is NULL or an empty string, "", the function retrieves the type
|
||||
* and data for the key's unnamed or default value, if any.
|
||||
* @param lpReserved
|
||||
* Reserved; must be NULL.
|
||||
* @param lpType
|
||||
* Pointer to a variable that receives a code indicating the type of data stored
|
||||
* in the specified value.
|
||||
* @param lpData
|
||||
* Pointer to a buffer that receives the value's data. This parameter can be NULL
|
||||
* if the data is not required. If the data is a string, the function checks for
|
||||
* a terminating null character. If one is not found, the string is stored with a
|
||||
* null terminator if the buffer is large enough to accommodate the extra
|
||||
* character. Otherwise, the string is stored as is.
|
||||
* @param lpcbData
|
||||
* Pointer to a variable that specifies the size of the buffer pointed to by the
|
||||
* lpData parameter, in bytes. When the function returns, this variable contains
|
||||
* the size of the data copied to lpData. The lpcbData parameter can be NULL only
|
||||
* if lpData is NULL. If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ
|
||||
* type, this size includes any terminating null character or characters.
|
||||
* If the buffer specified by lpData parameter is not large enough to hold the
|
||||
* data, the function returns ERROR_MORE_DATA and stores the required buffer size
|
||||
* in the variable pointed to by lpcbData. In this case, the contents of the lpData
|
||||
* buffer are undefined. If lpData is NULL, and lpcbData is non-NULL, the function
|
||||
* returns ERROR_SUCCESS and stores the size of the data, in bytes, in the variable
|
||||
* pointed to by lpcbData. This enables an application to determine the best way
|
||||
* to allocate a buffer for the value's data.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS.
|
||||
* If the function fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegQueryValueEx(HKEY hKey, String lpValueName, int lpReserved,
|
||||
IntByReference lpType, char[] lpData, IntByReference lpcbData);
|
||||
|
||||
public int RegQueryValueEx(HKEY hKey, String lpValueName, int lpReserved,
|
||||
IntByReference lpType, byte[] lpData, IntByReference lpcbData);
|
||||
|
||||
public int RegQueryValueEx(HKEY hKey, String lpValueName, int lpReserved,
|
||||
IntByReference lpType, IntByReference lpData, IntByReference lpcbData);
|
||||
|
||||
/**
|
||||
* The RegCloseKey function releases a handle to the specified registry key.
|
||||
* @param hKey
|
||||
* Handle to the open key to be closed. The handle must have been opened by the
|
||||
* RegCreateKeyEx, RegOpenKeyEx, or RegConnectRegistry function.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegCloseKey(HKEY hKey);
|
||||
|
||||
/**
|
||||
* The RegDeleteValue function removes a named value from the specified registry
|
||||
* key. Note that value names are not case sensitive.
|
||||
* @param hKey
|
||||
* Handle to an open key. The key must have been opened with the KEY_SET_VALUE
|
||||
* access right.
|
||||
* @param lpValueName
|
||||
* Pointer to a null-terminated string that names the value to remove. If this
|
||||
* parameter is NULL or an empty string, the value set by the RegSetValue function
|
||||
* is removed.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegDeleteValue(HKEY hKey, String lpValueName);
|
||||
|
||||
/**
|
||||
* The RegSetValueEx function sets the data and type of a specified value under a
|
||||
* registry key.
|
||||
* @param hKey
|
||||
* Handle to an open key. The key must have been opened with the KEY_SET_VALUE
|
||||
* access right.
|
||||
* @param lpValueName
|
||||
* Pointer to a string containing the name of the value to set. If a value with
|
||||
* this name is not already present in the key, the function adds it to the key.
|
||||
* If lpValueName is NULL or an empty string, "", the function sets the type and
|
||||
* data for the key's unnamed or default value.
|
||||
* @param Reserved
|
||||
* Reserved; must be zero.
|
||||
* @param dwType
|
||||
* Type of data pointed to by the lpData parameter.
|
||||
* @param lpData
|
||||
* Pointer to a buffer containing the data to be stored with the specified value name.
|
||||
* @param cbData
|
||||
* Size of the information pointed to by the lpData parameter, in bytes. If the data
|
||||
* is of type REG_SZ, REG_EXPAND_SZ, or REG_MULTI_SZ, cbData must include the size of
|
||||
* the terminating null character or characters.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegSetValueEx(HKEY hKey, String lpValueName, int Reserved, int dwType,
|
||||
char[] lpData, int cbData);
|
||||
|
||||
public int RegSetValueEx(HKEY hKey, String lpValueName, int Reserved, int dwType,
|
||||
byte[] lpData, int cbData);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param hKey
|
||||
* @param lpSubKey
|
||||
* @param Reserved
|
||||
* @param lpClass
|
||||
* @param dwOptions
|
||||
* @param samDesired
|
||||
* @param lpSecurityAttributes
|
||||
* @param phkResult
|
||||
* @param lpdwDisposition
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegCreateKeyEx(HKEY hKey, String lpSubKey, int Reserved, String lpClass,
|
||||
int dwOptions, int samDesired, SECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
HKEYByReference phkResult, IntByReference lpdwDisposition);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param hKey
|
||||
* @param name
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegDeleteKey(HKEY hKey, String name);
|
||||
|
||||
/**
|
||||
* The RegEnumKeyEx function enumerates subkeys of the specified open registry key.
|
||||
* The function retrieves information about one subkey each time it is called.
|
||||
* @param hKey
|
||||
* Handle to an open key. The key must have been opened with the
|
||||
* KEY_ENUMERATE_SUB_KEYS access right.
|
||||
* @param dwIndex
|
||||
* Index of the subkey to retrieve. This parameter should be zero for the first
|
||||
* call to the RegEnumKeyEx function and then incremented for subsequent calls.
|
||||
* Because subkeys are not ordered, any new subkey will have an arbitrary index.
|
||||
* This means that the function may return subkeys in any order.
|
||||
* @param lpName
|
||||
* Pointer to a buffer that receives the name of the subkey, including the
|
||||
* terminating null character. The function copies only the name of the subkey,
|
||||
* not the full key hierarchy, to the buffer.
|
||||
* @param lpcName
|
||||
* Pointer to a variable that specifies the size of the buffer specified by the
|
||||
* lpName parameter, in TCHARs. This size should include the terminating null
|
||||
* character. When the function returns, the variable pointed to by lpcName
|
||||
* contains the number of characters stored in the buffer. The count returned
|
||||
* does not include the terminating null character.
|
||||
* @param reserved
|
||||
* Reserved; must be NULL.
|
||||
* @param lpClass
|
||||
* Pointer to a buffer that receives the null-terminated class string of the
|
||||
* enumerated subkey. This parameter can be NULL.
|
||||
* @param lpcClass
|
||||
* Pointer to a variable that specifies the size of the buffer specified by the
|
||||
* lpClass parameter, in TCHARs. The size should include the terminating null
|
||||
* character. When the function returns, lpcClass contains the number of
|
||||
* characters stored in the buffer. The count returned does not include the
|
||||
* terminating null character. This parameter can be NULL only if lpClass is NULL.
|
||||
* @param lpftLastWriteTime
|
||||
* Pointer to a variable that receives the time at which the enumerated subkey
|
||||
* was last written.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegEnumKeyEx(HKEY hKey, int dwIndex, char[] lpName, IntByReference lpcName,
|
||||
IntByReference reserved, char[] lpClass, IntByReference lpcClass,
|
||||
WinBase.FILETIME lpftLastWriteTime);
|
||||
|
||||
/**
|
||||
* The RegEnumValue function enumerates the values for the specified open registry
|
||||
* key. The function copies one indexed value name and data block for the key each
|
||||
* time it is called.
|
||||
* @param hKey
|
||||
* Handle to an open key. The key must have been opened with the KEY_QUERY_VALUE
|
||||
* access right.
|
||||
* @param dwIndex
|
||||
* Index of the value to be retrieved. This parameter should be zero for the first
|
||||
* call to the RegEnumValue function and then be incremented for subsequent calls.
|
||||
* Because values are not ordered, any new value will have an arbitrary index.
|
||||
* This means that the function may return values in any order.
|
||||
* @param lpValueName
|
||||
* Pointer to a buffer that receives the name of the value, including the
|
||||
* terminating null character.
|
||||
* @param lpcchValueName
|
||||
* Pointer to a variable that specifies the size of the buffer pointed to by the
|
||||
* lpValueName parameter, in TCHARs. This size should include the terminating null
|
||||
* character. When the function returns, the variable pointed to by lpcValueName
|
||||
* contains the number of characters stored in the buffer. The count returned
|
||||
* does not include the terminating null character.
|
||||
* @param reserved
|
||||
* Reserved; must be NULL.
|
||||
* @param lpType
|
||||
* Pointer to a variable that receives a code indicating the type of data stored
|
||||
* in the specified value.
|
||||
* @param lpData
|
||||
* Pointer to a buffer that receives the data for the value entry. This parameter
|
||||
* can be NULL if the data is not required.
|
||||
* @param lpcbData
|
||||
* Pointer to a variable that specifies the size of the buffer pointed to by the
|
||||
* lpData parameter, in bytes.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegEnumValue(HKEY hKey, int dwIndex, char[] lpValueName,
|
||||
IntByReference lpcchValueName, IntByReference reserved,
|
||||
IntByReference lpType, byte[] lpData, IntByReference lpcbData);
|
||||
|
||||
/**
|
||||
* The RegQueryInfoKey function retrieves information about the specified
|
||||
* registry key.
|
||||
* @param hKey
|
||||
* A handle to an open key. The key must have been opened with the
|
||||
* KEY_QUERY_VALUE access right.
|
||||
* @param lpClass
|
||||
* A pointer to a buffer that receives the null-terminated class
|
||||
* string of the key. This parameter can be ignored. This parameter can be NULL.
|
||||
* @param lpcClass
|
||||
* A pointer to a variable that specifies the size of the buffer pointed to by
|
||||
* the lpClass parameter, in characters.
|
||||
* @param lpReserved
|
||||
* Reserved; must be NULL.
|
||||
* @param lpcSubKeys
|
||||
* A pointer to a variable that receives the number of subkeys that are contained by the specified key.
|
||||
* This parameter can be NULL.
|
||||
* @param lpcMaxSubKeyLen
|
||||
* A pointer to a variable that receives the size of the key's subkey with the
|
||||
* longest name, in characters, not including the terminating null character.
|
||||
* This parameter can be NULL.
|
||||
* @param lpcMaxClassLen
|
||||
* A pointer to a variable that receives the size of the longest string that
|
||||
* specifies a subkey class, in characters. The count returned does not include
|
||||
* the terminating null character. This parameter can be NULL.
|
||||
* @param lpcValues
|
||||
* A pointer to a variable that receives the number of values that are associated
|
||||
* with the key. This parameter can be NULL.
|
||||
* @param lpcMaxValueNameLen
|
||||
* A pointer to a variable that receives the size of the key's longest value name,
|
||||
* in characters. The size does not include the terminating null character. This
|
||||
* parameter can be NULL.
|
||||
* @param lpcMaxValueLen
|
||||
* A pointer to a variable that receives the size of the longest data component
|
||||
* among the key's values, in bytes. This parameter can be NULL.
|
||||
* @param lpcbSecurityDescriptor
|
||||
* A pointer to a variable that receives the size of the key's security descriptor,
|
||||
* in bytes. This parameter can be NULL.
|
||||
* @param lpftLastWriteTime
|
||||
* A pointer to a FILETIME structure that receives the last write time.
|
||||
* This parameter can be NULL.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegQueryInfoKey(HKEY hKey, char[] lpClass,
|
||||
IntByReference lpcClass, IntByReference lpReserved,
|
||||
IntByReference lpcSubKeys, IntByReference lpcMaxSubKeyLen,
|
||||
IntByReference lpcMaxClassLen, IntByReference lpcValues,
|
||||
IntByReference lpcMaxValueNameLen, IntByReference lpcMaxValueLen,
|
||||
IntByReference lpcbSecurityDescriptor,
|
||||
WinBase.FILETIME lpftLastWriteTime);
|
||||
}
|
||||
@@ -0,0 +1,902 @@
|
||||
/* 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.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.platform.win32.WinNT.PSIDByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.SID_AND_ATTRIBUTES;
|
||||
import com.sun.jna.platform.win32.WinNT.SID_NAME_USE;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEY;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEYByReference;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* Advapi32 utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Advapi32Util {
|
||||
|
||||
/**
|
||||
* An account.
|
||||
*/
|
||||
public static class Account {
|
||||
/**
|
||||
* Account name.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* Account domain.
|
||||
*/
|
||||
public String domain;
|
||||
/**
|
||||
* Account SID.
|
||||
*/
|
||||
public byte[] sid;
|
||||
/**
|
||||
* String representation of the account SID.
|
||||
*/
|
||||
public String sidString;
|
||||
/**
|
||||
* Account type, one of SID_NAME_USE.
|
||||
*/
|
||||
public int accountType;
|
||||
/**
|
||||
* Fully qualified account name.
|
||||
*/
|
||||
public String fqn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the name of the user associated with the current thread.
|
||||
* @return A user name.
|
||||
*/
|
||||
public static String getUserName() {
|
||||
char[] buffer = new char[128];
|
||||
IntByReference len = new IntByReference(buffer.length);
|
||||
boolean result = Advapi32.INSTANCE.GetUserNameW(buffer, len);
|
||||
|
||||
if (! result) {
|
||||
|
||||
int rc = Kernel32.INSTANCE.GetLastError();
|
||||
|
||||
switch(rc) {
|
||||
case W32Errors.ERROR_INSUFFICIENT_BUFFER:
|
||||
buffer = new char[len.getValue()];
|
||||
break;
|
||||
default:
|
||||
throw new Win32Exception(Native.getLastError());
|
||||
}
|
||||
|
||||
result = Advapi32.INSTANCE.GetUserNameW(buffer, len);
|
||||
}
|
||||
|
||||
if (! result) {
|
||||
throw new Win32Exception(Native.getLastError());
|
||||
}
|
||||
|
||||
return Native.toString(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a security identifier (SID) for the account on the current system.
|
||||
* @param accountName Specifies the account name.
|
||||
* @return A structure containing the account SID;
|
||||
*/
|
||||
public static Account getAccountByName(String accountName) {
|
||||
return getAccountByName(null, accountName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a security identifier (SID) for a given account.
|
||||
* @param systemName Name of the system.
|
||||
* @param accountName Account name.
|
||||
* @return A structure containing the account SID.
|
||||
*/
|
||||
public static Account getAccountByName(String systemName, String accountName) {
|
||||
IntByReference pSid = new IntByReference(0);
|
||||
IntByReference cchDomainName = new IntByReference(0);
|
||||
PointerByReference peUse = new PointerByReference();
|
||||
|
||||
if (Advapi32.INSTANCE.LookupAccountName(systemName, accountName, null, pSid, null, cchDomainName, peUse)) {
|
||||
throw new RuntimeException("LookupAccountNameW was expected to fail with ERROR_INSUFFICIENT_BUFFER");
|
||||
}
|
||||
|
||||
int rc = Kernel32.INSTANCE.GetLastError();
|
||||
if (pSid.getValue() == 0 || rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
|
||||
Memory sidMemory = new Memory(pSid.getValue());
|
||||
PSID result = new PSID(sidMemory);
|
||||
char[] referencedDomainName = new char[cchDomainName.getValue() + 1];
|
||||
|
||||
if (! Advapi32.INSTANCE.LookupAccountName(systemName, accountName, result, pSid, referencedDomainName, cchDomainName, peUse)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
Account account = new Account();
|
||||
account.accountType = peUse.getPointer().getInt(0);
|
||||
account.name = accountName;
|
||||
|
||||
String[] accountNamePartsBs = accountName.split("\\\\", 2);
|
||||
String[] accountNamePartsAt = accountName.split("@", 2);
|
||||
|
||||
if (accountNamePartsBs.length == 2) {
|
||||
account.name = accountNamePartsBs[1];
|
||||
} else if (accountNamePartsAt.length == 2) {
|
||||
account.name = accountNamePartsAt[0];
|
||||
} else {
|
||||
account.name = accountName;
|
||||
}
|
||||
|
||||
if (cchDomainName.getValue() > 0) {
|
||||
account.domain = Native.toString(referencedDomainName);
|
||||
account.fqn = account.domain + "\\" + account.name;
|
||||
} else {
|
||||
account.fqn = account.name;
|
||||
}
|
||||
|
||||
account.sid = result.getBytes();
|
||||
account.sidString = convertSidToStringSid(new PSID(account.sid));
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the account by SID on the local system.
|
||||
*
|
||||
* @param sid SID.
|
||||
* @return Account.
|
||||
*/
|
||||
public static Account getAccountBySid(PSID sid) {
|
||||
return getAccountBySid(null, sid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the account by SID.
|
||||
*
|
||||
* @param systemName Name of the system.
|
||||
* @param sid SID.
|
||||
* @return Account.
|
||||
*/
|
||||
public static Account getAccountBySid(String systemName, PSID sid) {
|
||||
IntByReference cchName = new IntByReference();
|
||||
IntByReference cchDomainName = new IntByReference();
|
||||
PointerByReference peUse = new PointerByReference();
|
||||
|
||||
if (Advapi32.INSTANCE.LookupAccountSid(null, sid,
|
||||
null, cchName, null, cchDomainName, peUse)) {
|
||||
throw new RuntimeException("LookupAccountSidW was expected to fail with ERROR_INSUFFICIENT_BUFFER");
|
||||
}
|
||||
|
||||
int rc = Kernel32.INSTANCE.GetLastError();
|
||||
if (cchName.getValue() == 0 || rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
|
||||
char[] domainName = new char[cchDomainName.getValue()];
|
||||
char[] name = new char[cchName.getValue()];
|
||||
|
||||
if (! Advapi32.INSTANCE.LookupAccountSid(null, sid,
|
||||
name, cchName, domainName, cchDomainName, peUse)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
Account account = new Account();
|
||||
account.accountType = peUse.getPointer().getInt(0);
|
||||
account.name = Native.toString(name);
|
||||
|
||||
if (cchDomainName.getValue() > 0) {
|
||||
account.domain = Native.toString(domainName);
|
||||
account.fqn = account.domain + "\\" + account.name;
|
||||
} else {
|
||||
account.fqn = account.name;
|
||||
}
|
||||
|
||||
account.sid = sid.getBytes();
|
||||
account.sidString = convertSidToStringSid(sid);
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a security identifier (SID) to a string format suitable for display,
|
||||
* storage, or transmission.
|
||||
* @param sid SID bytes.
|
||||
* @return String SID.
|
||||
*/
|
||||
public static String convertSidToStringSid(PSID sid) {
|
||||
PointerByReference stringSid = new PointerByReference();
|
||||
if (! Advapi32.INSTANCE.ConvertSidToStringSid(sid, stringSid)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
String result = stringSid.getValue().getString(0, true);
|
||||
Kernel32.INSTANCE.LocalFree(stringSid.getValue());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string representation of a security identifier (SID) to
|
||||
* a binary format.
|
||||
* @param sidString
|
||||
* String SID.
|
||||
* @return SID bytes.
|
||||
*/
|
||||
public static byte[] convertStringSidToSid(String sidString) {
|
||||
PSIDByReference pSID = new PSIDByReference();
|
||||
if (! Advapi32.INSTANCE.ConvertStringSidToSid(sidString, pSID)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return pSID.getValue().getBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares a SID to a well known SID and returns TRUE if they match.
|
||||
* @param sidString
|
||||
* String representation of a SID.
|
||||
* @param wellKnownSidType
|
||||
* Member of the WELL_KNOWN_SID_TYPE enumeration to compare with the SID at pSid.
|
||||
* @return
|
||||
* True if the SID is of the well-known type, false otherwise.
|
||||
*/
|
||||
public static boolean isWellKnownSid(String sidString, int wellKnownSidType) {
|
||||
PSIDByReference pSID = new PSIDByReference();
|
||||
if (! Advapi32.INSTANCE.ConvertStringSidToSid(sidString, pSID)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return Advapi32.INSTANCE.IsWellKnownSid(pSID.getValue(), wellKnownSidType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares a SID to a well known SID and returns TRUE if they match.
|
||||
* @param sidBytes
|
||||
* Byte representation of a SID.
|
||||
* @param wellKnownSidType
|
||||
* Member of the WELL_KNOWN_SID_TYPE enumeration to compare with the SID at pSid.
|
||||
* @return
|
||||
* True if the SID is of the well-known type, false otherwise.
|
||||
*/
|
||||
public static boolean isWellKnownSid(byte[] sidBytes, int wellKnownSidType) {
|
||||
PSID pSID = new PSID(sidBytes);
|
||||
return Advapi32.INSTANCE.IsWellKnownSid(pSID, wellKnownSidType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an account name from a string SID on the local machine.
|
||||
*
|
||||
* @param sidString SID.
|
||||
* @return Account.
|
||||
*/
|
||||
public static Account getAccountBySid(String sidString) {
|
||||
return getAccountBySid(null, sidString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an account name from a string SID.
|
||||
*
|
||||
* @param systemName System name.
|
||||
* @param sidString SID.
|
||||
* @return Account.
|
||||
*/
|
||||
public static Account getAccountBySid(String systemName, String sidString) {
|
||||
return getAccountBySid(systemName, new PSID(convertStringSidToSid(sidString)));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns the groups associated with a security token,
|
||||
* such as a user token.
|
||||
*
|
||||
* @param hToken Token.
|
||||
* @return Token groups.
|
||||
*/
|
||||
public static Account[] getTokenGroups(HANDLE hToken) {
|
||||
// get token group information size
|
||||
IntByReference tokenInformationLength = new IntByReference();
|
||||
if (Advapi32.INSTANCE.GetTokenInformation(hToken,
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenGroups, null, 0, tokenInformationLength)) {
|
||||
throw new RuntimeException("Expected GetTokenInformation to fail with ERROR_INSUFFICIENT_BUFFER");
|
||||
}
|
||||
int rc = Kernel32.INSTANCE.GetLastError();
|
||||
if (rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
// get token group information
|
||||
WinNT.TOKEN_GROUPS groups = new WinNT.TOKEN_GROUPS(tokenInformationLength.getValue());
|
||||
if (! Advapi32.INSTANCE.GetTokenInformation(hToken,
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenGroups, groups,
|
||||
tokenInformationLength.getValue(), tokenInformationLength)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
ArrayList<Account> userGroups = new ArrayList<Account>();
|
||||
// make array of names
|
||||
for (SID_AND_ATTRIBUTES sidAndAttribute : groups.getGroups()) {
|
||||
Account group = null;
|
||||
try {
|
||||
group = Advapi32Util.getAccountBySid(sidAndAttribute.Sid);
|
||||
} catch(Exception e) {
|
||||
group = new Account();
|
||||
group.sid = sidAndAttribute.Sid.getBytes();
|
||||
group.sidString = Advapi32Util.convertSidToStringSid(sidAndAttribute.Sid);
|
||||
group.name = group.sidString;
|
||||
group.fqn = group.sidString;
|
||||
group.accountType = SID_NAME_USE.SidTypeGroup;
|
||||
}
|
||||
userGroups.add(group);
|
||||
}
|
||||
return userGroups.toArray(new Account[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns the information about the user who owns a security token,
|
||||
*
|
||||
* @param hToken Token.
|
||||
* @return Token user.
|
||||
*/
|
||||
public static Account getTokenAccount(HANDLE hToken) {
|
||||
// get token group information size
|
||||
IntByReference tokenInformationLength = new IntByReference();
|
||||
if (Advapi32.INSTANCE.GetTokenInformation(hToken,
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenUser, null, 0, tokenInformationLength)) {
|
||||
throw new RuntimeException("Expected GetTokenInformation to fail with ERROR_INSUFFICIENT_BUFFER");
|
||||
}
|
||||
int rc = Kernel32.INSTANCE.GetLastError();
|
||||
if (rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
// get token user information
|
||||
WinNT.TOKEN_USER user = new WinNT.TOKEN_USER(tokenInformationLength.getValue());
|
||||
if (! Advapi32.INSTANCE.GetTokenInformation(hToken,
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenUser, user,
|
||||
tokenInformationLength.getValue(), tokenInformationLength)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return getAccountBySid(user.User.Sid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the group memberships of the currently logged on user.
|
||||
* @return An array of groups.
|
||||
*/
|
||||
public static Account[] getCurrentUserGroups() {
|
||||
HANDLEByReference phToken = new HANDLEByReference();
|
||||
try {
|
||||
// open thread or process token
|
||||
HANDLE threadHandle = Kernel32.INSTANCE.GetCurrentThread();
|
||||
if (! Advapi32.INSTANCE.OpenThreadToken(threadHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, true, phToken)) {
|
||||
if (W32Errors.ERROR_NO_TOKEN != Kernel32.INSTANCE.GetLastError()) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
|
||||
if (! Advapi32.INSTANCE.OpenProcessToken(processHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
}
|
||||
return getTokenGroups(phToken.getValue());
|
||||
} finally {
|
||||
if (phToken.getValue() != WinBase.INVALID_HANDLE_VALUE) {
|
||||
if (! Kernel32.INSTANCE.CloseHandle(phToken.getValue())) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a registry key exists.
|
||||
* @param root
|
||||
* HKEY_LOCAL_MACHINE, etc.
|
||||
* @param key
|
||||
* Path to the registry key.
|
||||
* @return
|
||||
* True if the key exists.
|
||||
*/
|
||||
public static boolean registryKeyExists(HKEY root, String key) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, phkKey);
|
||||
switch(rc) {
|
||||
case W32Errors.ERROR_SUCCESS:
|
||||
Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
return true;
|
||||
case W32Errors.ERROR_FILE_NOT_FOUND:
|
||||
return false;
|
||||
default:
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a registry value exists.
|
||||
* @param root
|
||||
* HKEY_LOCAL_MACHINE, etc.
|
||||
* @param key
|
||||
* Registry key path.
|
||||
* @param value
|
||||
* Value name.
|
||||
* @return
|
||||
* True if the value exists.
|
||||
*/
|
||||
public static boolean registryValueExists(HKEY root, String key, String value) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, phkKey);
|
||||
try {
|
||||
switch(rc) {
|
||||
case W32Errors.ERROR_SUCCESS:
|
||||
break;
|
||||
case W32Errors.ERROR_FILE_NOT_FOUND:
|
||||
return false;
|
||||
default:
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
IntByReference lpcbData = new IntByReference();
|
||||
IntByReference lpType = new IntByReference();
|
||||
rc = Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData);
|
||||
switch(rc) {
|
||||
case W32Errors.ERROR_SUCCESS:
|
||||
case W32Errors.ERROR_INSUFFICIENT_BUFFER:
|
||||
return true;
|
||||
case W32Errors.ERROR_FILE_NOT_FOUND:
|
||||
return false;
|
||||
default:
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
} finally {
|
||||
if (phkKey.getValue() != WinBase.INVALID_HANDLE_VALUE) {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a registry REG_SZ value.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param key
|
||||
* Registry path.
|
||||
* @param value
|
||||
* Name of the value to retrieve.
|
||||
* @return
|
||||
* String value.
|
||||
*/
|
||||
public static String registryGetStringValue(HKEY root, String key, String value) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
IntByReference lpcbData = new IntByReference();
|
||||
IntByReference lpType = new IntByReference();
|
||||
rc = Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData);
|
||||
if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
if (lpType.getValue() != WinNT.REG_SZ) {
|
||||
throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ");
|
||||
}
|
||||
char[] data = new char[lpcbData.getValue()];
|
||||
rc = Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkKey.getValue(), value, 0, lpType, data, lpcbData);
|
||||
if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return Native.toString(data);
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a registry DWORD value.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param key
|
||||
* Registry key path.
|
||||
* @param value
|
||||
* Name of the value to retrieve.
|
||||
* @return
|
||||
* Integer value.
|
||||
*/
|
||||
public static int registryGetIntValue(HKEY root, String key, String value) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
IntByReference lpcbData = new IntByReference();
|
||||
IntByReference lpType = new IntByReference();
|
||||
rc = Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData);
|
||||
if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
if (lpType.getValue() != WinNT.REG_DWORD) {
|
||||
throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ");
|
||||
}
|
||||
IntByReference data = new IntByReference();
|
||||
rc = Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkKey.getValue(), value, 0, lpType, data, lpcbData);
|
||||
if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return data.getValue();
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a registry key.
|
||||
* @param hKey
|
||||
* Parent key.
|
||||
* @param keyName
|
||||
* Key name.
|
||||
*/
|
||||
public static void registryCreateKey(HKEY hKey, String keyName) {
|
||||
HKEYByReference phkResult = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegCreateKeyEx(hKey, keyName, 0, null, 0,
|
||||
WinNT.KEY_READ, null, phkResult, null);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkResult.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a registry key.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param parentPath
|
||||
* Path to an existing registry key.
|
||||
* @param keyName
|
||||
* Key name.
|
||||
*/
|
||||
public static void registryCreateKey(HKEY root, String parentPath, String keyName) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, parentPath, 0, WinNT.KEY_CREATE_SUB_KEY, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
registryCreateKey(phkKey.getValue(), keyName);
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an integer value in registry.
|
||||
* @param hKey
|
||||
* Parent key.
|
||||
* @param name
|
||||
* Name.
|
||||
* @param value
|
||||
* Value.
|
||||
*/
|
||||
public static void registrySetIntValue(HKEY hKey, String name, int value) {
|
||||
byte[] data = new byte[4];
|
||||
data[0] = (byte)(value & 0xff);
|
||||
data[1] = (byte)((value >> 8) & 0xff);
|
||||
data[2] = (byte)((value >> 16) & 0xff);
|
||||
data[3] = (byte)((value >> 24) & 0xff);
|
||||
int rc = Advapi32.INSTANCE.RegSetValueEx(hKey, name, 0, WinNT.REG_DWORD, data, 4);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an integer value in registry.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param keyPath
|
||||
* Path to an existing registry key.
|
||||
* @param name
|
||||
* Name.
|
||||
* @param value
|
||||
* Value.
|
||||
*/
|
||||
public static void registrySetIntValue(HKEY root, String keyPath, String name, int value) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
registrySetIntValue(phkKey.getValue(), name, value);
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a string value in registry.
|
||||
* @param hKey
|
||||
* Parent key.
|
||||
* @param name
|
||||
* Name.
|
||||
* @param value
|
||||
* Value.
|
||||
*/
|
||||
public static void registrySetStringValue(HKEY hKey, String name, String value) {
|
||||
char[] data = Native.toCharArray(value);
|
||||
int rc = Advapi32.INSTANCE.RegSetValueEx(hKey, name, 0, WinNT.REG_SZ, data, data.length * 2);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a string value in registry.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param keyPath
|
||||
* Path to an existing registry key.
|
||||
* @param name
|
||||
* Name.
|
||||
* @param value
|
||||
* Value.
|
||||
*/
|
||||
public static void registrySetStringValue(HKEY root, String keyPath, String name, String value) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
registrySetStringValue(phkKey.getValue(), name, value);
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a registry key.
|
||||
* @param hKey
|
||||
* Parent key.
|
||||
* @param keyName
|
||||
* Name of the key to delete.
|
||||
*/
|
||||
public static void registryDeleteKey(HKEY hKey, String keyName) {
|
||||
int rc = Advapi32.INSTANCE.RegDeleteKey(hKey, keyName);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a registry key.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param keyPath
|
||||
* Path to an existing registry key.
|
||||
* @param keyName
|
||||
* Name of the key to delete.
|
||||
*/
|
||||
public static void registryDeleteKey(HKEY root, String keyPath, String keyName) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
registryDeleteKey(phkKey.getValue(), keyName);
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a registry value.
|
||||
* @param hKey
|
||||
* Parent key.
|
||||
* @param valueName
|
||||
* Name of the value to delete.
|
||||
*/
|
||||
public static void registryDeleteValue(HKEY hKey, String valueName) {
|
||||
int rc = Advapi32.INSTANCE.RegDeleteValue(hKey, valueName);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a registry value.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param keyPath
|
||||
* Path to an existing registry key.
|
||||
* @param valueName
|
||||
* Name of the value to delete.
|
||||
*/
|
||||
public static void registryDeleteValue(HKEY root, String keyPath, String valueName) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
registryDeleteValue(phkKey.getValue(), valueName);
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get names of the registry key's sub-keys.
|
||||
* @param hKey
|
||||
* Registry key.
|
||||
* @return
|
||||
* Array of registry key names.
|
||||
*/
|
||||
public static String[] registryGetKeys(HKEY hKey) {
|
||||
IntByReference lpcSubKeys = new IntByReference();
|
||||
IntByReference lpcMaxSubKeyLen = new IntByReference();
|
||||
int rc = Advapi32.INSTANCE.RegQueryInfoKey(hKey, null, null, null,
|
||||
lpcSubKeys, lpcMaxSubKeyLen, null, null, null, null, null, null);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
ArrayList<String> keys = new ArrayList<String>(lpcSubKeys.getValue());
|
||||
char[] name = new char[lpcMaxSubKeyLen.getValue() + 1];
|
||||
for (int i = 0; i < lpcSubKeys.getValue(); i++) {
|
||||
IntByReference lpcchValueName = new IntByReference(lpcMaxSubKeyLen.getValue() + 1);
|
||||
rc = Advapi32.INSTANCE.RegEnumKeyEx(hKey, i, name, lpcchValueName,
|
||||
null, null, null, null);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
keys.add(Native.toString(name));
|
||||
}
|
||||
return keys.toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get names of the registry key's sub-keys.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param keyPath
|
||||
* Path to a registry key.
|
||||
* @return
|
||||
* Array of registry key names.
|
||||
*/
|
||||
public static String[] registryGetKeys(HKEY root, String keyPath) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
return registryGetKeys(phkKey.getValue());
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a table of registry values.
|
||||
* @param hKey
|
||||
* Registry key.
|
||||
* @return
|
||||
* Table of values.
|
||||
*/
|
||||
public static TreeMap<String, Object> registryGetValues(HKEY hKey) {
|
||||
IntByReference lpcValues = new IntByReference();
|
||||
IntByReference lpcMaxValueNameLen = new IntByReference();
|
||||
IntByReference lpcMaxValueLen = new IntByReference();
|
||||
int rc = Advapi32.INSTANCE.RegQueryInfoKey(hKey, null, null, null, null,
|
||||
null, null, lpcValues, lpcMaxValueNameLen, lpcMaxValueLen, null, null);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
TreeMap<String, Object> keyValues = new TreeMap<String, Object>();
|
||||
char[] name = new char[lpcMaxValueNameLen.getValue() + 1];
|
||||
byte[] data = new byte[lpcMaxValueLen.getValue()];
|
||||
for (int i = 0; i < lpcValues.getValue(); i++) {
|
||||
IntByReference lpcchValueName = new IntByReference(lpcMaxValueNameLen.getValue() + 1);
|
||||
IntByReference lpcbData = new IntByReference(lpcMaxValueLen.getValue());
|
||||
IntByReference lpType = new IntByReference();
|
||||
rc = Advapi32.INSTANCE.RegEnumValue(hKey, i, name, lpcchValueName, null,
|
||||
lpType, data, lpcbData);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
switch(lpType.getValue()) {
|
||||
case WinNT.REG_DWORD:
|
||||
keyValues.put(Native.toString(name),
|
||||
((int)(data[0] & 0xff)) +
|
||||
(((int)(data[1] & 0xff)) << 8) +
|
||||
(((int)(data[2] & 0xff)) << 16) +
|
||||
(((int)(data[3] & 0xff)) << 24));
|
||||
break;
|
||||
case WinNT.REG_SZ:
|
||||
try {
|
||||
keyValues.put(Native.toString(name),
|
||||
new String(data, 0, data.length - 2, "UTF-16LE"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unsupported type: " + lpType.getValue());
|
||||
}
|
||||
}
|
||||
return keyValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a table of registry values.
|
||||
* @param root
|
||||
* Registry root.
|
||||
* @param keyPath
|
||||
* Regitry key path.
|
||||
* @return
|
||||
* Table of values.
|
||||
*/
|
||||
public static TreeMap<String, Object> registryGetValues(HKEY root, String keyPath) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
return registryGetValues(phkKey.getValue());
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/* 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 com.sun.jna.IntegerType;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* @author dblock[at]dblock[dot]org
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public interface BaseTSD extends StdCallLibrary {
|
||||
/**
|
||||
* Signed long type for pointer precision.
|
||||
* Use when casting a pointer to a long to perform pointer arithmetic.
|
||||
*/
|
||||
public static class LONG_PTR extends IntegerType {
|
||||
public LONG_PTR() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public LONG_PTR(long value) {
|
||||
super(Pointer.SIZE, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Signed SIZE_T.
|
||||
*/
|
||||
public static class SSIZE_T extends LONG_PTR {
|
||||
public SSIZE_T() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public SSIZE_T(long value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsigned LONG_PTR.
|
||||
*/
|
||||
public static class ULONG_PTR extends IntegerType {
|
||||
public ULONG_PTR() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public ULONG_PTR(long value) {
|
||||
super(Pointer.SIZE, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsigned DWORD_PTR.
|
||||
*/
|
||||
public static class DWORD_PTR extends IntegerType {
|
||||
public DWORD_PTR() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public DWORD_PTR(long value) {
|
||||
super(Pointer.SIZE, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The maximum number of bytes to which a pointer can point.
|
||||
* Use for a count that must span the full range of a pointer.
|
||||
*/
|
||||
public static class SIZE_T extends ULONG_PTR {
|
||||
public SIZE_T() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public SIZE_T(long value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/* 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 com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.WinCrypt.CRYPTPROTECT_PROMPTSTRUCT;
|
||||
import com.sun.jna.platform.win32.WinCrypt.DATA_BLOB;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Crypt32.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Crypt32 extends StdCallLibrary {
|
||||
|
||||
Crypt32 INSTANCE = (Crypt32) Native.loadLibrary("Crypt32",
|
||||
Crypt32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* The CryptProtectData function performs encryption on the data in a DATA_BLOB
|
||||
* structure. Typically, only a user with the same logon credential as the encrypter
|
||||
* can decrypt the data. In addition, the encryption and decryption usually must be
|
||||
* done on the same computer.
|
||||
* @param pDataIn
|
||||
* Pointer to a DATA_BLOB structure that contains the plaintext to be encrypted.
|
||||
* @param szDataDescr
|
||||
* String with a readable description of the data to be encrypted. This description
|
||||
* string is included with the encrypted data. This parameter is optional and can
|
||||
* be set to NULL, except on Windows 2000.
|
||||
* @param pOptionalEntropy
|
||||
* Pointer to a DATA_BLOB structure that contains a password or other additional
|
||||
* entropy used to encrypt the data. The DATA_BLOB structure used in the encryption
|
||||
* phase must also be used in the decryption phase. This parameter can be set to NULL
|
||||
* for no additional entropy.
|
||||
* @param pvReserved
|
||||
* Reserved for future use and must be set to NULL.
|
||||
* @param pPromptStruct
|
||||
* Pointer to a CRYPTPROTECT_PROMPTSTRUCT structure that provides information about
|
||||
* where and when prompts are to be displayed and what the content of those prompts
|
||||
* should be. This parameter can be set to NULL in both the encryption and decryption
|
||||
* phases.
|
||||
* @param dwFlags
|
||||
* One of CRYPTPROTECT_LOCAL_MACHINE, CRYPTPROTECT_UI_FORBIDDEN, CRYPTPROTECT_AUDIT,
|
||||
* CRYPTPROTECT_VERIFY_PROTECTION.
|
||||
* @param pDataOut
|
||||
* Pointer to a DATA_BLOB structure that receives the encrypted data. When you have
|
||||
* finished using the DATA_BLOB structure, free its pbData member by calling the
|
||||
* LocalFree function.
|
||||
* @return
|
||||
* If the function succeeds, the function returns TRUE. If the function fails,
|
||||
* it returns FALSE. For extended error information, call GetLastError.
|
||||
*/
|
||||
public boolean CryptProtectData(DATA_BLOB pDataIn, String szDataDescr,
|
||||
DATA_BLOB pOptionalEntropy, Pointer pvReserved,
|
||||
CRYPTPROTECT_PROMPTSTRUCT pPromptStruct,
|
||||
int dwFlags,
|
||||
DATA_BLOB pDataOut);
|
||||
|
||||
/**
|
||||
* The CryptUnprotectData function decrypts and does an integrity check of the data in
|
||||
* a DATA_BLOB structure. Usually, only a user with the same logon credentials as the
|
||||
* encrypter can decrypt the data. In addition, the encryption and decryption must be
|
||||
* done on the same computer.
|
||||
* @param pDataIn
|
||||
* Pointer to a DATA_BLOB structure that holds the encrypted data. The DATA_BLOB
|
||||
* structure's cbData member holds the length of the pbData member's byte string that
|
||||
* contains the text to be encrypted.
|
||||
* @param szDataDescr
|
||||
* Pointer to a string-readable description of the encrypted data included with the
|
||||
* encrypted data. This parameter can be set to NULL. When you have finished using
|
||||
* ppszDataDescr, free it by calling the LocalFree function.
|
||||
* @param pOptionalEntropy
|
||||
* Pointer to a DATA_BLOB structure that contains a password or other additional
|
||||
* entropy used when the data was encrypted. This parameter can be set to NULL;
|
||||
* however, if an optional entropy DATA_BLOB structure was used in the encryption
|
||||
* phase, that same DATA_BLOB structure must be used for the decryption phase.
|
||||
* @param pvReserved
|
||||
* Reserved for future use; must be set to NULL.
|
||||
* @param pPromptStruct
|
||||
* Pointer to a CRYPTPROTECT_PROMPTSTRUCT structure that provides information about
|
||||
* where and when prompts are to be displayed and what the content of those prompts
|
||||
* should be. This parameter can be set to NULL.
|
||||
* @param dwFlags
|
||||
* DWORD value that specifies options for this function. This parameter can be zero,
|
||||
* in which case no option is set, or CRYPTPROTECT_UI_FORBIDDEN.
|
||||
* @param pDataOut
|
||||
* Pointer to a DATA_BLOB structure where the function stores the decrypted data.
|
||||
* When you have finished using the DATA_BLOB structure, free its pbData member by
|
||||
* calling the LocalFree function.
|
||||
* @return
|
||||
* If the function succeeds, the return value is TRUE. If the function fails, the
|
||||
* return value is FALSE.
|
||||
*/
|
||||
public boolean CryptUnprotectData(DATA_BLOB pDataIn, PointerByReference szDataDescr,
|
||||
DATA_BLOB pOptionalEntropy, Pointer pvReserved,
|
||||
CRYPTPROTECT_PROMPTSTRUCT pPromptStruct,
|
||||
int dwFlags,
|
||||
DATA_BLOB pDataOut);
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/* 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 com.sun.jna.platform.win32.WinCrypt.CRYPTPROTECT_PROMPTSTRUCT;
|
||||
import com.sun.jna.platform.win32.WinCrypt.DATA_BLOB;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* Crypt32 utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Crypt32Util {
|
||||
|
||||
/**
|
||||
* Protect a blob of data.
|
||||
* @param data
|
||||
* Data to protect.
|
||||
* @return
|
||||
* Protected data.
|
||||
*/
|
||||
public static byte[] cryptProtectData(byte[] data) {
|
||||
return cryptProtectData(data, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protect a blob of data with optional flags.
|
||||
* @param data
|
||||
* Data to protect.
|
||||
* @param flags
|
||||
* Optional flags, eg. CRYPTPROTECT_LOCAL_MACHINE | CRYPTPROTECT_UI_FORBIDDEN.
|
||||
* @return
|
||||
* Protected data.
|
||||
*/
|
||||
public static byte[] cryptProtectData(byte[] data, int flags) {
|
||||
return cryptProtectData(data, null, flags, "", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protect a blob of data.
|
||||
* @param data
|
||||
* Data to protect.
|
||||
* @param entropy
|
||||
* Optional entropy.
|
||||
* @param flags
|
||||
* Optional flags.
|
||||
* @param description
|
||||
* Optional description.
|
||||
* @param prompt
|
||||
* Prompt structure.
|
||||
* @return
|
||||
* Protected bytes.
|
||||
*/
|
||||
public static byte[] cryptProtectData(byte[] data, byte[] entropy, int flags,
|
||||
String description, CRYPTPROTECT_PROMPTSTRUCT prompt) {
|
||||
DATA_BLOB pDataIn = new DATA_BLOB(data);
|
||||
DATA_BLOB pDataProtected = new DATA_BLOB();
|
||||
DATA_BLOB pEntropy = (entropy == null) ? null : new DATA_BLOB(entropy);
|
||||
try {
|
||||
if (! Crypt32.INSTANCE.CryptProtectData(pDataIn, description,
|
||||
pEntropy, null, prompt, flags, pDataProtected)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return pDataProtected.getData();
|
||||
} finally {
|
||||
if (pDataProtected.pbData != null) {
|
||||
Kernel32.INSTANCE.LocalFree(pDataProtected.pbData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unprotect a blob of data.
|
||||
* @param data
|
||||
* Data to unprotect.
|
||||
* @return
|
||||
* Unprotected blob of data.
|
||||
*/
|
||||
public static byte[] cryptUnprotectData(byte[] data) {
|
||||
return cryptUnprotectData(data, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unprotect a blob of data.
|
||||
* @param data
|
||||
* Data to unprotect.
|
||||
* @param flags
|
||||
* Optional flags, eg. CRYPTPROTECT_UI_FORBIDDEN.
|
||||
* @return
|
||||
* Unprotected blob of data.
|
||||
*/
|
||||
public static byte[] cryptUnprotectData(byte[] data, int flags) {
|
||||
return cryptUnprotectData(data, null, flags, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unprotect a blob of data.
|
||||
* @param data
|
||||
* Data to unprotect.
|
||||
* @param entropy
|
||||
* Optional entropy.
|
||||
* @param flags
|
||||
* Optional flags.
|
||||
* @param prompt
|
||||
* Optional prompt structure.
|
||||
* @return
|
||||
* Unprotected blob of data.
|
||||
*/
|
||||
public static byte[] cryptUnprotectData(byte[] data, byte[] entropy, int flags,
|
||||
CRYPTPROTECT_PROMPTSTRUCT prompt) {
|
||||
DATA_BLOB pDataIn = new DATA_BLOB(data);
|
||||
DATA_BLOB pDataUnprotected = new DATA_BLOB();
|
||||
DATA_BLOB pEntropy = (entropy == null) ? null : new DATA_BLOB(entropy);
|
||||
PointerByReference pDescription = new PointerByReference();
|
||||
try {
|
||||
if (! Crypt32.INSTANCE.CryptUnprotectData(pDataIn, pDescription,
|
||||
pEntropy, null, prompt, flags, pDataUnprotected)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return pDataUnprotected.getData();
|
||||
} finally {
|
||||
if (pDataUnprotected.pbData != null) {
|
||||
Kernel32.INSTANCE.LocalFree(pDataUnprotected.pbData);
|
||||
}
|
||||
if (pDescription.getValue() != null) {
|
||||
Kernel32.INSTANCE.LocalFree(pDescription.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
/* 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 com.sun.jna.NativeLong;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.win32.Guid.GUID;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
|
||||
/**
|
||||
* Ported from DsGetDC.h.
|
||||
* Windows SDK 6.0a
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface DsGetDC extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* The DOMAIN_CONTROLLER_INFO structure is used with the DsGetDcName
|
||||
* function to receive data about a domain controller.
|
||||
*/
|
||||
public static class DOMAIN_CONTROLLER_INFO extends Structure {
|
||||
|
||||
public static class ByReference extends DOMAIN_CONTROLLER_INFO implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public DOMAIN_CONTROLLER_INFO() {
|
||||
|
||||
}
|
||||
|
||||
public DOMAIN_CONTROLLER_INFO(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the computer name
|
||||
* of the discovered domain controller. The returned computer name is
|
||||
* prefixed with "\\". The DNS-style name, for example, "\\phoenix.fabrikam.com",
|
||||
* is returned, if available. If the DNS-style name is not available, the
|
||||
* flat-style name (for example, "\\phoenix") is returned. This example would apply
|
||||
* if the domain is a Windows NT 4.0 domain or if the domain does not support the
|
||||
* IP family of protocols.
|
||||
*/
|
||||
public WString DomainControllerName;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the address of the discovered
|
||||
* domain controller. The address is prefixed with "\\". This WString is one of the
|
||||
* types defined by the DomainControllerAddressType member.
|
||||
*/
|
||||
public WString DomainControllerAddress;
|
||||
/**
|
||||
* Indicates the type of WString that is contained in the DomainControllerAddress member.
|
||||
*/
|
||||
public int DomainControllerAddressType;
|
||||
/**
|
||||
* The GUID of the domain. This member is zero if the domain controller does not have
|
||||
* a Domain GUID; for example, the domain controller is not a Windows 2000 domain
|
||||
* controller.
|
||||
*/
|
||||
public GUID DomainGuid;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the domain. The
|
||||
* DNS-style name, for example, "fabrikam.com", is returned if available. Otherwise,
|
||||
* the flat-style name, for example, "fabrikam", is returned. This name may be different
|
||||
* than the requested domain name if the domain has been renamed.
|
||||
*/
|
||||
public WString DomainName;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the domain at the root
|
||||
* of the DS tree. The DNS-style name, for example, "fabrikam.com", is returned if
|
||||
* available. Otherwise, the flat-style name, for example, "fabrikam" is returned.
|
||||
*/
|
||||
public WString DnsForestName;
|
||||
/**
|
||||
* Contains a set of flags that describe the domain controller.
|
||||
*/
|
||||
public int Flags;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the site where the
|
||||
* domain controller is located. This member may be NULL if the domain controller is
|
||||
* not in a site; for example, the domain controller is a Windows NT 4.0 domain
|
||||
* controller.
|
||||
*/
|
||||
public WString DcSiteName;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the site that the
|
||||
* computer belongs to. The computer is specified in the ComputerName parameter passed
|
||||
* to DsGetDcName. This member may be NULL if the site that contains the computer
|
||||
* cannot be found; for example, if the DS administrator has not associated the
|
||||
* subnet that the computer is in with a valid site.
|
||||
*/
|
||||
public WString ClientSiteName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to DOMAIN_CONTROLLER_INFO.
|
||||
*/
|
||||
public static class PDOMAIN_CONTROLLER_INFO extends Structure {
|
||||
|
||||
public static class ByReference extends PDOMAIN_CONTROLLER_INFO implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public DOMAIN_CONTROLLER_INFO.ByReference dci;
|
||||
}
|
||||
|
||||
/**
|
||||
* Domain is a member of the forest.
|
||||
*/
|
||||
public static final int DS_DOMAIN_IN_FOREST = 0x0001;
|
||||
/**
|
||||
* Domain is directly trusted.
|
||||
*/
|
||||
public static final int DS_DOMAIN_DIRECT_OUTBOUND = 0x0002;
|
||||
/**
|
||||
* Domain is root of a tree in the forest.
|
||||
*/
|
||||
public static final int DS_DOMAIN_TREE_ROOT = 0x0004;
|
||||
/**
|
||||
* Domain is the primary domain of queried server.
|
||||
*/
|
||||
public static final int DS_DOMAIN_PRIMARY = 0x0008;
|
||||
/**
|
||||
* Primary domain is running in native mode.
|
||||
*/
|
||||
public static final int DS_DOMAIN_NATIVE_MODE = 0x0010;
|
||||
/**
|
||||
* Domain is directly trusting.
|
||||
*/
|
||||
public static final int DS_DOMAIN_DIRECT_INBOUND = 0x0020;
|
||||
/**
|
||||
* Valid domain flags.
|
||||
*/
|
||||
public static final int DS_DOMAIN_VALID_FLAGS =
|
||||
DS_DOMAIN_IN_FOREST |
|
||||
DS_DOMAIN_DIRECT_OUTBOUND |
|
||||
DS_DOMAIN_TREE_ROOT |
|
||||
DS_DOMAIN_PRIMARY |
|
||||
DS_DOMAIN_NATIVE_MODE |
|
||||
DS_DOMAIN_DIRECT_INBOUND;
|
||||
|
||||
/**
|
||||
* The DS_DOMAIN_TRUSTS structure is used with the DsEnumerateDomainTrusts function to
|
||||
* contain trust data for a domain.
|
||||
*/
|
||||
public static class DS_DOMAIN_TRUSTS extends Structure {
|
||||
|
||||
public static class ByReference extends DS_DOMAIN_TRUSTS implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated string that contains the NetBIOS name of the domain.
|
||||
*/
|
||||
public WString NetbiosDomainName;
|
||||
/**
|
||||
* Pointer to a null-terminated string that contains the DNS name of the domain. This member may be NULL.
|
||||
*/
|
||||
public WString DnsDomainName;
|
||||
/**
|
||||
* Contains a set of flags that specify more data about the domain trust.
|
||||
*/
|
||||
public NativeLong Flags;
|
||||
/**
|
||||
* Contains the index in the Domains array returned by the DsEnumerateDomainTrusts function that
|
||||
* corresponds to the parent domain of the domain represented by this structure.
|
||||
*/
|
||||
public NativeLong ParentIndex;
|
||||
/**
|
||||
* Contains a value that indicates the type of trust represented by this structure.
|
||||
*/
|
||||
public NativeLong TrustType;
|
||||
/**
|
||||
* Contains a value that indicates the attributes of the trust represented by this structure.
|
||||
*/
|
||||
public NativeLong TrustAttributes;
|
||||
|
||||
/**
|
||||
* Contains the security identifier of the domain represented by this structure.
|
||||
*/
|
||||
public PSID.ByReference DomainSid;
|
||||
|
||||
/**
|
||||
* Contains the GUID of the domain represented by this structure.
|
||||
*/
|
||||
public GUID DomainGuid;
|
||||
};
|
||||
|
||||
/**
|
||||
* A pointer to an array of DS_DOMAIN_TRUSTS.
|
||||
*/
|
||||
public static class PDS_DOMAIN_TRUSTS extends Structure {
|
||||
public static class ByReference extends PDS_DOMAIN_TRUSTS implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public DS_DOMAIN_TRUSTS.ByReference t;
|
||||
|
||||
/**
|
||||
* Returns domain trusts.
|
||||
* @param count
|
||||
* Number of domain trusts.
|
||||
* @return
|
||||
* An array of domain trusts.
|
||||
*/
|
||||
public DS_DOMAIN_TRUSTS[] getTrusts(int count) {
|
||||
return (DS_DOMAIN_TRUSTS[]) t.toArray(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
/* 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.
|
||||
* <p/>
|
||||
* 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.platform.win32.WinDef.HBITMAP;
|
||||
import com.sun.jna.platform.win32.WinDef.HDC;
|
||||
import com.sun.jna.platform.win32.WinDef.HRGN;
|
||||
import com.sun.jna.platform.win32.WinGDI.BITMAPINFO;
|
||||
import com.sun.jna.platform.win32.WinGDI.BITMAPINFOHEADER;
|
||||
import com.sun.jna.platform.win32.WinGDI.RGNDATA;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/** Definition (incomplete) of <code>gdi32.dll</code>. */
|
||||
public interface GDI32 extends StdCallLibrary {
|
||||
|
||||
GDI32 INSTANCE = (GDI32) Native.loadLibrary("gdi32", GDI32.class,
|
||||
W32APIOptions.DEFAULT_OPTIONS);
|
||||
|
||||
/**
|
||||
* The ExtCreateRegion function creates a region from the specified region and transformation data.
|
||||
* @param lpXform
|
||||
* Pointer to an XFORM structure that defines the transformation to be performed on the region. If this pointer is NULL,
|
||||
* the identity transformation is used.
|
||||
* @param nCount
|
||||
* Specifies the number of bytes pointed to by lpRgnData.
|
||||
* @param lpRgnData
|
||||
* Pointer to a RGNDATA structure that contains the region data in logical units.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the value of the region.
|
||||
* If the function fails, the return value is NULL.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
public HRGN ExtCreateRegion(Pointer lpXform, int nCount, RGNDATA lpRgnData);
|
||||
|
||||
/**
|
||||
* The CombineRgn function combines two regions and stores the result in a third region.
|
||||
* The two regions are combined according to the specified mode.
|
||||
* @param hrgnDest
|
||||
* Handle to a new region with dimensions defined by combining two other regions.
|
||||
* @param hrgnSrc1
|
||||
* Handle to the first of two regions to be combined.
|
||||
* @param hrgnSrc2
|
||||
* Handle to the second of two regions to be combined.
|
||||
* @param fnCombineMode
|
||||
* Specifies a mode indicating how the two regions will be combined.
|
||||
* @return
|
||||
* The return value specifies the type of the resulting region.
|
||||
*/
|
||||
int CombineRgn(HRGN hrgnDest, HRGN hrgnSrc1, HRGN hrgnSrc2,
|
||||
int fnCombineMode);
|
||||
|
||||
/**
|
||||
* The CreateRectRgn function creates a rectangular region.
|
||||
* @param nLeftRect
|
||||
* Specifies the x-coordinate of the upper-left corner of the region in logical units.
|
||||
* @param nTopRect
|
||||
* Specifies the y-coordinate of the upper-left corner of the region in logical units.
|
||||
* @param nRightRect
|
||||
* Specifies the x-coordinate of the lower-right corner of the region in logical units.
|
||||
* @param nBottomRect
|
||||
* Specifies the y-coordinate of the lower-right corner of the region in logical units.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the handle to the region.
|
||||
* If the function fails, the return value is NULL.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HRGN CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect,
|
||||
int nBottomRect);
|
||||
|
||||
/**
|
||||
* The CreateRoundRectRgn function creates a rectangular region with rounded corners.
|
||||
* @param nLeftRect
|
||||
* Specifies the x-coordinate of the upper-left corner of the region in logical units.
|
||||
* @param nTopRect
|
||||
* Specifies the y-coordinate of the upper-left corner of the region in logical units.
|
||||
* @param nRightRect
|
||||
* Specifies the x-coordinate of the lower-right corner of the region in logical units.
|
||||
* @param nBottomRect
|
||||
* Specifies the y-coordinate of the lower-right corner of the region in logical units.
|
||||
* @param nWidthEllipse
|
||||
* Specifies the width of the ellipse used to create the rounded corners in logical units.
|
||||
* @param nHeightEllipse
|
||||
* Specifies the height of the ellipse used to create the rounded corners in logical units.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the handle to the region.
|
||||
* If the function fails, the return value is NULL.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HRGN CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect,
|
||||
int nBottomRect, int nWidthEllipse, int nHeightEllipse);
|
||||
|
||||
/**
|
||||
* The CreatePolyPolygonRgn function creates a region consisting of a series
|
||||
* of polygons. The polygons can overlap.
|
||||
* @param lppt
|
||||
* Pointer to an array of POINT structures that define the vertices of the polygons in logical units.
|
||||
* The polygons are specified consecutively. Each polygon is presumed closed and each vertex is
|
||||
* specified only once.
|
||||
* @param lpPolyCounts
|
||||
* Pointer to an array of integers, each of which specifies the number of points in one of the polygons
|
||||
* in the array pointed to by lppt.
|
||||
* @param nCount
|
||||
* Specifies the total number of integers in the array pointed to by lpPolyCounts.
|
||||
* @param fnPolyFillMode
|
||||
* Specifies the fill mode used to determine which pixels are in the region.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the handle to the region.
|
||||
* If the function fails, the return value is zero.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HRGN CreatePolyPolygonRgn(WinUser.POINT[] lppt, int[] lpPolyCounts,
|
||||
int nCount, int fnPolyFillMode);
|
||||
|
||||
/**
|
||||
* The SetRectRgn function converts a region into a rectangular region with the specified coordinates.
|
||||
* @param hrgn
|
||||
* Handle to the region.
|
||||
* @param nLeftRect
|
||||
* Specifies the x-coordinate of the upper-left corner of the rectangular region in logical units.
|
||||
* @param nTopRect
|
||||
* Specifies the y-coordinate of the upper-left corner of the rectangular region in logical units.
|
||||
* @param nRightRect
|
||||
* Specifies the x-coordinate of the lower-right corner of the rectangular region in logical units.
|
||||
* @param nBottomRect
|
||||
* Specifies the y-coordinate of the lower-right corner of the rectangular region in logical units.
|
||||
* @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 SetRectRgn(HRGN hrgn, int nLeftRect, int nTopRect, int nRightRect,
|
||||
int nBottomRect);
|
||||
|
||||
/**
|
||||
* The SetPixel function sets the pixel at the specified coordinates to the specified color.
|
||||
* @param hDC
|
||||
* Handle to the device context.
|
||||
* @param x
|
||||
* Specifies the x-coordinate, in logical units, of the point to be set.
|
||||
* @param y
|
||||
* Specifies the y-coordinate, in logical units, of the point to be set.
|
||||
* @param crColor
|
||||
* Specifies the color to be used to paint the point. To create a COLORREF color value, use the RGB macro.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the RGB value that the function sets the pixel to.
|
||||
* This value may differ from the color specified by crColor; that occurs when an exact match for the
|
||||
* specified color cannot be found. If the function fails, the return value is 1. To get extended error
|
||||
* information, call GetLastError. This can be the following value.
|
||||
*/
|
||||
int SetPixel(HDC hDC, int x, int y, int crColor);
|
||||
|
||||
/**
|
||||
* The CreateCompatibleDC function creates a memory device context (DC) compatible with the specified device.
|
||||
* @param hDC
|
||||
* Handle to an existing DC. If this handle is NULL, the function creates a memory DC compatible with the
|
||||
* application's current screen.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the handle to a memory DC.
|
||||
* If the function fails, the return value is NULL.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HDC CreateCompatibleDC(HDC hDC);
|
||||
|
||||
/**
|
||||
* The DeleteDC function deletes the specified device context (DC).
|
||||
* @param hDC
|
||||
* Handle to the device context.
|
||||
* @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 DeleteDC(HDC hDC);
|
||||
|
||||
/**
|
||||
* The CreateDIBitmap function creates a compatible bitmap (DDB) from a DIB and, optionally,
|
||||
* sets the bitmap bits.
|
||||
* @param hDC
|
||||
* Handle to a device context.
|
||||
* @param lpbmih
|
||||
* Pointer to a bitmap information header structure, which may be one of those shown in the following table.
|
||||
* @param fdwInit
|
||||
* Specifies how the system initializes the bitmap bits.
|
||||
* @param lpbInit
|
||||
* Pointer to an array of bytes containing the initial bitmap data.
|
||||
* @param lpbmi
|
||||
* Pointer to a BITMAPINFO structure that describes the dimensions and color format of
|
||||
* the array pointed to by the lpbInit parameter.
|
||||
* @param fuUsage
|
||||
* Specifies whether the bmiColors member of the BITMAPINFO structure was initialized and, if so,
|
||||
* whether bmiColors contains explicit red, green, blue (RGB) values or palette indexes. The
|
||||
* fuUsage parameter must be one of the following values.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a handle to the compatible bitmap.
|
||||
* If the function fails, the return value is NULL.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HBITMAP CreateDIBitmap(HDC hDC, BITMAPINFOHEADER lpbmih, int fdwInit,
|
||||
Pointer lpbInit, BITMAPINFO lpbmi, int fuUsage);
|
||||
|
||||
/**
|
||||
* The CreateDIBSection function creates a DIB that applications can write to directly.
|
||||
* The function gives you a pointer to the location of the bitmap bit values. You can supply
|
||||
* a handle to a file-mapping object that the function will use to create the bitmap, or you
|
||||
* can let the system allocate the memory for the bitmap.
|
||||
* @param hDC
|
||||
* Handle to a device context. If the value of iUsage is DIB_PAL_COLORS, the function uses this
|
||||
* device context's logical palette to initialize the DIB colors.
|
||||
* @param pbmi
|
||||
* Pointer to a BITMAPINFO structure that specifies various attributes of the DIB, including
|
||||
* the bitmap dimensions and colors.
|
||||
* @param iUsage
|
||||
* Specifies the type of data contained in the bmiColors array member of the BITMAPINFO structure
|
||||
* pointed to by pbmi (either logical palette indexes or literal RGB values).
|
||||
* @param ppvBits
|
||||
* Pointer to a variable that receives a pointer to the location of the DIB bit values.
|
||||
* @param hSection
|
||||
* Handle to a file-mapping object that the function will use to create the DIB. This parameter can be NULL.
|
||||
* @param dwOffset
|
||||
* Specifies the offset from the beginning of the file-mapping object referenced by hSection where storage
|
||||
* for the bitmap bit values is to begin.
|
||||
* @return
|
||||
* Specifies the offset from the beginning of the file-mapping object referenced by hSection where storage
|
||||
* for the bitmap bit values is to begin.
|
||||
*/
|
||||
HBITMAP CreateDIBSection(HDC hDC, BITMAPINFO pbmi, int iUsage,
|
||||
PointerByReference ppvBits, Pointer hSection, int dwOffset);
|
||||
|
||||
/**
|
||||
* The CreateCompatibleBitmap function creates a bitmap compatible with the device that is
|
||||
* associated with the specified device context.
|
||||
* @param hDC
|
||||
* Handle to a device context.
|
||||
* @param width
|
||||
* Specifies the bitmap width, in pixels.
|
||||
* @param height
|
||||
* Specifies the bitmap height, in pixels.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a handle to the compatible bitmap (DDB).
|
||||
* If the function fails, the return value is NULL.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HBITMAP CreateCompatibleBitmap(HDC hDC, int width, int height);
|
||||
|
||||
/**
|
||||
* The SelectObject function selects an object into the specified device context (DC).
|
||||
* The new object replaces the previous object of the same type.
|
||||
* @param hDC
|
||||
* Handle to the DC.
|
||||
* @param hGDIObj
|
||||
* Handle to the object to be selected.
|
||||
* @return
|
||||
* If the selected object is not a region and the function succeeds, the return value
|
||||
* is a handle to the object being replaced. If the selected object is a region and the
|
||||
* function succeeds, the return value is one of the REGION values.
|
||||
*/
|
||||
HANDLE SelectObject(HDC hDC, HANDLE hGDIObj);
|
||||
|
||||
/**
|
||||
* The DeleteObject function deletes a logical pen, brush, font, bitmap, region, or palette,
|
||||
* freeing all system resources associated with the object. After the object is deleted, the
|
||||
* specified handle is no longer valid.
|
||||
* @param hObject
|
||||
* Handle to a logical pen, brush, font, bitmap, region, or palette.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
* If the specified handle is not valid or is currently selected into a DC, the return value is zero.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
boolean DeleteObject(HANDLE hObject);
|
||||
|
||||
/** The GetDeviceCaps function retrieves device-specific information for
|
||||
* the specified device.
|
||||
* @param hdc A handle to the DC.
|
||||
* @param nIndex The item to be returned.
|
||||
* @return
|
||||
* The return value specifies the value of the desired item. When
|
||||
* <i>nIndex</i> is <code>BITSPIXEL</code> and the device has 15bpp or
|
||||
* 16bpp, the return value is 16.
|
||||
*/
|
||||
int GetDeviceCaps(HDC hdc, int nIndex);
|
||||
|
||||
/** The GetDIBits function retrieves the bits fo the specified compatible
|
||||
* bitmap and copies them into a buffer as a DIB using the specified
|
||||
* format.
|
||||
* @param hdc A handle to the device context.
|
||||
* @param hbmp A handle to the bitmap. This must be a compatible bitmap
|
||||
* (DDB).
|
||||
* @param uStartScan The first scan line to retrieve
|
||||
* @param cScanLines The number of scan lines to retrieve.
|
||||
* @param lpvBits A pointer to a buffer to receive the bitmap data. If
|
||||
* this parameter is <code>null</code>, the function passes the dimensions
|
||||
* and format of the bitmap to the {@link BITMAPINFO} structure pointed to
|
||||
* by the <i>lpbi</i> parameter.
|
||||
* @param lpbi A pointer to a {@link BITMAPINFO} structure that specifies
|
||||
* the desired format for the DIB data.
|
||||
* @param uUsage The format of the bmiColors member of the {@link
|
||||
* BITMAPINFO} structure.
|
||||
*/
|
||||
int GetDIBits(HDC hdc, HBITMAP hbmp, int uStartScan, int cScanLines, Pointer lpvBits, BITMAPINFO lpbi, int uUsage);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/* 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 com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from Guid.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Guid extends StdCallLibrary {
|
||||
|
||||
public static class GUID extends Structure {
|
||||
|
||||
public static class ByReference extends GUID implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public GUID() {
|
||||
|
||||
}
|
||||
|
||||
public GUID(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public int Data1;
|
||||
public short Data2;
|
||||
public short Data3;
|
||||
public byte[] Data4 = new byte[8];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,848 @@
|
||||
/* 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.
|
||||
* <p/>
|
||||
* 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.nio.Buffer;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.WinBase.MEMORYSTATUSEX;
|
||||
import com.sun.jna.platform.win32.WinBase.SYSTEM_INFO;
|
||||
import com.sun.jna.platform.win32.WinDef.DWORD;
|
||||
import com.sun.jna.platform.win32.WinDef.HMODULE;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.LARGE_INTEGER;
|
||||
import com.sun.jna.platform.win32.WinNT.OSVERSIONINFO;
|
||||
import com.sun.jna.platform.win32.WinNT.OSVERSIONINFOEX;
|
||||
import com.sun.jna.ptr.ByReference;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/** Definition (incomplete) of <code>kernel32.dll</code>. */
|
||||
public interface Kernel32 extends StdCallLibrary {
|
||||
|
||||
Kernel32 INSTANCE = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class,
|
||||
W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* Frees the specified local memory object and invalidates its handle.
|
||||
* @param hLocal
|
||||
* A handle to the local memory object.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NULL.
|
||||
* If the function fails, the return value is equal to a handle to the local memory object.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
Pointer LocalFree(Pointer hLocal);
|
||||
|
||||
/**
|
||||
* Frees the specified global memory object and invalidates its handle.
|
||||
* @param hGlobal
|
||||
* A handle to the global memory object.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NULL
|
||||
* If the function fails, the return value is equal to a handle to the global memory object.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
Pointer GlobalFree(Pointer hGlobal);
|
||||
|
||||
/**
|
||||
* The GetModuleHandle function retrieves a module handle for the specified module
|
||||
* if the file has been mapped into the address space of the calling process.
|
||||
* @param name
|
||||
* Pointer to a null-terminated string that contains the name of the module
|
||||
* (either a .dll or .exe file).
|
||||
* @return
|
||||
* If the function succeeds, the return value is a handle to the specified module.
|
||||
* If the function fails, the return value is NULL. To get extended error
|
||||
* information, call GetLastError.
|
||||
*/
|
||||
HMODULE GetModuleHandle(String name);
|
||||
|
||||
/**
|
||||
* The GetSystemTime function retrieves the current system date and time.
|
||||
* The system time is expressed in Coordinated Universal Time (UTC).
|
||||
* @param lpSystemTime
|
||||
* Pointer to a SYSTEMTIME structure to receive the current system date and time.
|
||||
*/
|
||||
void GetSystemTime(WinBase.SYSTEMTIME lpSystemTime);
|
||||
|
||||
/**
|
||||
* The GetCurrentThreadId function retrieves the thread identifier of the calling thread.
|
||||
* @return The return value is the thread identifier of the calling thread.
|
||||
*/
|
||||
int GetCurrentThreadId();
|
||||
|
||||
/**
|
||||
* The GetCurrentThread function retrieves a pseudo handle for the current thread.
|
||||
* @return The return value is a pseudo handle for the current thread.
|
||||
*/
|
||||
HANDLE GetCurrentThread();
|
||||
|
||||
/**
|
||||
* This function returns the process identifier of the calling process.
|
||||
* @return The return value is the process identifier of the calling process.
|
||||
*/
|
||||
int GetCurrentProcessId();
|
||||
|
||||
/**
|
||||
* This function returns a pseudohandle for the current process.
|
||||
* @return The return value is a pseudohandle to the current process.
|
||||
*/
|
||||
HANDLE GetCurrentProcess();
|
||||
|
||||
/**
|
||||
* The GetProcessId function retrieves the process identifier of the
|
||||
* specified process.
|
||||
* @param process
|
||||
* Handle to the process. The handle must have the PROCESS_QUERY_INFORMATION access right.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the process identifier of the
|
||||
* specified process. If the function fails, the return value is zero. To get
|
||||
* extended error information, call GetLastError.
|
||||
*/
|
||||
int GetProcessId(HANDLE process);
|
||||
|
||||
/**
|
||||
* The GetProcessVersion function retrieves the major and minor version numbers of the system
|
||||
* on which the specified process expects to run.
|
||||
* @param processId
|
||||
* Process identifier of the process of interest. A value of zero specifies the
|
||||
* calling process.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the version of the system on
|
||||
* which the process expects to run. The high word of the return value contains
|
||||
* the major version number. The low word of the return value contains the minor
|
||||
* version number. If the function fails, the return value is zero. To get extended
|
||||
* error information, call GetLastError. The function fails if ProcessId is an
|
||||
* invalid value.
|
||||
*/
|
||||
int GetProcessVersion(int processId);
|
||||
|
||||
/**
|
||||
* The GetLastError function retrieves the calling thread's last-error code value.
|
||||
* The last-error code is maintained on a per-thread basis. Multiple threads do not
|
||||
* overwrite each other's last-error code.
|
||||
* @return
|
||||
* The return value is the calling thread's last-error code value.
|
||||
*/
|
||||
int GetLastError();
|
||||
|
||||
/**
|
||||
* The SetLastError function sets the last-error code for the calling thread.
|
||||
* @param dwErrCode
|
||||
* Last-error code for the thread.
|
||||
*/
|
||||
void SetLastError(int dwErrCode);
|
||||
|
||||
/**
|
||||
* The GetDriveType function determines whether a disk drive is a removable,
|
||||
* fixed, CD-ROM, RAM disk, or network drive.
|
||||
* @param lpRootPathName
|
||||
* Pointer to a null-terminated string that specifies the root directory of
|
||||
* the disk to return information about. A trailing backslash is required.
|
||||
* If this parameter is NULL, the function uses the root of the current directory.
|
||||
* @return
|
||||
* The return value specifies the type of drive.
|
||||
*/
|
||||
int GetDriveType(String lpRootPathName);
|
||||
|
||||
/**
|
||||
* The FormatMessage function formats a message string. The function requires a
|
||||
* message definition as input. The message definition can come from a buffer
|
||||
* passed into the function. It can come from a message table resource in an
|
||||
* already-loaded module. Or the caller can ask the function to search the
|
||||
* system's message table resource(s) for the message definition. The function
|
||||
* finds the message definition in a message table resource based on a message
|
||||
* identifier and a language identifier. The function copies the formatted message
|
||||
* text to an output buffer, processing any embedded insert sequences if requested.
|
||||
* @param dwFlags
|
||||
* Formatting options, and how to interpret the lpSource parameter. The low-order
|
||||
* byte of dwFlags specifies how the function handles line breaks in the output
|
||||
* buffer. The low-order byte can also specify the maximum width of a formatted
|
||||
* output line.
|
||||
* @param lpSource
|
||||
* Location of the message definition.
|
||||
* @param dwMessageId
|
||||
* Message identifier for the requested message.
|
||||
* @param dwLanguageId
|
||||
* Language identifier for the requested message.
|
||||
* @param lpBuffer
|
||||
* Pointer to a buffer that receives the null-terminated string that specifies the
|
||||
* formatted message.
|
||||
* @param nSize
|
||||
* If the FORMAT_MESSAGE_ALLOCATE_BUFFER flag is not set, this parameter specifies
|
||||
* the size of the output buffer, in TCHARs. If FORMAT_MESSAGE_ALLOCATE_BUFFER is
|
||||
* set, this parameter specifies the minimum number of TCHARs to allocate for an
|
||||
* output buffer.
|
||||
* @param va_list
|
||||
* Pointer to an array of values that are used as insert values in the formatted message.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the number of TCHARs stored in
|
||||
* the output buffer, excluding the terminating null character. If the function
|
||||
* fails, the return value is zero. To get extended error information, call
|
||||
* GetLastError.
|
||||
*/
|
||||
int FormatMessage(int dwFlags, Pointer lpSource, int dwMessageId,
|
||||
int dwLanguageId, PointerByReference lpBuffer,
|
||||
int nSize, Pointer va_list);
|
||||
|
||||
/**
|
||||
* The FormatMessage function formats a message string. The function requires a
|
||||
* message definition as input. The message definition can come from a buffer
|
||||
* passed into the function. It can come from a message table resource in an
|
||||
* already-loaded module. Or the caller can ask the function to search the
|
||||
* system's message table resource(s) for the message definition. The function
|
||||
* finds the message definition in a message table resource based on a message
|
||||
* identifier and a language identifier. The function copies the formatted message
|
||||
* text to an output buffer, processing any embedded insert sequences if requested.
|
||||
* @param dwFlags
|
||||
* Formatting options, and how to interpret the lpSource parameter. The low-order
|
||||
* byte of dwFlags specifies how the function handles line breaks in the output
|
||||
* buffer. The low-order byte can also specify the maximum width of a formatted
|
||||
* output line.
|
||||
* @param lpSource
|
||||
* Location of the message definition.
|
||||
* @param dwMessageId
|
||||
* Message identifier for the requested message.
|
||||
* @param dwLanguageId
|
||||
* Language identifier for the requested message.
|
||||
* @param lpBuffer
|
||||
* Pointer to a buffer that receives the null-terminated string that specifies the
|
||||
* formatted message.
|
||||
* @param nSize
|
||||
* If the FORMAT_MESSAGE_ALLOCATE_BUFFER flag is not set, this parameter specifies
|
||||
* the size of the output buffer, in TCHARs. If FORMAT_MESSAGE_ALLOCATE_BUFFER is
|
||||
* set, this parameter specifies the minimum number of TCHARs to allocate for an
|
||||
* output buffer.
|
||||
* @param va_list
|
||||
* Pointer to an array of values that are used as insert values in the formatted message.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the number of TCHARs stored in
|
||||
* the output buffer, excluding the terminating null character. If the function
|
||||
* fails, the return value is zero. To get extended error information, call
|
||||
* GetLastError.
|
||||
*/
|
||||
int FormatMessage(int dwFlags, Pointer lpSource, int dwMessageId,
|
||||
int dwLanguageId, Buffer lpBuffer,
|
||||
int nSize, Pointer va_list);
|
||||
|
||||
/**
|
||||
* The CreateFile function creates or opens a file, file stream, directory, physical
|
||||
* disk, volume, console buffer, tape drive, communications resource, mailslot, or
|
||||
* named pipe. The function returns a handle that can be used to access an object.
|
||||
* @param lpFileName
|
||||
* A pointer to a null-terminated string that specifies the name of an object to create or open.
|
||||
* @param dwDesiredAccess
|
||||
* The access to the object, which can be read, write, or both.
|
||||
* @param dwShareMode
|
||||
* The sharing mode of an object, which can be read, write, both, or none.
|
||||
* @param lpSecurityAttributes
|
||||
* A pointer to a SECURITY_ATTRIBUTES structure that determines whether or not
|
||||
* the returned handle can be inherited by child processes. If lpSecurityAttributes
|
||||
* is NULL, the handle cannot be inherited.
|
||||
* @param dwCreationDisposition
|
||||
* An action to take on files that exist and do not exist.
|
||||
* @param dwFlagsAndAttributes
|
||||
* The file attributes and flags.
|
||||
* @param hTemplateFile
|
||||
* Handle to a template file with the GENERIC_READ access right. The template file
|
||||
* supplies file attributes and extended attributes for the file that is being
|
||||
* created. This parameter can be NULL.
|
||||
* @return
|
||||
* If the function succeeds, the return value is an open handle to a specified file.
|
||||
* If a specified file exists before the function call and dwCreationDisposition is
|
||||
* CREATE_ALWAYS or OPEN_ALWAYS, a call to GetLastError returns ERROR_ALREADY_EXISTS,
|
||||
* even when the function succeeds. If a file does not exist before the call,
|
||||
* GetLastError returns 0 (zero). If the function fails, the return value is
|
||||
* INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
|
||||
*/
|
||||
HANDLE CreateFile(String lpFileName, int dwDesiredAccess, int dwShareMode,
|
||||
WinNT.SECURITY_ATTRIBUTES lpSecurityAttributes, int dwCreationDisposition,
|
||||
int dwFlagsAndAttributes, HANDLE hTemplateFile);
|
||||
|
||||
|
||||
/**
|
||||
* The CreateDirectory function creates a new directory. If the underlying file
|
||||
* system supports security on files and directories, the function applies a
|
||||
* specified security descriptor to the new directory.
|
||||
* @param lpPathName
|
||||
* Pointer to a null-terminated string that specifies the path of the directory
|
||||
* to be created.
|
||||
* @param lpSecurityAttributes
|
||||
* Pointer to a SECURITY_ATTRIBUTES structure. The lpSecurityDescriptor member
|
||||
* of the structure specifies a security descriptor for the new directory. If
|
||||
* lpSecurityAttributes is NULL, the directory gets a default security descriptor.
|
||||
* @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 CreateDirectory(String lpPathName,
|
||||
WinNT.SECURITY_ATTRIBUTES lpSecurityAttributes);
|
||||
|
||||
/**
|
||||
* Creates an input/output (I/O) completion port and associates it with a specified
|
||||
* file handle, or creates an I/O completion port that is not yet associated with a
|
||||
* file handle, allowing association at a later time.
|
||||
* @param FileHandle
|
||||
* An open file handle or INVALID_HANDLE_VALUE.
|
||||
* @param ExistingCompletionPort
|
||||
* A handle to an existing I/O completion port or NULL.
|
||||
* @param CompletionKey
|
||||
* The per-handle user-defined completion key that is included in every I/O completion
|
||||
* packet for the specified file handle.
|
||||
* @param NumberOfConcurrentThreads
|
||||
* The maximum number of threads that the operating system can allow to concurrently
|
||||
* process I/O completion packets for the I/O completion port.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the handle to an I/O completion port:
|
||||
* If the ExistingCompletionPort parameter was NULL, the return value is a new handle.
|
||||
* If the ExistingCompletionPort parameter was a valid I/O completion port handle, the return value is that same handle.
|
||||
* If the FileHandle parameter was a valid handle, that file handle is now associated with the returned I/O completion port.
|
||||
* If the function fails, the return value is NULL. To get extended error information, call the GetLastError function.
|
||||
*/
|
||||
HANDLE CreateIoCompletionPort(HANDLE FileHandle, HANDLE ExistingCompletionPort,
|
||||
Pointer CompletionKey, int NumberOfConcurrentThreads);
|
||||
|
||||
/**
|
||||
* Attempts to dequeue an I/O completion packet from the specified I/O completion
|
||||
* port. If there is no completion packet queued, the function waits for a pending
|
||||
* I/O operation associated with the completion port to complete.
|
||||
* @param CompletionPort
|
||||
* A handle to the completion port.
|
||||
* @param lpNumberOfBytes
|
||||
* A pointer to a variable that receives the number of bytes transferred during
|
||||
* an I/O operation that has completed.
|
||||
* @param lpCompletionKey
|
||||
* A pointer to a variable that receives the completion key value associated with
|
||||
* the file handle whose I/O operation has completed.
|
||||
* @param lpOverlapped
|
||||
* A pointer to a variable that receives the address of the OVERLAPPED structure
|
||||
* that was specified when the completed I/O operation was started.
|
||||
* @param dwMilliseconds
|
||||
* The number of milliseconds that the caller is willing to wait for a completion
|
||||
* packet to appear at the completion port.
|
||||
* @return
|
||||
* Returns nonzero (TRUE) if successful or zero (FALSE) otherwise.
|
||||
*/
|
||||
boolean GetQueuedCompletionStatus(HANDLE CompletionPort,
|
||||
IntByReference lpNumberOfBytes, ByReference lpCompletionKey,
|
||||
PointerByReference lpOverlapped, int dwMilliseconds);
|
||||
|
||||
/**
|
||||
* Posts an I/O completion packet to an I/O completion port.
|
||||
* @param CompletionPort
|
||||
* A handle to an I/O completion port to which the I/O completion packet is to be posted.
|
||||
* @param dwNumberOfBytesTransferred
|
||||
* The value to be returned through the lpNumberOfBytesTransferred parameter of the GetQueuedCompletionStatus function.
|
||||
* @param dwCompletionKey
|
||||
* The value to be returned through the lpCompletionKey parameter of the GetQueuedCompletionStatus function.
|
||||
* @param lpOverlapped
|
||||
* The value to be returned through the lpOverlapped parameter of the GetQueuedCompletionStatus 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 PostQueuedCompletionStatus(HANDLE CompletionPort,
|
||||
int dwNumberOfBytesTransferred, Pointer dwCompletionKey,
|
||||
WinBase.OVERLAPPED lpOverlapped);
|
||||
|
||||
/**
|
||||
* Waits until the specified object is in the signaled state or the time-out interval elapses.
|
||||
* To enter an alertable wait state, use the WaitForSingleObjectEx function.
|
||||
* To wait for multiple objects, use the WaitForMultipleObjects.
|
||||
* @param hHandle
|
||||
* A handle to the object. For a list of the object types whose handles can be specified, see the following Remarks section.
|
||||
* If this handle is closed while the wait is still pending, the function's behavior is undefined.
|
||||
* The handle must have the SYNCHRONIZE access right. For more information, see Standard Access Rights.
|
||||
* @param dwMilliseconds
|
||||
* The time-out interval, in milliseconds. If a nonzero value is specified, the function waits until the object is signaled or the interval elapses.
|
||||
* If dwMilliseconds is zero, the function does not enter a wait state if the object is not signaled; it always returns immediately.
|
||||
* If dwMilliseconds is INFINITE, the function will return only when the object is signaled.
|
||||
* @return
|
||||
* If the function succeeds, the return value indicates the event that caused the function to return.
|
||||
*/
|
||||
int WaitForSingleObject(HANDLE hHandle, int dwMilliseconds);
|
||||
|
||||
/**
|
||||
* Waits until one or all of the specified objects are in the signaled state or the time-out interval elapses.
|
||||
* To enter an alertable wait state, use the WaitForMultipleObjectsEx function.
|
||||
* @param nCount
|
||||
* The number of object handles in the array pointed to by lpHandles. The maximum number of object handles is MAXIMUM_WAIT_OBJECTS.
|
||||
* @param hHandle
|
||||
* An array of object handles. For a list of the object types whose handles can be specified, see the following Remarks section. The array can contain handles to objects of different types.
|
||||
* It may not contain multiple copies of the same handle.
|
||||
* If one of these handles is closed while the wait is still pending, the function's behavior is undefined.
|
||||
* The handles must have the SYNCHRONIZE access right. For more information, see Standard Access Rights.
|
||||
* @param bWaitAll
|
||||
* If this parameter is TRUE, the function returns when the state of all objects in the lpHandles array is signaled.
|
||||
* If FALSE, the function returns when the state of any one of the objects is set to signaled.
|
||||
* In the latter case, the return value indicates the object whose state caused the function to return.
|
||||
* @param dwMilliseconds
|
||||
* The time-out interval, in milliseconds. If a nonzero value is specified, the function waits until the specified objects are signaled or the interval elapses.
|
||||
* If dwMilliseconds is zero, the function does not enter a wait state if the specified objects are not signaled; it always returns immediately.
|
||||
* If dwMilliseconds is INFINITE, the function will return only when the specified objects are signaled.
|
||||
* @return
|
||||
* If the function succeeds, the return value indicates the event that caused the function to return.
|
||||
*/
|
||||
int WaitForMultipleObjects(int nCount, HANDLE[] hHandle, boolean bWaitAll, int dwMilliseconds);
|
||||
|
||||
/**
|
||||
* The DuplicateHandle function duplicates an object handle.
|
||||
*
|
||||
* @param hSourceProcessHandle
|
||||
* Handle to the process with the handle to duplicate.
|
||||
* The handle must have the PROCESS_DUP_HANDLE access right.
|
||||
* @param hSourceHandle
|
||||
* Handle to duplicate. This is an open object handle that is valid in the
|
||||
* context of the source process.
|
||||
* @param hTargetProcessHandle
|
||||
* Handle to the process that is to receive the duplicated handle.
|
||||
* The handle must have the PROCESS_DUP_HANDLE access right.
|
||||
* @param lpTargetHandle
|
||||
* Pointer to a variable that receives the duplicate handle. This handle value is valid in
|
||||
* the context of the target process. If hSourceHandle is a pseudo handle returned by
|
||||
* GetCurrentProcess or GetCurrentThread, DuplicateHandle converts it to a real handle to
|
||||
* a process or thread, respectively.
|
||||
* @param dwDesiredAccess
|
||||
* Access requested for the new handle.
|
||||
* @param bInheritHandle
|
||||
* Indicates whether the handle is inheritable.
|
||||
* @param dwOptions
|
||||
* Optional actions.
|
||||
* @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 DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle,
|
||||
HANDLE hTargetProcessHandle, HANDLEByReference lpTargetHandle,
|
||||
int dwDesiredAccess, boolean bInheritHandle, int dwOptions);
|
||||
|
||||
/**
|
||||
* The CloseHandle function closes an open object handle.
|
||||
*
|
||||
* @param hObject
|
||||
* Handle to an open object. This parameter can be a pseudo handle or INVALID_HANDLE_VALUE.
|
||||
* @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 CloseHandle(HANDLE hObject);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves information that describes the changes within the specified directory.
|
||||
* The function does not report changes to the specified directory itself.
|
||||
* Note: there's no ReadDirectoryChangesA.
|
||||
* @param directory
|
||||
* A handle to the directory to be monitored. This directory must be opened with the
|
||||
* FILE_LIST_DIRECTORY access right.
|
||||
* @param info
|
||||
* A pointer to the DWORD-aligned formatted buffer in which the read results are to be returned.
|
||||
* @param length
|
||||
* The size of the buffer that is pointed to by the lpBuffer parameter, in bytes.
|
||||
* @param watchSubtree
|
||||
* If this parameter is TRUE, the function monitors the directory tree rooted at the specified
|
||||
* directory. If this parameter is FALSE, the function monitors only the directory specified by
|
||||
* the hDirectory parameter.
|
||||
* @param notifyFilter
|
||||
* The filter criteria that the function checks to determine if the wait operation has completed.
|
||||
* @param bytesReturned
|
||||
* For synchronous calls, this parameter receives the number of bytes transferred into the
|
||||
* lpBuffer parameter. For asynchronous calls, this parameter is undefined. You must use an asynchronous
|
||||
* notification technique to retrieve the number of bytes transferred.
|
||||
* @param overlapped
|
||||
* A pointer to an OVERLAPPED structure that supplies data to be used during asynchronous operation.
|
||||
* Otherwise, this value is NULL. The Offset and OffsetHigh members of this structure are not used.
|
||||
* @param completionRoutine
|
||||
* A pointer to a completion routine to be called when the operation has been completed or canceled and
|
||||
* the calling thread is in an alertable wait state.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero. For synchronous calls, this means that the
|
||||
* operation succeeded. For asynchronous calls, this indicates that the operation was successfully queued.
|
||||
* If the function fails, the return value is zero. To get extended error information, call GetLastError.
|
||||
* If the network redirector or the target file system does not support this operation, the function
|
||||
* fails with ERROR_INVALID_FUNCTION.
|
||||
*/
|
||||
public boolean ReadDirectoryChangesW(HANDLE directory,
|
||||
WinNT.FILE_NOTIFY_INFORMATION info, int length, boolean watchSubtree,
|
||||
int notifyFilter, IntByReference bytesReturned, WinBase.OVERLAPPED overlapped,
|
||||
OVERLAPPED_COMPLETION_ROUTINE completionRoutine);
|
||||
|
||||
/**
|
||||
* Retrieves the short path form of the specified path.
|
||||
* @param lpszLongPath
|
||||
* The path string.
|
||||
* @param lpdzShortPath
|
||||
* A pointer to a buffer to receive the null-terminated short form of the path that lpszLongPath specifies.
|
||||
* @param cchBuffer
|
||||
* The size of the buffer that lpszShortPath points to, in TCHARs.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the length, in TCHARs, of the string that is copied to
|
||||
* lpszShortPath, not including the terminating null character.
|
||||
* If the lpszShortPath buffer is too small to contain the path, the return value is the size of the buffer,
|
||||
* in TCHARs, that is required to hold the path and the terminating null character.
|
||||
* If the function fails for any other reason, the return value is zero. To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
int GetShortPathName(String lpszLongPath, char[] lpdzShortPath, int cchBuffer);
|
||||
|
||||
/**
|
||||
* The LocalAlloc function allocates the specified number of bytes from the heap.
|
||||
* Windows memory management does not provide a separate local heap and global heap.
|
||||
* @param type
|
||||
* Memory allocation attributes. The default is the LMEM_FIXED value.
|
||||
* @param cbInput
|
||||
* Number of bytes to allocate. If this parameter is zero and the uFlags parameter
|
||||
* specifies LMEM_MOVEABLE, the function returns a handle to a memory object that
|
||||
* is marked as discarded.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a handle to the newly allocated memory object.
|
||||
* If the function fails, the return value is NULL. To get extended error information, call GetLastError.
|
||||
*/
|
||||
Pointer LocalAlloc(int type, int cbInput);
|
||||
|
||||
/**
|
||||
* Writes data to the specified file or input/output (I/O) device.
|
||||
* @param hFile
|
||||
* A handle to the file or I/O device (for example, a file, file stream, physical disk, volume,
|
||||
* console buffer, tape drive, socket, communications resource, mailslot, or pipe).
|
||||
* @param lpBuffer
|
||||
* A pointer to the buffer containing the data to be written to the file or device.
|
||||
* @param nNumberOfBytesToWrite
|
||||
* The number of bytes to be written to the file or device.
|
||||
* @param lpNumberOfBytesWritten
|
||||
* A pointer to the variable that receives the number of bytes written when using a synchronous hFile parameter.
|
||||
* @param lpOverlapped
|
||||
* A pointer to an OVERLAPPED structure is required if the hFile parameter was opened with FILE_FLAG_OVERLAPPED,
|
||||
* otherwise this parameter can be NULL.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero (TRUE).
|
||||
* If the function fails, or is completing asynchronously, the return value is zero (FALSE).
|
||||
* To get extended error information, call the GetLastError function.
|
||||
*/
|
||||
boolean WriteFile(HANDLE hFile, byte[] lpBuffer, int nNumberOfBytesToWrite,
|
||||
IntByReference lpNumberOfBytesWritten,
|
||||
WinBase.OVERLAPPED lpOverlapped);
|
||||
|
||||
/**
|
||||
* Creates or opens a named or unnamed event object.
|
||||
* @param lpEventAttributes
|
||||
* A pointer to a SECURITY_ATTRIBUTES structure. If this parameter is NULL,
|
||||
* the handle cannot be inherited by child processes.
|
||||
* @param bManualReset
|
||||
* If this parameter is TRUE, the function creates a manual-reset event object,
|
||||
* which requires the use of the ResetEvent function to set the event state to nonsignaled.
|
||||
* If this parameter is FALSE, the function creates an auto-reset event object, and system
|
||||
* automatically resets the event state to nonsignaled after a single waiting thread has
|
||||
* been released.
|
||||
* @param bInitialState
|
||||
* If this parameter is TRUE, the initial state of the event object is signaled; otherwise,
|
||||
* it is nonsignaled.
|
||||
* @param lpName
|
||||
* The name of the event object. The name is limited to MAX_PATH characters. Name comparison
|
||||
* is case sensitive.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a handle to the event object. If the named event
|
||||
* object existed before the function call, the function returns a handle to the existing object
|
||||
* and GetLastError returns ERROR_ALREADY_EXISTS.
|
||||
* If the function fails, the return value is NULL. To get extended error information, call GetLastError.
|
||||
*/
|
||||
HANDLE CreateEvent(WinNT.SECURITY_ATTRIBUTES lpEventAttributes,
|
||||
boolean bManualReset, boolean bInitialState,
|
||||
String lpName);
|
||||
|
||||
/**
|
||||
* Sets the specified event object to the signaled state.
|
||||
* @param hEvent
|
||||
* A handle to the event object. The CreateEvent or OpenEvent function returns this handle.
|
||||
* @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 SetEvent(HANDLE hEvent);
|
||||
|
||||
/**
|
||||
* Sets the specified event object to the signaled state and then resets it to the nonsignaled
|
||||
* state after releasing the appropriate number of waiting threads.
|
||||
* @param hEvent
|
||||
* A handle to the event object. The CreateEvent or OpenEvent function returns this handle.
|
||||
* @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 PulseEvent(HANDLE hEvent);
|
||||
|
||||
/**
|
||||
* Creates or opens a named or unnamed file mapping object for a specified file.
|
||||
* @param hFile
|
||||
* A handle to the file from which to create a file mapping object.
|
||||
* @param lpAttributes
|
||||
* A pointer to a SECURITY_ATTRIBUTES structure that determines whether a returned handle can be inherited by child processes. The lpSecurityDescriptor member of the SECURITY_ATTRIBUTES structure specifies a security descriptor for a new file mapping object.
|
||||
* @param flProtect
|
||||
* Specifies the page protection of the file mapping object. All mapped views of the object must be compatible with this protection.
|
||||
* @param dwMaximumSizeHigh
|
||||
* The high-order DWORD of the maximum size of the file mapping object.
|
||||
* @param dwMaximumSizeLow
|
||||
* The low-order DWORD of the maximum size of the file mapping object.
|
||||
* @param lpName
|
||||
* The name of the file mapping object.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a handle to the newly created file mapping object.
|
||||
* If the object exists before the function call, the function returns a handle to the existing object (with its current size, not the specified size), and GetLastError returns ERROR_ALREADY_EXISTS.
|
||||
* If the function fails, the return value is NULL. To get extended error information, call GetLastError.
|
||||
*/
|
||||
HANDLE CreateFileMapping(HANDLE hFile, WinNT.SECURITY_ATTRIBUTES lpAttributes,
|
||||
int flProtect, int dwMaximumSizeHigh,
|
||||
int dwMaximumSizeLow, String lpName);
|
||||
|
||||
/**
|
||||
* Maps a view of a file mapping into the address space of a calling process.
|
||||
* @param hFileMappingObject
|
||||
* A handle to a file mapping object. The CreateFileMapping and OpenFileMapping functions return this handle.
|
||||
* @param dwDesiredAccess
|
||||
* The type of access to a file mapping object, which determines the protection of the pages.
|
||||
* @param dwFileOffsetHigh
|
||||
* A high-order DWORD of the file offset where the view begins.
|
||||
* @param dwFileOffsetLow
|
||||
* A low-order DWORD of the file offset where the view is to begin.
|
||||
* @param dwNumberOfBytesToMap
|
||||
* The number of bytes of a file mapping to map to the view.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the starting address of the mapped view.
|
||||
* If the function fails, the return value is NULL. To get extended error information, call GetLastError.
|
||||
*/
|
||||
Pointer MapViewOfFile(HANDLE hFileMappingObject, int dwDesiredAccess,
|
||||
int dwFileOffsetHigh, int dwFileOffsetLow,
|
||||
int dwNumberOfBytesToMap);
|
||||
|
||||
/**
|
||||
* Unmaps a mapped view of a file from the calling process's address space.
|
||||
* @param lpBaseAddress
|
||||
* A pointer to the base address of the mapped view of a file that is to be unmapped.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the starting address of the mapped view.
|
||||
* If the function fails, the return value is NULL. To get extended error information, call GetLastError.
|
||||
*/
|
||||
boolean UnmapViewOfFile(Pointer lpBaseAddress);
|
||||
|
||||
/**
|
||||
* Retrieves only the NetBIOS name of the local computer.
|
||||
*
|
||||
* @param buffer
|
||||
* A pointer to a buffer that receives the computer name or the cluster virtual server
|
||||
* name. The buffer size should be large enough to contain MAX_COMPUTERNAME_LENGTH + 1
|
||||
* characters.
|
||||
* @param lpnSize
|
||||
* On input, specifies the size of the buffer, in TCHARs. On output, the number of TCHARs
|
||||
* copied to the destination buffer, not including the terminating null character. If
|
||||
* the buffer is too small, the function fails and GetLastError returns
|
||||
* ERROR_BUFFER_OVERFLOW. The lpnSize parameter specifies the size of the buffer required,
|
||||
* including the terminating null character.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a nonzero value.
|
||||
* If the function fails, the return value is zero. To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
public boolean GetComputerName(char[] buffer, IntByReference lpnSize);
|
||||
|
||||
/**
|
||||
* The OpenThread function opens an existing thread object.
|
||||
* @param dwDesiredAccess
|
||||
* Access to the thread object. This access right is checked against any security
|
||||
* descriptor for the thread.
|
||||
* @param bInheritHandle
|
||||
* If this parameter is TRUE, the new process inherits the handle. If the parameter
|
||||
* is FALSE, the handle is not inherited.
|
||||
* @param dwThreadId
|
||||
* Identifier of the thread to be opened.
|
||||
* @return
|
||||
* If the function succeeds, the return value is an open handle to the specified process.
|
||||
* If the function fails, the return value is NULL. To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
HANDLE OpenThread(int dwDesiredAccess, boolean bInheritHandle, int dwThreadId);
|
||||
|
||||
/**
|
||||
* This function returns a handle to an existing process object.
|
||||
* @param fdwAccess
|
||||
* Not supported; set to zero.
|
||||
* @param fInherit
|
||||
* Not supported; set to FALSE.
|
||||
* @param IDProcess
|
||||
* Specifies the process identifier of the process to open.
|
||||
* @return
|
||||
* An open handle to the specified process indicates success.
|
||||
* NULL indicates failure.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HANDLE OpenProcess(int fdwAccess, boolean fInherit, int IDProcess);
|
||||
|
||||
/**
|
||||
* The GetTempPath function retrieves the path of the directory designated
|
||||
* for temporary files.
|
||||
* @param nBufferLength
|
||||
* Size of the string buffer identified by lpBuffer, in TCHARs.
|
||||
* @param buffer
|
||||
* Pointer to a string buffer that receives the null-terminated string specifying the
|
||||
* temporary file path. The returned string ends with a backslash, for example,
|
||||
* C:\TEMP\.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the length, in TCHARs, of the string
|
||||
* copied to lpBuffer, not including the terminating null character. If the return value
|
||||
* is greater than nBufferLength, the return value is the length, in TCHARs, of the
|
||||
* buffer required to hold the path.
|
||||
*
|
||||
* If the function fails, the return value is zero. To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
DWORD GetTempPath(DWORD nBufferLength, char[] buffer);
|
||||
|
||||
/**
|
||||
* The GetVersion function returns the current version number of the operating system.
|
||||
* @return
|
||||
* If the function succeeds, the return value includes the major and minor version numbers
|
||||
* of the operating system in the low order word, and information about the operating system
|
||||
* platform in the high order word.
|
||||
*/
|
||||
DWORD GetVersion();
|
||||
|
||||
/**
|
||||
* The GetVersionEx function obtains extended information about the version of the operating
|
||||
* system that is currently running.
|
||||
* @param lpVersionInfo
|
||||
* Pointer to an OSVERSIONINFO data structure that the function fills with operating system
|
||||
* version information.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a nonzero value.
|
||||
* If the function fails, the return value is zero. To get extended error information,
|
||||
* call GetLastError. The function fails if you specify an invalid value for the
|
||||
* dwOSVersionInfoSize member of the OSVERSIONINFO or OSVERSIONINFOEX structure.
|
||||
*/
|
||||
boolean GetVersionEx(OSVERSIONINFO lpVersionInfo);
|
||||
|
||||
/**
|
||||
* The GetVersionEx function obtains extended information about the version of the operating
|
||||
* system that is currently running.
|
||||
* @param lpVersionInfo
|
||||
* Pointer to an OSVERSIONINFOEX data structure that the function fills with operating system
|
||||
* version information.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a nonzero value.
|
||||
* If the function fails, the return value is zero. To get extended error information,
|
||||
* call GetLastError. The function fails if you specify an invalid value for the
|
||||
* dwOSVersionInfoSize member of the OSVERSIONINFO or OSVERSIONINFOEX structure.
|
||||
*/
|
||||
boolean GetVersionEx(OSVERSIONINFOEX lpVersionInfo);
|
||||
|
||||
/**
|
||||
* The GetSystemInfo function returns information about the current system.
|
||||
* @param lpSystemInfo
|
||||
* Pointer to a SYSTEM_INFO structure that receives the information.
|
||||
*/
|
||||
void GetSystemInfo(SYSTEM_INFO lpSystemInfo);
|
||||
|
||||
/**
|
||||
* The GetNativeSystemInfo function retrieves information about the current system to an
|
||||
* application running under WOW64. If the function is called from a 64-bit application,
|
||||
* it is equivalent to the GetSystemInfo function.
|
||||
* @param lpSystemInfo
|
||||
* Pointer to a SYSTEM_INFO structure that receives the information.
|
||||
*/
|
||||
void GetNativeSystemInfo(SYSTEM_INFO lpSystemInfo);
|
||||
|
||||
/**
|
||||
* The IsWow64Process function determines whether the specified process is running under WOW64.
|
||||
* @param hProcess
|
||||
* Handle to a process.
|
||||
* @param Wow64Process
|
||||
* Pointer to a value that is set to TRUE if the process is running under WOW64.
|
||||
* Otherwise, the value is set to FALSE.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a nonzero value.
|
||||
* If the function fails, the return value is zero. To get extended error information, call GetLastError.
|
||||
*/
|
||||
boolean IsWow64Process(HANDLE hProcess, IntByReference Wow64Process);
|
||||
|
||||
/**
|
||||
* Retrieves information about the system's current usage of both physical and virtual memory.
|
||||
* @param lpBuffer
|
||||
* A pointer to a MEMORYSTATUSEX structure that receives information about current memory availability.
|
||||
* @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 GlobalMemoryStatusEx(MEMORYSTATUSEX lpBuffer);
|
||||
|
||||
/**
|
||||
* The GetLogicalDriveStrings function fills a buffer with strings that specify
|
||||
* valid drives in the system.
|
||||
* @param nBufferLength
|
||||
* Maximum size of the buffer pointed to by lpBuffer, in TCHARs. This size does not include
|
||||
* the terminating null character. If this parameter is zero, lpBuffer is not used.
|
||||
* @param lpBuffer
|
||||
* Pointer to a buffer that receives a series of null-terminated strings, one for each valid
|
||||
* drive in the system, plus with an additional null character. Each string is a device name.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the length, in characters, of the strings
|
||||
* copied to the buffer, not including the terminating null character. Note that an ANSI-ASCII
|
||||
* null character uses one byte, but a Unicode null character uses two bytes.
|
||||
* If the buffer is not large enough, the return value is greater than nBufferLength. It is
|
||||
* the size of the buffer required to hold the drive strings.
|
||||
* If the function fails, the return value is zero. To get extended error information, use
|
||||
* the GetLastError function.
|
||||
*/
|
||||
DWORD GetLogicalDriveStrings(DWORD nBufferLength, char[] lpBuffer);
|
||||
|
||||
/**
|
||||
* The GetDiskFreeSpaceEx function retrieves information about the amount of space that is
|
||||
* available on a disk volume, which is the total amount of space, the total amount of free
|
||||
* space, and the total amount of free space available to the user that is associated with
|
||||
* the calling thread.
|
||||
* @param lpDirectoryName
|
||||
* A pointer to a null-terminated string that specifies a directory on a disk.
|
||||
* If this parameter is NULL, the function uses the root of the current disk.
|
||||
* If this parameter is a UNC name, it must include a trailing backslash, for example,
|
||||
* \\MyServer\MyShare\.
|
||||
* This parameter does not have to specify the root directory on a disk. The function
|
||||
* accepts any directory on a disk.
|
||||
* @param lpFreeBytesAvailable
|
||||
* A pointer to a variable that receives the total number of free bytes on a disk that
|
||||
* are available to the user who is associated with the calling thread.
|
||||
* This parameter can be NULL.
|
||||
* @param lpTotalNumberOfBytes
|
||||
* A pointer to a variable that receives the total number of bytes on a disk that are
|
||||
* available to the user who is associated with the calling thread.
|
||||
* This parameter can be NULL.
|
||||
* @param lpTotalNumberOfFreeBytes
|
||||
* A pointer to a variable that receives the total number of free bytes on a disk.
|
||||
* This parameter can be NULL.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
* If the function fails, the return value is 0 (zero). To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
boolean GetDiskFreeSpaceEx(String lpDirectoryName, LARGE_INTEGER.ByReference lpFreeBytesAvailable,
|
||||
LARGE_INTEGER.ByReference lpTotalNumberOfBytes, LARGE_INTEGER.ByReference lpTotalNumberOfFreeBytes);
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/* 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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.LastErrorException;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.WinDef.DWORD;
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* Kernel32 utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Kernel32Util {
|
||||
|
||||
/**
|
||||
* Get current computer NetBIOS name.
|
||||
* @return
|
||||
* Netbios name.
|
||||
*/
|
||||
public static String getComputerName() {
|
||||
char buffer[] = new char[WinBase.MAX_COMPUTERNAME_LENGTH() + 1];
|
||||
IntByReference lpnSize = new IntByReference(buffer.length);
|
||||
if (! Kernel32.INSTANCE.GetComputerName(buffer, lpnSize)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return Native.toString(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a message from an HRESULT.
|
||||
* @param code
|
||||
* HRESULT
|
||||
* @return
|
||||
* Formatted message.
|
||||
*/
|
||||
public static String formatMessageFromHR(HRESULT code) {
|
||||
PointerByReference buffer = new PointerByReference();
|
||||
if (0 == Kernel32.INSTANCE.FormatMessage(
|
||||
WinBase.FORMAT_MESSAGE_ALLOCATE_BUFFER
|
||||
| WinBase.FORMAT_MESSAGE_FROM_SYSTEM
|
||||
| WinBase.FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
null,
|
||||
code.intValue(),
|
||||
0, // TODO: MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)
|
||||
buffer,
|
||||
0,
|
||||
null)) {
|
||||
throw new LastErrorException(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
String s = buffer.getValue().getString(0, ! Boolean.getBoolean("w32.ascii"));
|
||||
s = s.replace(".\r",".").replace(".\n",".");
|
||||
Kernel32.INSTANCE.LocalFree(buffer.getValue());
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a system message from an error code.
|
||||
* @param code
|
||||
* Error code, typically a result of GetLastError.
|
||||
* @return
|
||||
* Formatted message.
|
||||
*/
|
||||
public static String formatMessageFromLastErrorCode(int code) {
|
||||
return formatMessageFromHR(W32Errors.HRESULT_FROM_WIN32(code));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path designated for temporary files.
|
||||
* @return
|
||||
* Path.
|
||||
*/
|
||||
public static String getTempPath() {
|
||||
DWORD nBufferLength = new DWORD(WinDef.MAX_PATH);
|
||||
char[] buffer = new char[nBufferLength.intValue()];
|
||||
if (Kernel32.INSTANCE.GetTempPath(nBufferLength, buffer).intValue() == 0) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return Native.toString(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns valid drives in the system.
|
||||
* @return
|
||||
* An array of valid drives.
|
||||
*/
|
||||
public static String[] getLogicalDriveStrings() {
|
||||
DWORD dwSize = Kernel32.INSTANCE.GetLogicalDriveStrings(new DWORD(0), null);
|
||||
if (dwSize.intValue() <= 0) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
char buf[] = new char[dwSize.intValue()];
|
||||
dwSize = Kernel32.INSTANCE.GetLogicalDriveStrings(dwSize, buf);
|
||||
if (dwSize.intValue() <= 0) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
List<String> drives = new ArrayList<String>();
|
||||
String drive = "";
|
||||
// the buffer is double-null-terminated
|
||||
for(int i = 0; i < buf.length - 1; i++) {
|
||||
if (buf[i] == 0) {
|
||||
drives.add(drive);
|
||||
drive = "";
|
||||
} else {
|
||||
drive += buf[i];
|
||||
}
|
||||
}
|
||||
return drives.toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
/* 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 com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from LMAccess.h.
|
||||
* Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface LMAccess extends StdCallLibrary {
|
||||
|
||||
public static class LOCALGROUP_INFO_0 extends Structure {
|
||||
public LOCALGROUP_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LOCALGROUP_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public WString lgrui0_name;
|
||||
}
|
||||
|
||||
public static class LOCALGROUP_INFO_1 extends Structure {
|
||||
public LOCALGROUP_INFO_1() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LOCALGROUP_INFO_1(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public WString lgrui1_name;
|
||||
public WString lgrui1_comment;
|
||||
}
|
||||
|
||||
//
|
||||
// bit masks for the NetUserEnum filter parameter.
|
||||
//
|
||||
|
||||
public static final int FILTER_TEMP_DUPLICATE_ACCOUNT = 0x0001;
|
||||
public static final int FILTER_NORMAL_ACCOUNT = 0x0002;
|
||||
// public static final int FILTER_PROXY_ACCOUNT = 0x0004;
|
||||
public static final int FILTER_INTERDOMAIN_TRUST_ACCOUNT = 0x0008;
|
||||
public static final int FILTER_WORKSTATION_TRUST_ACCOUNT = 0x0010;
|
||||
public static final int FILTER_SERVER_TRUST_ACCOUNT = 0x0020;
|
||||
|
||||
/**
|
||||
* The USER_INFO_0 structure contains a user account name.
|
||||
*/
|
||||
public static class USER_INFO_0 extends Structure {
|
||||
public USER_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public USER_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a Unicode string that specifies the name of the user account.
|
||||
*/
|
||||
public WString usri0_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The USER_INFO_1 structure contains information about a user account, including
|
||||
* account name, password data, privilege level, and the path to the user's home
|
||||
* directory.
|
||||
*/
|
||||
public static class USER_INFO_1 extends Structure {
|
||||
public USER_INFO_1() {
|
||||
super();
|
||||
}
|
||||
|
||||
public USER_INFO_1(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a Unicode string that specifies the name of the user
|
||||
* account.
|
||||
*/
|
||||
public WString usri1_name;
|
||||
/**
|
||||
* Pointer to a Unicode string that specifies the password of the user
|
||||
* indicated by the usri1_name member.
|
||||
*/
|
||||
public WString usri1_password;
|
||||
/**
|
||||
* Specifies a DWORD value that indicates the number of seconds that have
|
||||
* elapsed since the usri1_password member was last changed.
|
||||
*/
|
||||
public int usri1_password_age;
|
||||
/**
|
||||
* Specifies a DWORD value that indicates the level of privilege assigned
|
||||
* to the usri1_name member.
|
||||
*/
|
||||
public int usri1_priv;
|
||||
/**
|
||||
* Pointer to a Unicode string specifying the path of the home directory
|
||||
* for the user specified in the usri1_name member.
|
||||
*/
|
||||
public WString usri1_home_dir;
|
||||
/**
|
||||
* Pointer to a Unicode string that contains a comment to associate with
|
||||
* the user account.
|
||||
*/
|
||||
public WString usri1_comment;
|
||||
/**
|
||||
* Specifies a DWORD value that determines several features.
|
||||
*/
|
||||
public int usri1_flags;
|
||||
/**
|
||||
* Pointer to a Unicode string specifying the path for the user's
|
||||
* logon script file.
|
||||
*/
|
||||
public WString usri1_script_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_USERS_INFO_0 structure contains global group member information.
|
||||
*/
|
||||
public static class GROUP_USERS_INFO_0 extends Structure {
|
||||
public GROUP_USERS_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_USERS_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that specifies a name.
|
||||
*/
|
||||
public WString grui0_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The LOCALGROUP_USERS_INFO_0 structure contains local group member information.
|
||||
*/
|
||||
public static class LOCALGROUP_USERS_INFO_0 extends Structure {
|
||||
public LOCALGROUP_USERS_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LOCALGROUP_USERS_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a Unicode string specifying the name of a local group to which the user belongs.
|
||||
*/
|
||||
public WString lgrui0_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_INFO_0 structure contains the name of a global group in the security
|
||||
* database, which is the security accounts manager (SAM) database or, in the case
|
||||
* of domain controllers, the Active Directory.
|
||||
*/
|
||||
public static class GROUP_INFO_0 extends Structure {
|
||||
public GROUP_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that specifies
|
||||
* the name of the global group.
|
||||
*/
|
||||
public WString grpi0_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_INFO_1 structure contains a global group name and a comment to
|
||||
* associate with the group.
|
||||
*/
|
||||
public static class GROUP_INFO_1 extends Structure {
|
||||
public GROUP_INFO_1() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_1(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that specifies
|
||||
* the name of the global group.
|
||||
*/
|
||||
public WString grpi1_name;
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that specifies
|
||||
* a remark associated with the global group. This member can be a null
|
||||
* string. The comment can contain MAXCOMMENTSZ characters.
|
||||
*/
|
||||
public WString grpi1_comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_INFO_2 structure contains information about a global group, including
|
||||
* name, identifier, and resource attributes.
|
||||
*/
|
||||
public static class GROUP_INFO_2 extends Structure {
|
||||
public GROUP_INFO_2() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_2(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that
|
||||
* specifies the name of the global group.
|
||||
*/
|
||||
public WString grpi2_name;
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that contains a
|
||||
* remark associated with the global group. This member can be a null string.
|
||||
* The comment can contain MAXCOMMENTSZ characters.
|
||||
*/
|
||||
public WString grpi2_comment;
|
||||
/**
|
||||
* Specifies a DWORD value that contains the relative identifier (RID) of
|
||||
* the global group.
|
||||
*/
|
||||
public int grpi2_group_id;
|
||||
/**
|
||||
* These attributes are hard-coded to SE_GROUP_MANDATORY, SE_GROUP_ENABLED,
|
||||
* and SE_GROUP_ENABLED_BY_DEFAULT.
|
||||
*/
|
||||
public int grpi2_attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_INFO_3 structure contains information about a global group, including
|
||||
* name, security identifier (SID), and resource attributes.
|
||||
*/
|
||||
public static class GROUP_INFO_3 extends Structure {
|
||||
public GROUP_INFO_3() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_3(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that
|
||||
* specifies the name of the global group.
|
||||
*/
|
||||
public WString grpi3_name;
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that
|
||||
* contains a remark associated with the global group. This member can be
|
||||
* a null string. The comment can contain MAXCOMMENTSZ characters.
|
||||
*/
|
||||
public WString grpi3_comment;
|
||||
/**
|
||||
* Pointer to a SID structure that contains the security identifier (SID) that
|
||||
* uniquely identifies the global group.
|
||||
*/
|
||||
public PSID grpi3_group_sid;
|
||||
/**
|
||||
* These attributes are hard-coded to SE_GROUP_MANDATORY, SE_GROUP_ENABLED, and
|
||||
* SE_GROUP_ENABLED_BY_DEFAULT.
|
||||
*/
|
||||
public int grpi3_attributes;
|
||||
}
|
||||
|
||||
//
|
||||
// Privilege levels (USER_INFO_X field usriX_priv (X = 0/1)).
|
||||
//
|
||||
|
||||
public static final int USER_PRIV_MASK = 3;
|
||||
public static final int USER_PRIV_GUEST = 0;
|
||||
public static final int USER_PRIV_USER = 1;
|
||||
public static final int USER_PRIV_ADMIN = 2;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/* 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 com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from LMCons.h.
|
||||
* @author dblock[at]dblock.org
|
||||
* Windows SDK 6.0A
|
||||
*/
|
||||
public interface LMCons extends StdCallLibrary {
|
||||
public static final int NETBIOS_NAME_LEN = 16; // NetBIOS net name (bytes)
|
||||
|
||||
/**
|
||||
* Value to be used with APIs which have a "preferred maximum length" parameter.
|
||||
* This value indicates that the API should just allocate "as much as it takes."
|
||||
*/
|
||||
public static final int MAX_PREFERRED_LENGTH = -1;
|
||||
}
|
||||
@@ -0,0 +1,566 @@
|
||||
/* 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.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from LMErr.h.
|
||||
* @author dblock[at]dblock.org
|
||||
* Windows SDK 6.0A
|
||||
*/
|
||||
public interface LMErr extends StdCallLibrary {
|
||||
public static final int NERR_Success = 0;
|
||||
public static final int NERR_BASE = 2100;
|
||||
|
||||
public static final int NERR_NetNotStarted = NERR_BASE + 2; /* The workstation driver is not installed. */
|
||||
public static final int NERR_UnknownServer = NERR_BASE + 3; /* The server could not be located. */
|
||||
public static final int NERR_ShareMem = NERR_BASE + 4; /* An internal error occurred. The network cannot access a shared memory segment. */
|
||||
|
||||
public static final int NERR_NoNetworkResource = NERR_BASE + 5; /* A network resource shortage occurred . */
|
||||
public static final int NERR_RemoteOnly = NERR_BASE + 6; /* This operation is not supported on workstations. */
|
||||
public static final int NERR_DevNotRedirected = NERR_BASE + 7; /* The device is not connected. */
|
||||
/* NERR_BASE + 8 is used for ERROR_CONNECTED_OTHER_PASSWORD */
|
||||
/* NERR_BASE + 9 is used for ERROR_CONNECTED_OTHER_PASSWORD_DEFAULT */
|
||||
/* UNUSED BASE + 10 */
|
||||
/* UNUSED BASE + 11 */
|
||||
/* UNUSED BASE + 12 */
|
||||
/* UNUSED BASE + 13 */
|
||||
public static final int NERR_ServerNotStarted = NERR_BASE + 14; /* The Server service is not started. */
|
||||
public static final int NERR_ItemNotFound = NERR_BASE + 15; /* The queue is empty. */
|
||||
public static final int NERR_UnknownDevDir = NERR_BASE + 16; /* The device or directory does not exist. */
|
||||
public static final int NERR_RedirectedPath = NERR_BASE + 17; /* The operation is invalid on a redirected resource. */
|
||||
public static final int NERR_DuplicateShare = NERR_BASE + 18; /* The name has already been shared. */
|
||||
public static final int NERR_NoRoom = NERR_BASE + 19; /* The server is currently out of the requested resource. */
|
||||
/* UNUSED BASE + 20 */
|
||||
public static final int NERR_TooManyItems = NERR_BASE + 21; /* Requested addition of items exceeds the maximum allowed. */
|
||||
public static final int NERR_InvalidMaxUsers = NERR_BASE + 22; /* The Peer service supports only two simultaneous users. */
|
||||
public static final int NERR_BufTooSmall = NERR_BASE + 23; /* The API return buffer is too small. */
|
||||
/* UNUSED BASE + 24 */
|
||||
/* UNUSED BASE + 25 */
|
||||
/* UNUSED BASE + 26 */
|
||||
public static final int NERR_RemoteErr = NERR_BASE + 27; /* A remote API error occurred. */
|
||||
/* UNUSED BASE + 28 */
|
||||
/* UNUSED BASE + 29 */
|
||||
/* UNUSED BASE + 30 */
|
||||
public static final int NERR_LanmanIniError = NERR_BASE + 31; /* An error occurred when opening or reading the configuration file. */
|
||||
/* UNUSED BASE + 32 */
|
||||
/* UNUSED BASE + 33 */
|
||||
/* UNUSED BASE + 34 */
|
||||
/* UNUSED BASE + 35 */
|
||||
public static final int NERR_NetworkError = NERR_BASE + 36; /* A general network error occurred. */
|
||||
public static final int NERR_WkstaInconsistentState = NERR_BASE + 37;
|
||||
/* The Workstation service is in an inconsistent state. Restart the computer before restarting the Workstation service. */
|
||||
public static final int NERR_WkstaNotStarted = NERR_BASE + 38; /* The Workstation service has not been started. */
|
||||
public static final int NERR_BrowserNotStarted = NERR_BASE + 39; /* The requested information is not available. */
|
||||
public static final int NERR_InternalError = NERR_BASE + 40; /* An internal Windows error occurred.*/
|
||||
public static final int NERR_BadTransactConfig = NERR_BASE + 41; /* The server is not configured for transactions. */
|
||||
public static final int NERR_InvalidAPI = NERR_BASE + 42; /* The requested API is not supported on the remote server. */
|
||||
public static final int NERR_BadEventName = NERR_BASE + 43; /* The event name is invalid. */
|
||||
public static final int NERR_DupNameReboot = NERR_BASE + 44; /* The computer name already exists on the network. Change it and restart the computer. */
|
||||
/*
|
||||
* Config API related
|
||||
* Error codes from BASE + 45 to BASE + 49
|
||||
*/
|
||||
|
||||
/* UNUSED BASE + 45 */
|
||||
public static final int NERR_CfgCompNotFound = NERR_BASE + 46; /* The specified component could not be found in the configuration information. */
|
||||
public static final int NERR_CfgParamNotFound = NERR_BASE + 47; /* The specified parameter could not be found in the configuration information. */
|
||||
public static final int NERR_LineTooLong = NERR_BASE + 49; /* A line in the configuration file is too long. */
|
||||
|
||||
/*
|
||||
* Spooler API related
|
||||
* Error codes from BASE + 50 to BASE + 79
|
||||
*/
|
||||
|
||||
public static final int NERR_QNotFound = NERR_BASE + 50; /* The printer does not exist. */
|
||||
public static final int NERR_JobNotFound = NERR_BASE + 51; /* The print job does not exist. */
|
||||
public static final int NERR_DestNotFound = NERR_BASE + 52; /* The printer destination cannot be found. */
|
||||
public static final int NERR_DestExists = NERR_BASE + 53; /* The printer destination already exists. */
|
||||
public static final int NERR_QExists = NERR_BASE + 54; /* The printer queue already exists. */
|
||||
public static final int NERR_QNoRoom = NERR_BASE + 55; /* No more printers can be added. */
|
||||
public static final int NERR_JobNoRoom = NERR_BASE + 56; /* No more print jobs can be added. */
|
||||
public static final int NERR_DestNoRoom = NERR_BASE + 57; /* No more printer destinations can be added. */
|
||||
public static final int NERR_DestIdle = NERR_BASE + 58; /* This printer destination is idle and cannot accept control operations. */
|
||||
public static final int NERR_DestInvalidOp = NERR_BASE + 59; /* This printer destination request contains an invalid control function. */
|
||||
public static final int NERR_ProcNoRespond = NERR_BASE + 60; /* The print processor is not responding. */
|
||||
public static final int NERR_SpoolerNotLoaded = NERR_BASE + 61; /* The spooler is not running. */
|
||||
public static final int NERR_DestInvalidState = NERR_BASE + 62; /* This operation cannot be performed on the print destination in its current state. */
|
||||
public static final int NERR_QInvalidState = NERR_BASE + 63; /* This operation cannot be performed on the printer queue in its current state. */
|
||||
public static final int NERR_JobInvalidState = NERR_BASE + 64; /* This operation cannot be performed on the print job in its current state. */
|
||||
public static final int NERR_SpoolNoMemory = NERR_BASE + 65; /* A spooler memory allocation failure occurred. */
|
||||
public static final int NERR_DriverNotFound = NERR_BASE + 66; /* The device driver does not exist. */
|
||||
public static final int NERR_DataTypeInvalid = NERR_BASE + 67; /* The data type is not supported by the print processor. */
|
||||
public static final int NERR_ProcNotFound = NERR_BASE + 68; /* The print processor is not installed. */
|
||||
|
||||
/*
|
||||
* Service API related
|
||||
* Error codes from BASE + 80 to BASE + 99
|
||||
*/
|
||||
|
||||
public static final int NERR_ServiceTableLocked = NERR_BASE + 80; /* The service database is locked. */
|
||||
public static final int NERR_ServiceTableFull = NERR_BASE + 81; /* The service table is full. */
|
||||
public static final int NERR_ServiceInstalled = NERR_BASE + 82; /* The requested service has already been started. */
|
||||
public static final int NERR_ServiceEntryLocked = NERR_BASE + 83; /* The service does not respond to control actions. */
|
||||
public static final int NERR_ServiceNotInstalled = NERR_BASE + 84; /* The service has not been started. */
|
||||
public static final int NERR_BadServiceName = NERR_BASE + 85; /* The service name is invalid. */
|
||||
public static final int NERR_ServiceCtlTimeout = NERR_BASE + 86; /* The service is not responding to the control function. */
|
||||
public static final int NERR_ServiceCtlBusy = NERR_BASE + 87; /* The service control is busy. */
|
||||
public static final int NERR_BadServiceProgName = NERR_BASE + 88; /* The configuration file contains an invalid service program name. */
|
||||
public static final int NERR_ServiceNotCtrl = NERR_BASE + 89; /* The service could not be controlled in its present state. */
|
||||
public static final int NERR_ServiceKillProc = NERR_BASE + 90; /* The service ended abnormally. */
|
||||
public static final int NERR_ServiceCtlNotValid = NERR_BASE + 91; /* The requested pause, continue, or stop is not valid for this service. */
|
||||
public static final int NERR_NotInDispatchTbl = NERR_BASE + 92; /* The service control dispatcher could not find the service name in the dispatch table. */
|
||||
public static final int NERR_BadControlRecv = NERR_BASE + 93; /* The service control dispatcher pipe read failed. */
|
||||
public static final int NERR_ServiceNotStarting = NERR_BASE + 94; /* A thread for the new service could not be created. */
|
||||
|
||||
/*
|
||||
* Wksta and Logon API related
|
||||
* Error codes from BASE + 100 to BASE + 118
|
||||
*/
|
||||
|
||||
public static final int NERR_AlreadyLoggedOn = NERR_BASE + 100; /* This workstation is already logged on to the local-area network. */
|
||||
public static final int NERR_NotLoggedOn = NERR_BASE + 101; /* The workstation is not logged on to the local-area network. */
|
||||
public static final int NERR_BadUsername = NERR_BASE + 102; /* The user name or group name parameter is invalid. */
|
||||
public static final int NERR_BadPassword = NERR_BASE + 103; /* The password parameter is invalid. */
|
||||
public static final int NERR_UnableToAddName_W = NERR_BASE + 104; /* @W The logon processor did not add the message alias. */
|
||||
public static final int NERR_UnableToAddName_F = NERR_BASE + 105; /* The logon processor did not add the message alias. */
|
||||
public static final int NERR_UnableToDelName_W = NERR_BASE + 106; /* @W The logoff processor did not delete the message alias. */
|
||||
public static final int NERR_UnableToDelName_F = NERR_BASE + 107; /* The logoff processor did not delete the message alias. */
|
||||
/* UNUSED BASE + 108 */
|
||||
public static final int NERR_LogonsPaused = NERR_BASE + 109; /* Network logons are paused. */
|
||||
public static final int NERR_LogonServerConflict = NERR_BASE + 110;/* A centralized logon-server conflict occurred. */
|
||||
public static final int NERR_LogonNoUserPath = NERR_BASE + 111; /* The server is configured without a valid user path. */
|
||||
public static final int NERR_LogonScriptError = NERR_BASE + 112; /* An error occurred while loading or running the logon script. */
|
||||
/* UNUSED BASE + 113 */
|
||||
public static final int NERR_StandaloneLogon = NERR_BASE + 114; /* The logon server was not specified. Your computer will be logged on as STANDALONE. */
|
||||
public static final int NERR_LogonServerNotFound = NERR_BASE + 115; /* The logon server could not be found. */
|
||||
public static final int NERR_LogonDomainExists = NERR_BASE + 116; /* There is already a logon domain for this computer. */
|
||||
public static final int NERR_NonValidatedLogon = NERR_BASE + 117; /* The logon server could not validate the logon. */
|
||||
|
||||
/*
|
||||
* ACF API related = access, user, group;
|
||||
* Error codes from BASE + 119 to BASE + 149
|
||||
*/
|
||||
|
||||
public static final int NERR_ACFNotFound = NERR_BASE + 119; /* The security database could not be found. */
|
||||
public static final int NERR_GroupNotFound = NERR_BASE + 120; /* The group name could not be found. */
|
||||
public static final int NERR_UserNotFound = NERR_BASE + 121; /* The user name could not be found. */
|
||||
public static final int NERR_ResourceNotFound = NERR_BASE + 122; /* The resource name could not be found. */
|
||||
public static final int NERR_GroupExists = NERR_BASE + 123; /* The group already exists. */
|
||||
public static final int NERR_UserExists = NERR_BASE + 124; /* The account already exists. */
|
||||
public static final int NERR_ResourceExists = NERR_BASE + 125; /* The resource permission list already exists. */
|
||||
public static final int NERR_NotPrimary = NERR_BASE + 126; /* This operation is only allowed on the primary domain controller of the domain. */
|
||||
public static final int NERR_ACFNotLoaded = NERR_BASE + 127; /* The security database has not been started. */
|
||||
public static final int NERR_ACFNoRoom = NERR_BASE + 128; /* There are too many names in the user accounts database. */
|
||||
public static final int NERR_ACFFileIOFail = NERR_BASE + 129; /* A disk I/O failure occurred.*/
|
||||
public static final int NERR_ACFTooManyLists = NERR_BASE + 130; /* The limit of 64 entries per resource was exceeded. */
|
||||
public static final int NERR_UserLogon = NERR_BASE + 131; /* Deleting a user with a session is not allowed. */
|
||||
public static final int NERR_ACFNoParent = NERR_BASE + 132; /* The parent directory could not be located. */
|
||||
public static final int NERR_CanNotGrowSegment = NERR_BASE + 133; /* Unable to add to the security database session cache segment. */
|
||||
public static final int NERR_SpeGroupOp = NERR_BASE + 134; /* This operation is not allowed on this special group. */
|
||||
public static final int NERR_NotInCache = NERR_BASE + 135; /* This user is not cached in user accounts database session cache. */
|
||||
public static final int NERR_UserInGroup = NERR_BASE + 136; /* The user already belongs to this group. */
|
||||
public static final int NERR_UserNotInGroup = NERR_BASE + 137; /* The user does not belong to this group. */
|
||||
public static final int NERR_AccountUndefined = NERR_BASE + 138; /* This user account is undefined. */
|
||||
public static final int NERR_AccountExpired = NERR_BASE + 139; /* This user account has expired. */
|
||||
public static final int NERR_InvalidWorkstation = NERR_BASE + 140; /* The user is not allowed to log on from this workstation. */
|
||||
public static final int NERR_InvalidLogonHours = NERR_BASE + 141; /* The user is not allowed to log on at this time. */
|
||||
public static final int NERR_PasswordExpired = NERR_BASE + 142; /* The password of this user has expired. */
|
||||
public static final int NERR_PasswordCantChange = NERR_BASE + 143; /* The password of this user cannot change. */
|
||||
public static final int NERR_PasswordHistConflict = NERR_BASE + 144; /* This password cannot be used now. */
|
||||
public static final int NERR_PasswordTooShort = NERR_BASE + 145; /* The password does not meet the password policy requirements. Check the minimum password length, password complexity and password history requirements. */
|
||||
public static final int NERR_PasswordTooRecent = NERR_BASE + 146; /* The password of this user is too recent to change. */
|
||||
public static final int NERR_InvalidDatabase = NERR_BASE + 147; /* The security database is corrupted. */
|
||||
public static final int NERR_DatabaseUpToDate = NERR_BASE + 148; /* No updates are necessary to this replicant network/local security database. */
|
||||
public static final int NERR_SyncRequired = NERR_BASE + 149; /* This replicant database is outdated; synchronization is required. */
|
||||
|
||||
/*
|
||||
* Use API related
|
||||
* Error codes from BASE + 150 to BASE + 169
|
||||
*/
|
||||
|
||||
public static final int NERR_UseNotFound = NERR_BASE + 150; /* The network connection could not be found. */
|
||||
public static final int NERR_BadAsgType = NERR_BASE + 151; /* This asg_type is invalid. */
|
||||
public static final int NERR_DeviceIsShared = NERR_BASE + 152; /* This device is currently being shared. */
|
||||
public static final int NERR_SameAsComputerName = NERR_BASE + 153; /* The user name may not be same as computer name. */
|
||||
|
||||
|
||||
/*
|
||||
* Message Server related
|
||||
* Error codes BASE + 170 to BASE + 209
|
||||
*/
|
||||
|
||||
public static final int NERR_NoComputerName = NERR_BASE + 170; /* The computer name could not be added as a message alias. The name may already exist on the network. */
|
||||
public static final int NERR_MsgAlreadyStarted = NERR_BASE + 171; /* The Messenger service is already started. */
|
||||
public static final int NERR_MsgInitFailed = NERR_BASE + 172; /* The Messenger service failed to start. */
|
||||
public static final int NERR_NameNotFound = NERR_BASE + 173; /* The message alias could not be found on the network. */
|
||||
public static final int NERR_AlreadyForwarded = NERR_BASE + 174; /* This message alias has already been forwarded. */
|
||||
public static final int NERR_AddForwarded = NERR_BASE + 175; /* This message alias has been added but is still forwarded. */
|
||||
public static final int NERR_AlreadyExists = NERR_BASE + 176; /* This message alias already exists locally. */
|
||||
public static final int NERR_TooManyNames = NERR_BASE + 177; /* The maximum number of added message aliases has been exceeded. */
|
||||
public static final int NERR_DelComputerName = NERR_BASE + 178; /* The computer name could not be deleted.*/
|
||||
public static final int NERR_LocalForward = NERR_BASE + 179; /* Messages cannot be forwarded back to the same workstation. */
|
||||
public static final int NERR_GrpMsgProcessor = NERR_BASE + 180; /* An error occurred in the domain message processor. */
|
||||
public static final int NERR_PausedRemote = NERR_BASE + 181; /* The message was sent, but the recipient has paused the Messenger service. */
|
||||
public static final int NERR_BadReceive = NERR_BASE + 182; /* The message was sent but not received. */
|
||||
public static final int NERR_NameInUse = NERR_BASE + 183; /* The message alias is currently in use. Try again later. */
|
||||
public static final int NERR_MsgNotStarted = NERR_BASE + 184; /* The Messenger service has not been started. */
|
||||
public static final int NERR_NotLocalName = NERR_BASE + 185; /* The name is not on the local computer. */
|
||||
public static final int NERR_NoForwardName = NERR_BASE + 186; /* The forwarded message alias could not be found on the network. */
|
||||
public static final int NERR_RemoteFull = NERR_BASE + 187; /* The message alias table on the remote station is full. */
|
||||
public static final int NERR_NameNotForwarded = NERR_BASE + 188; /* Messages for this alias are not currently being forwarded. */
|
||||
public static final int NERR_TruncatedBroadcast = NERR_BASE + 189; /* The broadcast message was truncated. */
|
||||
public static final int NERR_InvalidDevice = NERR_BASE + 194; /* This is an invalid device name. */
|
||||
public static final int NERR_WriteFault = NERR_BASE + 195; /* A write fault occurred. */
|
||||
/* UNUSED BASE + 196 */
|
||||
public static final int NERR_DuplicateName = NERR_BASE + 197; /* A duplicate message alias exists on the network. */
|
||||
public static final int NERR_DeleteLater = NERR_BASE + 198; /* @W This message alias will be deleted later. */
|
||||
public static final int NERR_IncompleteDel = NERR_BASE + 199; /* The message alias was not successfully deleted from all networks. */
|
||||
public static final int NERR_MultipleNets = NERR_BASE + 200; /* This operation is not supported on computers with multiple networks. */
|
||||
|
||||
/*
|
||||
* Server API related
|
||||
* Error codes BASE + 210 to BASE + 229
|
||||
*/
|
||||
|
||||
public static final int NERR_NetNameNotFound = NERR_BASE + 210; /* This shared resource does not exist.*/
|
||||
public static final int NERR_DeviceNotShared = NERR_BASE + 211; /* This device is not shared. */
|
||||
public static final int NERR_ClientNameNotFound = NERR_BASE + 212; /* A session does not exist with that computer name. */
|
||||
public static final int NERR_FileIdNotFound = NERR_BASE + 214; /* There is not an open file with that identification number. */
|
||||
public static final int NERR_ExecFailure = NERR_BASE + 215; /* A failure occurred when executing a remote administration command. */
|
||||
public static final int NERR_TmpFile = NERR_BASE + 216; /* A failure occurred when opening a remote temporary file. */
|
||||
public static final int NERR_TooMuchData = NERR_BASE + 217; /* The data returned from a remote administration command has been truncated to 64K. */
|
||||
public static final int NERR_DeviceShareConflict = NERR_BASE + 218; /* This device cannot be shared as both a spooled and a non-spooled resource. */
|
||||
public static final int NERR_BrowserTableIncomplete = NERR_BASE + 219; /* The information in the list of servers may be incorrect. */
|
||||
public static final int NERR_NotLocalDomain = NERR_BASE + 220; /* The computer is not active in this domain. */
|
||||
public static final int NERR_IsDfsShare = NERR_BASE + 221; /* The share must be removed from the Distributed File System before it can be deleted. */
|
||||
|
||||
/*
|
||||
* CharDev API related
|
||||
* Error codes BASE + 230 to BASE + 249
|
||||
*/
|
||||
|
||||
/* UNUSED BASE + 230 */
|
||||
public static final int NERR_DevInvalidOpCode = NERR_BASE + 231; /* The operation is invalid for this device. */
|
||||
public static final int NERR_DevNotFound = NERR_BASE + 232; /* This device cannot be shared. */
|
||||
public static final int NERR_DevNotOpen = NERR_BASE + 233; /* This device was not open. */
|
||||
public static final int NERR_BadQueueDevString = NERR_BASE + 234; /* This device name list is invalid. */
|
||||
public static final int NERR_BadQueuePriority = NERR_BASE + 235; /* The queue priority is invalid. */
|
||||
public static final int NERR_NoCommDevs = NERR_BASE + 237; /* There are no shared communication devices. */
|
||||
public static final int NERR_QueueNotFound = NERR_BASE + 238; /* The queue you specified does not exist. */
|
||||
public static final int NERR_BadDevString = NERR_BASE + 240; /* This list of devices is invalid. */
|
||||
public static final int NERR_BadDev = NERR_BASE + 241; /* The requested device is invalid. */
|
||||
public static final int NERR_InUseBySpooler = NERR_BASE + 242; /* This device is already in use by the spooler. */
|
||||
public static final int NERR_CommDevInUse = NERR_BASE + 243; /* This device is already in use as a communication device. */
|
||||
|
||||
/*
|
||||
* NetICanonicalize and NetIType and NetIMakeLMFileName
|
||||
* NetIListCanon and NetINameCheck
|
||||
* Error codes BASE + 250 to BASE + 269
|
||||
*/
|
||||
|
||||
public static final int NERR_InvalidComputer = NERR_BASE + 251; /* This computer name is invalid. */
|
||||
/* UNUSED BASE + 252 */
|
||||
/* UNUSED BASE + 253 */
|
||||
public static final int NERR_MaxLenExceeded = NERR_BASE + 254; /* The string and prefix specified are too long. */
|
||||
/* UNUSED BASE + 255 */
|
||||
public static final int NERR_BadComponent = NERR_BASE + 256; /* This path component is invalid. */
|
||||
public static final int NERR_CantType = NERR_BASE + 257; /* Could not determine the type of input. */
|
||||
/* UNUSED BASE + 258 */
|
||||
/* UNUSED BASE + 259 */
|
||||
public static final int NERR_TooManyEntries = NERR_BASE + 262; /* The buffer for types is not big enough. */
|
||||
|
||||
/*
|
||||
* NetProfile
|
||||
* Error codes BASE + 270 to BASE + 276
|
||||
*/
|
||||
|
||||
public static final int NERR_ProfileFileTooBig = NERR_BASE + 270; /* Profile files cannot exceed 64K. */
|
||||
public static final int NERR_ProfileOffset = NERR_BASE + 271; /* The start offset is out of range. */
|
||||
public static final int NERR_ProfileCleanup = NERR_BASE + 272; /* The system cannot delete current connections to network resources. */
|
||||
public static final int NERR_ProfileUnknownCmd = NERR_BASE + 273; /* The system was unable to parse the command line in this file.*/
|
||||
public static final int NERR_ProfileLoadErr = NERR_BASE + 274; /* An error occurred while loading the profile file. */
|
||||
public static final int NERR_ProfileSaveErr = NERR_BASE + 275; /* @W Errors occurred while saving the profile file. The profile was partially saved. */
|
||||
|
||||
|
||||
/*
|
||||
* NetAudit and NetErrorLog
|
||||
* Error codes BASE + 277 to BASE + 279
|
||||
*/
|
||||
|
||||
public static final int NERR_LogOverflow = NERR_BASE + 277; /* Log file %1 is full. */
|
||||
public static final int NERR_LogFileChanged = NERR_BASE + 278; /* This log file has changed between reads. */
|
||||
public static final int NERR_LogFileCorrupt = NERR_BASE + 279; /* Log file %1 is corrupt. */
|
||||
|
||||
|
||||
/*
|
||||
* NetRemote
|
||||
* Error codes BASE + 280 to BASE + 299
|
||||
*/
|
||||
public static final int NERR_SourceIsDir = NERR_BASE + 280; /* The source path cannot be a directory. */
|
||||
public static final int NERR_BadSource = NERR_BASE + 281; /* The source path is illegal. */
|
||||
public static final int NERR_BadDest = NERR_BASE + 282; /* The destination path is illegal. */
|
||||
public static final int NERR_DifferentServers = NERR_BASE + 283; /* The source and destination paths are on different servers. */
|
||||
/* UNUSED BASE + 284 */
|
||||
public static final int NERR_RunSrvPaused = NERR_BASE + 285; /* The Run server you requested is paused. */
|
||||
/* UNUSED BASE + 286 */
|
||||
/* UNUSED BASE + 287 */
|
||||
/* UNUSED BASE + 288 */
|
||||
public static final int NERR_ErrCommRunSrv = NERR_BASE + 289; /* An error occurred when communicating with a Run server. */
|
||||
/* UNUSED BASE + 290 */
|
||||
public static final int NERR_ErrorExecingGhost = NERR_BASE + 291; /* An error occurred when starting a background process. */
|
||||
public static final int NERR_ShareNotFound = NERR_BASE + 292; /* The shared resource you are connected to could not be found.*/
|
||||
/* UNUSED BASE + 293 */
|
||||
/* UNUSED BASE + 294 */
|
||||
|
||||
|
||||
/*
|
||||
* NetWksta.sys = redir; returned error codes.
|
||||
*
|
||||
* NERR_BASE + = 300-329;
|
||||
*/
|
||||
|
||||
public static final int NERR_InvalidLana = NERR_BASE + 300; /* The LAN adapter number is invalid. */
|
||||
public static final int NERR_OpenFiles = NERR_BASE + 301; /* There are open files on the connection. */
|
||||
public static final int NERR_ActiveConns = NERR_BASE + 302; /* Active connections still exist. */
|
||||
public static final int NERR_BadPasswordCore = NERR_BASE + 303; /* This share name or password is invalid. */
|
||||
public static final int NERR_DevInUse = NERR_BASE + 304; /* The device is being accessed by an active process. */
|
||||
public static final int NERR_LocalDrive = NERR_BASE + 305; /* The drive letter is in use locally. */
|
||||
|
||||
/*
|
||||
* Alert error codes.
|
||||
*
|
||||
* NERR_BASE + = 330-339;
|
||||
*/
|
||||
public static final int NERR_AlertExists = NERR_BASE + 330; /* The specified client is already registered for the specified event. */
|
||||
public static final int NERR_TooManyAlerts = NERR_BASE + 331; /* The alert table is full. */
|
||||
public static final int NERR_NoSuchAlert = NERR_BASE + 332; /* An invalid or nonexistent alert name was raised. */
|
||||
public static final int NERR_BadRecipient = NERR_BASE + 333; /* The alert recipient is invalid.*/
|
||||
public static final int NERR_AcctLimitExceeded = NERR_BASE + 334; /* A user's session with this server has been deleted
|
||||
* because the user's logon hours are no longer valid. */
|
||||
|
||||
/*
|
||||
* Additional Error and Audit log codes.
|
||||
*
|
||||
* NERR_BASE + (340-343;
|
||||
*/
|
||||
public static final int NERR_InvalidLogSeek = NERR_BASE + 340; /* The log file does not contain the requested record number. */
|
||||
/* UNUSED BASE + 341 */
|
||||
/* UNUSED BASE + 342 */
|
||||
/* UNUSED BASE + 343 */
|
||||
|
||||
/*
|
||||
* Additional UAS and NETLOGON codes
|
||||
*
|
||||
* NERR_BASE + (350-359;
|
||||
*/
|
||||
public static final int NERR_BadUasConfig = NERR_BASE + 350; /* The user accounts database is not configured correctly. */
|
||||
public static final int NERR_InvalidUASOp = NERR_BASE + 351; /* This operation is not permitted when the Netlogon service is running. */
|
||||
public static final int NERR_LastAdmin = NERR_BASE + 352; /* This operation is not allowed on the last administrative account. */
|
||||
public static final int NERR_DCNotFound = NERR_BASE + 353; /* Could not find domain controller for this domain. */
|
||||
public static final int NERR_LogonTrackingError = NERR_BASE + 354; /* Could not set logon information for this user. */
|
||||
public static final int NERR_NetlogonNotStarted = NERR_BASE + 355; /* The Netlogon service has not been started. */
|
||||
public static final int NERR_CanNotGrowUASFile = NERR_BASE + 356; /* Unable to add to the user accounts database. */
|
||||
public static final int NERR_TimeDiffAtDC = NERR_BASE + 357; /* This server's clock is not synchronized with the primary domain controller's clock. */
|
||||
public static final int NERR_PasswordMismatch = NERR_BASE + 358; /* A password mismatch has been detected. */
|
||||
|
||||
|
||||
/*
|
||||
* Server Integration error codes.
|
||||
*
|
||||
* NERR_BASE + (360-369;
|
||||
*/
|
||||
public static final int NERR_NoSuchServer = NERR_BASE + 360; /* The server identification does not specify a valid server. */
|
||||
public static final int NERR_NoSuchSession = NERR_BASE + 361; /* The session identification does not specify a valid session. */
|
||||
public static final int NERR_NoSuchConnection = NERR_BASE + 362; /* The connection identification does not specify a valid connection. */
|
||||
public static final int NERR_TooManyServers = NERR_BASE + 363; /* There is no space for another entry in the table of available servers. */
|
||||
public static final int NERR_TooManySessions = NERR_BASE + 364; /* The server has reached the maximum number of sessions it supports. */
|
||||
public static final int NERR_TooManyConnections = NERR_BASE + 365; /* The server has reached the maximum number of connections it supports. */
|
||||
public static final int NERR_TooManyFiles = NERR_BASE + 366; /* The server cannot open more files because it has reached its maximum number. */
|
||||
public static final int NERR_NoAlternateServers = NERR_BASE + 367; /* There are no alternate servers registered on this server. */
|
||||
/* UNUSED BASE + 368 */
|
||||
/* UNUSED BASE + 369 */
|
||||
|
||||
public static final int NERR_TryDownLevel = NERR_BASE + 370; /* Try down-level = remote admin protocol; version of API instead. */
|
||||
|
||||
/*
|
||||
* UPS error codes.
|
||||
*
|
||||
* NERR_BASE + = 380-384;
|
||||
*/
|
||||
public static final int NERR_UPSDriverNotStarted = NERR_BASE + 380; /* The UPS driver could not be accessed by the UPS service. */
|
||||
public static final int NERR_UPSInvalidConfig = NERR_BASE + 381; /* The UPS service is not configured correctly. */
|
||||
public static final int NERR_UPSInvalidCommPort = NERR_BASE + 382; /* The UPS service could not access the specified Comm Port. */
|
||||
public static final int NERR_UPSSignalAsserted = NERR_BASE + 383; /* The UPS indicated a line fail or low battery situation. Service not started. */
|
||||
public static final int NERR_UPSShutdownFailed = NERR_BASE + 384; /* The UPS service failed to perform a system shut down. */
|
||||
|
||||
/*
|
||||
* Remoteboot error codes.
|
||||
*
|
||||
* NERR_BASE + = 400-419;
|
||||
* Error codes 400 - 405 are used by RPLBOOT.SYS.
|
||||
* Error codes 403, 407 - 416 are used by RPLLOADR.COM,
|
||||
* Error code 417 is the alerter message of REMOTEBOOT = RPLSERVR.EXE;.
|
||||
* Error code 418 is for when REMOTEBOOT can't start
|
||||
* Error code 419 is for a disallowed 2nd rpl connection
|
||||
*
|
||||
*/
|
||||
public static final int NERR_BadDosRetCode = NERR_BASE + 400; /* The program below returned an MS-DOS error code:*/
|
||||
public static final int NERR_ProgNeedsExtraMem = NERR_BASE + 401; /* The program below needs more memory:*/
|
||||
public static final int NERR_BadDosFunction = NERR_BASE + 402; /* The program below called an unsupported MS-DOS function:*/
|
||||
public static final int NERR_RemoteBootFailed = NERR_BASE + 403; /* The workstation failed to boot.*/
|
||||
public static final int NERR_BadFileCheckSum = NERR_BASE + 404; /* The file below is corrupt.*/
|
||||
public static final int NERR_NoRplBootSystem = NERR_BASE + 405; /* No loader is specified in the boot-block definition file.*/
|
||||
public static final int NERR_RplLoadrNetBiosErr = NERR_BASE + 406; /* NetBIOS returned an error: The NCB and SMB are dumped above.*/
|
||||
public static final int NERR_RplLoadrDiskErr = NERR_BASE + 407; /* A disk I/O error occurred.*/
|
||||
public static final int NERR_ImageParamErr = NERR_BASE + 408; /* Image parameter substitution failed.*/
|
||||
public static final int NERR_TooManyImageParams = NERR_BASE + 409; /* Too many image parameters cross disk sector boundaries.*/
|
||||
public static final int NERR_NonDosFloppyUsed = NERR_BASE + 410; /* The image was not generated from an MS-DOS diskette formatted with /S.*/
|
||||
public static final int NERR_RplBootRestart = NERR_BASE + 411; /* Remote boot will be restarted later.*/
|
||||
public static final int NERR_RplSrvrCallFailed = NERR_BASE + 412; /* The call to the Remoteboot server failed.*/
|
||||
public static final int NERR_CantConnectRplSrvr = NERR_BASE + 413; /* Cannot connect to the Remoteboot server.*/
|
||||
public static final int NERR_CantOpenImageFile = NERR_BASE + 414; /* Cannot open image file on the Remoteboot server.*/
|
||||
public static final int NERR_CallingRplSrvr = NERR_BASE + 415; /* Connecting to the Remoteboot server...*/
|
||||
public static final int NERR_StartingRplBoot = NERR_BASE + 416; /* Connecting to the Remoteboot server...*/
|
||||
public static final int NERR_RplBootServiceTerm = NERR_BASE + 417; /* Remote boot service was stopped; check the error log for the cause of the problem.*/
|
||||
public static final int NERR_RplBootStartFailed = NERR_BASE + 418; /* Remote boot startup failed; check the error log for the cause of the problem.*/
|
||||
public static final int NERR_RPL_CONNECTED = NERR_BASE + 419; /* A second connection to a Remoteboot resource is not allowed.*/
|
||||
|
||||
/*
|
||||
* FTADMIN API error codes
|
||||
*
|
||||
* NERR_BASE + = 425-434;
|
||||
*
|
||||
* = Currently not used in NT;
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Browser service API error codes
|
||||
*
|
||||
* NERR_BASE + = 450-475;
|
||||
*
|
||||
*/
|
||||
public static final int NERR_BrowserConfiguredToNotRun = NERR_BASE + 450; /* The browser service was configured with MaintainServerList = No. */
|
||||
|
||||
/*
|
||||
* Additional Remoteboot error codes.
|
||||
*
|
||||
* NERR_BASE + = 510-550;
|
||||
*/
|
||||
public static final int NERR_RplNoAdaptersStarted = NERR_BASE + 510; /*Service failed to start since none of the network adapters started with this service.*/
|
||||
public static final int NERR_RplBadRegistry = NERR_BASE + 511; /*Service failed to start due to bad startup information in the registry.*/
|
||||
public static final int NERR_RplBadDatabase = NERR_BASE + 512; /*Service failed to start because its database is absent or corrupt.*/
|
||||
public static final int NERR_RplRplfilesShare = NERR_BASE + 513; /*Service failed to start because RPLFILES share is absent.*/
|
||||
public static final int NERR_RplNotRplServer = NERR_BASE + 514; /*Service failed to start because RPLUSER group is absent.*/
|
||||
public static final int NERR_RplCannotEnum = NERR_BASE + 515; /*Cannot enumerate service records.*/
|
||||
public static final int NERR_RplWkstaInfoCorrupted = NERR_BASE + 516; /*Workstation record information has been corrupted.*/
|
||||
public static final int NERR_RplWkstaNotFound = NERR_BASE + 517; /*Workstation record was not found.*/
|
||||
public static final int NERR_RplWkstaNameUnavailable = NERR_BASE + 518; /*Workstation name is in use by some other workstation.*/
|
||||
public static final int NERR_RplProfileInfoCorrupted = NERR_BASE + 519; /*Profile record information has been corrupted.*/
|
||||
public static final int NERR_RplProfileNotFound = NERR_BASE + 520; /*Profile record was not found.*/
|
||||
public static final int NERR_RplProfileNameUnavailable = NERR_BASE + 521; /*Profile name is in use by some other profile.*/
|
||||
public static final int NERR_RplProfileNotEmpty = NERR_BASE + 522; /*There are workstations using this profile.*/
|
||||
public static final int NERR_RplConfigInfoCorrupted = NERR_BASE + 523; /*Configuration record information has been corrupted.*/
|
||||
public static final int NERR_RplConfigNotFound = NERR_BASE + 524; /*Configuration record was not found.*/
|
||||
public static final int NERR_RplAdapterInfoCorrupted = NERR_BASE + 525; /*Adapter id record information has been corrupted.*/
|
||||
public static final int NERR_RplInternal = NERR_BASE + 526; /*An internal service error has occurred.*/
|
||||
public static final int NERR_RplVendorInfoCorrupted = NERR_BASE + 527; /*Vendor id record information has been corrupted.*/
|
||||
public static final int NERR_RplBootInfoCorrupted = NERR_BASE + 528; /*Boot block record information has been corrupted.*/
|
||||
public static final int NERR_RplWkstaNeedsUserAcct = NERR_BASE + 529; /*The user account for this workstation record is missing.*/
|
||||
public static final int NERR_RplNeedsRPLUSERAcct = NERR_BASE + 530; /*The RPLUSER local group could not be found.*/
|
||||
public static final int NERR_RplBootNotFound = NERR_BASE + 531; /*Boot block record was not found.*/
|
||||
public static final int NERR_RplIncompatibleProfile = NERR_BASE + 532; /*Chosen profile is incompatible with this workstation.*/
|
||||
public static final int NERR_RplAdapterNameUnavailable = NERR_BASE + 533; /*Chosen network adapter id is in use by some other workstation.*/
|
||||
public static final int NERR_RplConfigNotEmpty = NERR_BASE + 534; /*There are profiles using this configuration.*/
|
||||
public static final int NERR_RplBootInUse = NERR_BASE + 535; /*There are workstations, profiles or configurations using this boot block.*/
|
||||
public static final int NERR_RplBackupDatabase = NERR_BASE + 536; /*Service failed to backup Remoteboot database.*/
|
||||
public static final int NERR_RplAdapterNotFound = NERR_BASE + 537; /*Adapter record was not found.*/
|
||||
public static final int NERR_RplVendorNotFound = NERR_BASE + 538; /*Vendor record was not found.*/
|
||||
public static final int NERR_RplVendorNameUnavailable = NERR_BASE + 539; /*Vendor name is in use by some other vendor record.*/
|
||||
public static final int NERR_RplBootNameUnavailable = NERR_BASE + 540; /*(boot name, vendor id; is in use by some other boot block record.*/
|
||||
public static final int NERR_RplConfigNameUnavailable = NERR_BASE + 541; /*Configuration name is in use by some other configuration.*/
|
||||
|
||||
/**INTERNAL_ONLY**/
|
||||
|
||||
/*
|
||||
* Dfs API error codes.
|
||||
*
|
||||
* NERR_BASE + = 560-590;
|
||||
*/
|
||||
|
||||
public static final int NERR_DfsInternalCorruption = NERR_BASE + 560; /*The internal database maintained by the DFS service is corrupt*/
|
||||
public static final int NERR_DfsVolumeDataCorrupt = NERR_BASE + 561; /*One of the records in the internal DFS database is corrupt*/
|
||||
public static final int NERR_DfsNoSuchVolume = NERR_BASE + 562; /*There is no DFS name whose entry path matches the input Entry Path*/
|
||||
public static final int NERR_DfsVolumeAlreadyExists = NERR_BASE + 563; /*A root or link with the given name already exists*/
|
||||
public static final int NERR_DfsAlreadyShared = NERR_BASE + 564; /*The server share specified is already shared in the DFS*/
|
||||
public static final int NERR_DfsNoSuchShare = NERR_BASE + 565; /*The indicated server share does not support the indicated DFS namespace*/
|
||||
public static final int NERR_DfsNotALeafVolume = NERR_BASE + 566; /*The operation is not valid on this portion of the namespace*/
|
||||
public static final int NERR_DfsLeafVolume = NERR_BASE + 567; /*The operation is not valid on this portion of the namespace*/
|
||||
public static final int NERR_DfsVolumeHasMultipleServers = NERR_BASE + 568; /*The operation is ambiguous because the link has multiple servers*/
|
||||
public static final int NERR_DfsCantCreateJunctionPoint = NERR_BASE + 569; /*Unable to create a link*/
|
||||
public static final int NERR_DfsServerNotDfsAware = NERR_BASE + 570; /*The server is not DFS Aware*/
|
||||
public static final int NERR_DfsBadRenamePath = NERR_BASE + 571; /*The specified rename target path is invalid*/
|
||||
public static final int NERR_DfsVolumeIsOffline = NERR_BASE + 572; /*The specified DFS link is offline*/
|
||||
public static final int NERR_DfsNoSuchServer = NERR_BASE + 573; /*The specified server is not a server for this link*/
|
||||
public static final int NERR_DfsCyclicalName = NERR_BASE + 574; /*A cycle in the DFS name was detected*/
|
||||
public static final int NERR_DfsNotSupportedInServerDfs = NERR_BASE + 575; /*The operation is not supported on a server-based DFS*/
|
||||
public static final int NERR_DfsDuplicateService = NERR_BASE + 576; /*This link is already supported by the specified server-share*/
|
||||
public static final int NERR_DfsCantRemoveLastServerShare = NERR_BASE + 577; /*Can't remove the last server-share supporting this root or link*/
|
||||
public static final int NERR_DfsVolumeIsInterDfs = NERR_BASE + 578; /*The operation is not supported for an Inter-DFS link*/
|
||||
public static final int NERR_DfsInconsistent = NERR_BASE + 579; /*The internal state of the DFS Service has become inconsistent*/
|
||||
public static final int NERR_DfsServerUpgraded = NERR_BASE + 580; /*The DFS Service has been installed on the specified server*/
|
||||
public static final int NERR_DfsDataIsIdentical = NERR_BASE + 581; /*The DFS data being reconciled is identical*/
|
||||
public static final int NERR_DfsCantRemoveDfsRoot = NERR_BASE + 582; /*The DFS root cannot be deleted - Uninstall DFS if required*/
|
||||
public static final int NERR_DfsChildOrParentInDfs = NERR_BASE + 583; /*A child or parent directory of the share is already in a DFS*/
|
||||
public static final int NERR_DfsInternalError = NERR_BASE + 590; /*DFS internal error*/
|
||||
|
||||
/*
|
||||
* Net setup error codes.
|
||||
*
|
||||
* NERR_BASE + = 591-600;
|
||||
*/
|
||||
public static final int NERR_SetupAlreadyJoined = NERR_BASE + 591; /*This machine is already joined to a domain.*/
|
||||
public static final int NERR_SetupNotJoined = NERR_BASE + 592; /*This machine is not currently joined to a domain.*/
|
||||
public static final int NERR_SetupDomainController = NERR_BASE + 593; /*This machine is a domain controller and cannot be unjoined from a domain.*/
|
||||
public static final int NERR_DefaultJoinRequired = NERR_BASE + 594; /*The destination domain controller does not support creating machine accounts in OUs.*/
|
||||
public static final int NERR_InvalidWorkgroupName = NERR_BASE + 595; /*The specified workgroup name is invalid.*/
|
||||
public static final int NERR_NameUsesIncompatibleCodePage = NERR_BASE + 596; /*The specified computer name is incompatible with the default language used on the domain controller.*/
|
||||
public static final int NERR_ComputerAccountNotFound = NERR_BASE + 597; /*The specified computer account could not be found. Contact an administrator to verify the account is in the domain. If the account has been deleted unjoin, reboot, and rejoin the domain.*/
|
||||
public static final int NERR_PersonalSku = NERR_BASE + 598; /*This version of Windows cannot be joined to a domain.*/
|
||||
public static final int NERR_SetupCheckDNSConfig = NERR_BASE + 599; /*An attempt to resolve the DNS name of a DC in the domain being joined has failed. Please verify this client is configured to reach a DNS server that can resolve DNS names in the target domain.*/
|
||||
|
||||
/*
|
||||
* Some Password and account error results
|
||||
*
|
||||
* NERR_BASE + = 601 - 608;
|
||||
*/
|
||||
public static final int NERR_PasswordMustChange = NERR_BASE + 601; /* Password must change at next logon */
|
||||
public static final int NERR_AccountLockedOut = NERR_BASE + 602; /* Account is locked out */
|
||||
public static final int NERR_PasswordTooLong = NERR_BASE + 603; /* Password is too long */
|
||||
public static final int NERR_PasswordNotComplexEnough = NERR_BASE + 604; /* Password doesn't meet the complexity policy */
|
||||
public static final int NERR_PasswordFilterError = NERR_BASE + 605; /* Password doesn't meet the requirements of the filter dll's */
|
||||
|
||||
/***********WARNING ****************
|
||||
*The range 2750-2799 has been *
|
||||
*allocated to the IBM LAN Server *
|
||||
***********************************/
|
||||
|
||||
/***********WARNING ****************
|
||||
*The range 2900-2999 has been *
|
||||
*reserved for Microsoft OEMs *
|
||||
***********************************/
|
||||
|
||||
public static final int MAX_NERR = NERR_BASE + 899; /* This is the last error in NERR range. */
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/* 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 com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from LMJoin.h.
|
||||
* Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface LMJoin extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* Status of a workstation.
|
||||
*/
|
||||
public abstract class NETSETUP_JOIN_STATUS {
|
||||
public static final int NetSetupUnknownStatus = 0;
|
||||
public static final int NetSetupUnjoined = 1;
|
||||
public static final int NetSetupWorkgroupName = 2;
|
||||
public static final int NetSetupDomainName = 3;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
/* 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 com.sun.jna.Memory;
|
||||
import com.sun.jna.NativeLong;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.Union;
|
||||
import com.sun.jna.platform.win32.WinNT.LARGE_INTEGER;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from NTSecApi.h
|
||||
* Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface NTSecApi extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* The LSA_UNICODE_STRING structure is used by various Local Security Authority (LSA)
|
||||
* functions to specify a Unicode string.
|
||||
*/
|
||||
public static class LSA_UNICODE_STRING extends Structure {
|
||||
public static class ByReference extends LSA_UNICODE_STRING implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the length, in bytes, of the string pointed to by the Buffer member,
|
||||
* not including the terminating null character, if any.
|
||||
*/
|
||||
public short Length;
|
||||
/**
|
||||
* Specifies the total size, in bytes, of the memory allocated for Buffer. Up to
|
||||
* MaximumLength bytes can be written into the buffer without trampling memory.
|
||||
*/
|
||||
public short MaximumLength;
|
||||
/**
|
||||
* Pointer to a wide character string. Note that the strings returned by the
|
||||
* various LSA functions might not be null terminated.
|
||||
*/
|
||||
public Pointer Buffer;
|
||||
|
||||
/**
|
||||
* String representation of the buffer.
|
||||
* @return
|
||||
* Unicode string.
|
||||
*/
|
||||
public String getString() {
|
||||
byte[] data = Buffer.getByteArray(0, Length);
|
||||
if (data.length < 2 || data[data.length - 1] != 0) {
|
||||
Memory newdata = new Memory(data.length + 2);
|
||||
newdata.write(0, data, 0, data.length);
|
||||
return newdata.getString(0, true);
|
||||
}
|
||||
return Buffer.getString(0, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to an LSA_UNICODE_STRING.
|
||||
*/
|
||||
public static class PLSA_UNICODE_STRING {
|
||||
public static class ByReference extends PLSA_UNICODE_STRING
|
||||
implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public LSA_UNICODE_STRING.ByReference s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record contains an included top-level name.
|
||||
*/
|
||||
public static final int ForestTrustTopLevelName = 0;
|
||||
/**
|
||||
* Record contains an excluded top-level name.
|
||||
*/
|
||||
public static final int ForestTrustTopLevelNameEx = 1;
|
||||
/**
|
||||
* Record contains an LSA_FOREST_TRUST_DOMAIN_INFO structure.
|
||||
*/
|
||||
public static final int ForestTrustDomainInfo = 2;
|
||||
|
||||
public static class LSA_FOREST_TRUST_DOMAIN_INFO extends Structure {
|
||||
public PSID.ByReference Sid;
|
||||
public LSA_UNICODE_STRING DnsName;
|
||||
public LSA_UNICODE_STRING NetbiosName;
|
||||
}
|
||||
|
||||
public static class LSA_FOREST_TRUST_BINARY_DATA extends Structure {
|
||||
public NativeLong Length;
|
||||
public Pointer Buffer;
|
||||
}
|
||||
|
||||
public static class LSA_FOREST_TRUST_RECORD extends Structure {
|
||||
|
||||
public static class ByReference extends LSA_FOREST_TRUST_RECORD implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public static class UNION extends Union {
|
||||
public static class ByReference extends UNION implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public LSA_UNICODE_STRING TopLevelName;
|
||||
public LSA_FOREST_TRUST_DOMAIN_INFO DomainInfo;
|
||||
public LSA_FOREST_TRUST_BINARY_DATA Data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flags that control the behavior of the operation.
|
||||
*/
|
||||
public NativeLong Flags;
|
||||
|
||||
/**
|
||||
* LSA_FOREST_TRUST_RECORD_TYPE enumeration that indicates the type of the record.
|
||||
* The following table shows the possible values.
|
||||
* ForestTrustTopLevelName
|
||||
* Record contains an included top-level name.
|
||||
* ForestTrustTopLevelNameEx
|
||||
* Record contains an excluded top-level name.
|
||||
* ForestTrustDomainInfo
|
||||
* Record contains an LSA_FOREST_TRUST_DOMAIN_INFO structure.
|
||||
* ForestTrustRecordTypeLast
|
||||
* Marks the end of an enumeration.
|
||||
*/
|
||||
public int ForestTrustType;
|
||||
public LARGE_INTEGER Time;
|
||||
|
||||
/**
|
||||
* Data type depending on ForestTrustType.
|
||||
*/
|
||||
public UNION u;
|
||||
|
||||
public void read() {
|
||||
super.read();
|
||||
|
||||
switch(ForestTrustType) {
|
||||
case NTSecApi.ForestTrustTopLevelName:
|
||||
case NTSecApi.ForestTrustTopLevelNameEx:
|
||||
u.setType(LSA_UNICODE_STRING.class);
|
||||
break;
|
||||
case NTSecApi.ForestTrustDomainInfo:
|
||||
u.setType(LSA_FOREST_TRUST_DOMAIN_INFO.class);
|
||||
break;
|
||||
default:
|
||||
u.setType(LSA_FOREST_TRUST_BINARY_DATA.class);
|
||||
break;
|
||||
}
|
||||
|
||||
u.read();
|
||||
}
|
||||
}
|
||||
|
||||
public static class PLSA_FOREST_TRUST_RECORD extends Structure {
|
||||
public static class ByReference extends PLSA_FOREST_TRUST_RECORD implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public LSA_FOREST_TRUST_RECORD.ByReference tr;
|
||||
}
|
||||
|
||||
public static class LSA_FOREST_TRUST_INFORMATION extends Structure {
|
||||
|
||||
public static class ByReference extends LSA_FOREST_TRUST_INFORMATION implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of LSA_FOREST_TRUST_RECORD structures in the array pointed to by the
|
||||
* Entries member.
|
||||
*/
|
||||
public NativeLong RecordCount;
|
||||
/**
|
||||
* Pointer to a pointer to an array of LSA_FOREST_TRUST_RECORD structures,
|
||||
* each of which contains one piece of forest trust information.
|
||||
*/
|
||||
public PLSA_FOREST_TRUST_RECORD.ByReference Entries;
|
||||
|
||||
/**
|
||||
* Get an array of LSA_FOREST_TRUST_RECORD entries.
|
||||
* @return
|
||||
* An array of forest trust records.
|
||||
*/
|
||||
public PLSA_FOREST_TRUST_RECORD[] getEntries() {
|
||||
return (PLSA_FOREST_TRUST_RECORD[]) Entries.toArray(RecordCount.intValue());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The LSA_FOREST_TRUST_INFORMATION structure contains Local Security Authority
|
||||
* forest trust information.
|
||||
*/
|
||||
public static class PLSA_FOREST_TRUST_INFORMATION extends Structure {
|
||||
|
||||
public static class ByReference extends PLSA_FOREST_TRUST_INFORMATION implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public LSA_FOREST_TRUST_INFORMATION.ByReference fti;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/* 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.win32.StdCallLibrary;
|
||||
|
||||
public interface NTStatus extends StdCallLibrary {
|
||||
|
||||
public static final int STATUS_SUCCESS = 0x00000000; // ntsubauth
|
||||
public static final int STATUS_BUFFER_TOO_SMALL = 0xC0000023;
|
||||
|
||||
//
|
||||
// MessageId: STATUS_WAIT_0
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_WAIT_0
|
||||
//
|
||||
public static final int STATUS_WAIT_0 = 0x00000000; // winnt
|
||||
|
||||
//
|
||||
// MessageId: STATUS_WAIT_1
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_WAIT_1
|
||||
//
|
||||
public static final int STATUS_WAIT_1 = 0x00000001;
|
||||
|
||||
//
|
||||
// MessageId: STATUS_WAIT_2
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_WAIT_2
|
||||
//
|
||||
public static final int STATUS_WAIT_2 = 0x00000002;
|
||||
|
||||
//
|
||||
// MessageId: STATUS_WAIT_3
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_WAIT_3
|
||||
//
|
||||
public static final int STATUS_WAIT_3 = 0x00000003;
|
||||
|
||||
//
|
||||
// MessageId: STATUS_WAIT_63
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_WAIT_63
|
||||
//
|
||||
public static final int STATUS_WAIT_63 = 0x0000003F;
|
||||
|
||||
//
|
||||
// The success status codes 128 - 191 are reserved for wait completion
|
||||
// status with an abandoned mutant object.
|
||||
//
|
||||
public static final int STATUS_ABANDONED = 0x00000080;
|
||||
|
||||
//
|
||||
// MessageId: STATUS_ABANDONED_WAIT_0
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_ABANDONED_WAIT_0
|
||||
//
|
||||
public static final int STATUS_ABANDONED_WAIT_0 = 0x00000080; // winnt
|
||||
|
||||
//
|
||||
// MessageId: STATUS_ABANDONED_WAIT_63
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_ABANDONED_WAIT_63
|
||||
//
|
||||
public static final int STATUS_ABANDONED_WAIT_63 = 0x000000BF;
|
||||
}
|
||||
@@ -0,0 +1,403 @@
|
||||
/* 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 com.sun.jna.Native;
|
||||
import com.sun.jna.NativeLong;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.DsGetDC.PDOMAIN_CONTROLLER_INFO;
|
||||
import com.sun.jna.platform.win32.DsGetDC.PDS_DOMAIN_TRUSTS;
|
||||
import com.sun.jna.platform.win32.Guid.GUID;
|
||||
import com.sun.jna.platform.win32.NTSecApi.PLSA_FOREST_TRUST_INFORMATION;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.NativeLongByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Netapi32.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Netapi32 extends StdCallLibrary {
|
||||
|
||||
Netapi32 INSTANCE = (Netapi32) Native.loadLibrary("Netapi32",
|
||||
Netapi32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* Retrieves join status information for the specified computer.
|
||||
*
|
||||
* @param lpServer
|
||||
* Specifies the DNS or NetBIOS name of the computer on which to
|
||||
* call the function.
|
||||
* @param lpNameBuffer
|
||||
* Receives the NetBIOS name of the domain or workgroup to which
|
||||
* the computer is joined.
|
||||
* @param BufferType
|
||||
* Join status of the specified computer.
|
||||
* @return If the function succeeds, the return value is NERR_Success. If
|
||||
* the function fails, the return value is a system error code.
|
||||
*/
|
||||
public int NetGetJoinInformation(String lpServer,
|
||||
PointerByReference lpNameBuffer, IntByReference BufferType);
|
||||
|
||||
/**
|
||||
* Frees the memory that the NetApiBufferAllocate function allocates.
|
||||
*
|
||||
* @param buffer
|
||||
* @return If the function succeeds, the return value is NERR_Success. If
|
||||
* the function fails, the return value is a system error code.
|
||||
*/
|
||||
public int NetApiBufferFree(Pointer buffer);
|
||||
|
||||
/**
|
||||
* Returns information about each local group account on the specified
|
||||
* server.
|
||||
*
|
||||
* @param serverName
|
||||
* Specifies the DNS or NetBIOS name of the remote server on
|
||||
* which the function is to execute. If this parameter is NULL,
|
||||
* the local computer is used.
|
||||
* @param level
|
||||
* Specifies the information level of the data.
|
||||
* @param bufptr
|
||||
* Pointer to the address of the buffer that receives the
|
||||
* information structure.
|
||||
* @param prefmaxlen
|
||||
* Specifies the preferred maximum length of returned data, in
|
||||
* bytes.
|
||||
* @param entriesread
|
||||
* Pointer to a value that receives the count of elements
|
||||
* actually enumerated.
|
||||
* @param totalentries
|
||||
* Pointer to a value that receives the approximate total number
|
||||
* of entries that could have been enumerated from the current
|
||||
* resume position.
|
||||
* @param resume_handle
|
||||
* Pointer to a value that contains a resume handle that is used
|
||||
* to continue an existing local group search.
|
||||
* @return If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetLocalGroupEnum(String serverName, int level,
|
||||
PointerByReference bufptr, int prefmaxlen,
|
||||
IntByReference entriesread, IntByReference totalentries,
|
||||
IntByReference resume_handle);
|
||||
|
||||
/**
|
||||
* Returns the name of the primary domain controller (PDC).
|
||||
*
|
||||
* @param serverName
|
||||
* Specifies the DNS or NetBIOS name of the remote server on which the function is
|
||||
* to execute. If this parameter is NULL, the local computer is used.
|
||||
* @param domainName
|
||||
* Specifies the name of the domain.
|
||||
* @param bufptr
|
||||
* Receives a string that specifies the server name of the PDC of the domain.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetGetDCName(String serverName, String domainName,
|
||||
PointerByReference bufptr);
|
||||
|
||||
/**
|
||||
* The NetGroupEnum function retrieves information about each global group
|
||||
* in the security database, which is the security accounts manager (SAM) database or,
|
||||
* in the case of domain controllers, the Active Directory.
|
||||
* @param servername
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of the
|
||||
* remote server on which the function is to execute. If this parameter is NULL,
|
||||
* the local computer is used.
|
||||
* @param level
|
||||
* Specifies the information level of the data.
|
||||
* @param bufptr
|
||||
* Pointer to the buffer to receive the global group information structure.
|
||||
* The format of this data depends on the value of the level parameter.
|
||||
* @param prefmaxlen
|
||||
* Specifies the preferred maximum length of the returned data, in bytes.
|
||||
* If you specify MAX_PREFERRED_LENGTH, the function allocates the amount of
|
||||
* memory required to hold the data. If you specify another value in this
|
||||
* parameter, it can restrict the number of bytes that the function returns.
|
||||
* If the buffer size is insufficient to hold all entries, the function
|
||||
* returns ERROR_MORE_DATA.
|
||||
* @param entriesread
|
||||
* Pointer to a value that receives the count of elements actually enumerated.
|
||||
* @param totalentries
|
||||
* Pointer to a value that receives the total number of entries that could have
|
||||
* been enumerated from the current resume position. The total number of entries
|
||||
* is only a hint.
|
||||
* @param resume_handle
|
||||
* Pointer to a variable that contains a resume handle that is used to continue
|
||||
* the global group enumeration. The handle should be zero on the first call and
|
||||
* left unchanged for subsequent calls. If resume_handle is NULL, no resume handle
|
||||
* is stored.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetGroupEnum(String servername, int level, PointerByReference bufptr,
|
||||
int prefmaxlen, IntByReference entriesread, IntByReference totalentries,
|
||||
IntByReference resume_handle);
|
||||
|
||||
/**
|
||||
* The NetUserEnum function provides information about all user accounts on a server.
|
||||
* @param servername
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of the
|
||||
* remote server on which the function is to execute. If this parameter is NULL,
|
||||
* the local computer is used.
|
||||
* @param level
|
||||
* Specifies the information level of the data.
|
||||
* @param filter
|
||||
* Specifies a value that filters the account types for enumeration.
|
||||
* @param bufptr
|
||||
* Pointer to the buffer that receives the data. The format of this data depends
|
||||
* on the value of the level parameter. This buffer is allocated by the system and
|
||||
* must be freed using the NetApiBufferFree function. Note that you must free the
|
||||
* buffer even if the function fails with ERROR_MORE_DATA.
|
||||
* @param prefmaxlen
|
||||
* Specifies the preferred maximum length, in 8-bit bytes of returned data. If you
|
||||
* specify MAX_PREFERRED_LENGTH, the function allocates the amount of memory
|
||||
* required for the data. If you specify another value in this parameter, it can
|
||||
* restrict the number of bytes that the function returns. If the buffer size is
|
||||
* insufficient to hold all entries, the function returns ERROR_MORE_DATA.
|
||||
* @param entriesread
|
||||
* Pointer to a value that receives the count of elements actually enumerated.
|
||||
* @param totalentries
|
||||
* Pointer to a value that receives the total number of entries that could have
|
||||
* been enumerated from the current resume position. Note that applications should
|
||||
* consider this value only as a hint.
|
||||
* @param resume_handle
|
||||
* Pointer to a value that contains a resume handle which is used to continue an
|
||||
* existing user search. The handle should be zero on the first call and left
|
||||
* unchanged for subsequent calls. If resume_handle is NULL, then no resume
|
||||
* handle is stored.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserEnum(String servername, int level, int filter, PointerByReference bufptr,
|
||||
int prefmaxlen, IntByReference entriesread, IntByReference totalentries,
|
||||
IntByReference resume_handle);
|
||||
|
||||
/**
|
||||
* The NetUserGetGroups function retrieves a list of global groups to which a
|
||||
* specified user belongs.
|
||||
* @param servername
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of the
|
||||
* remote server on which the function is to execute. If this parameter is NULL,
|
||||
* the local computer is used.
|
||||
* @param username
|
||||
* Pointer to a constant string that specifies the name of the user to search for
|
||||
* in each group account. For more information, see the following Remarks section.
|
||||
* @param level
|
||||
* Specifies the information level of the data.
|
||||
* @param bufptr
|
||||
* Pointer to the buffer that receives the data. This buffer is allocated by the
|
||||
* system and must be freed using the NetApiBufferFree function. Note that you must
|
||||
* free the buffer even if the function fails with ERROR_MORE_DATA.
|
||||
* @param prefmaxlen
|
||||
* Specifies the preferred maximum length of returned data, in bytes. If you specify
|
||||
* MAX_PREFERRED_LENGTH, the function allocates the amount of memory required for the
|
||||
* data. If you specify another value in this parameter, it can restrict the number
|
||||
* of bytes that the function returns. If the buffer size is insufficient to hold
|
||||
* all entries, the function returns ERROR_MORE_DATA.
|
||||
* @param entriesread
|
||||
* Pointer to a value that receives the count of elements actually retrieved.
|
||||
* @param totalentries
|
||||
* Pointer to a value that receives the total number of entries that could have been retrieved.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserGetGroups(String servername, String username, int level,
|
||||
PointerByReference bufptr, int prefmaxlen,
|
||||
IntByReference entriesread, IntByReference totalentries);
|
||||
|
||||
/**
|
||||
* The NetUserGetLocalGroups function retrieves a list of local groups to which a
|
||||
* specified user belongs.
|
||||
* @param servername
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of the remote
|
||||
* server on which the function is to execute. If this parameter is NULL, the local
|
||||
* computer is used.
|
||||
* @param username
|
||||
* Pointer to a constant string that specifies the name of the user for which to return
|
||||
* local group membership information. If the string is of the form DomainName\UserName
|
||||
* the user name is expected to be found on that domain. If the string is of the form
|
||||
* UserName, the user name is expected to be found on the server specified by the
|
||||
* servername parameter.
|
||||
* @param level
|
||||
* Specifies the information level of the data.
|
||||
* @param flags
|
||||
* Specifies a bitmask of flags. Currently, only the value LG_INCLUDE_INDIRECT is
|
||||
* defined. If this bit is set, the function also returns the names of the local
|
||||
* groups in which the user is indirectly a member (that is, the user has membership
|
||||
* in a global group that is itself a member of one or more local groups).
|
||||
* @param bufptr
|
||||
* Pointer to the buffer that receives the data. The format of this data depends on
|
||||
* the value of the level parameter. This buffer is allocated by the system and must
|
||||
* be freed using the NetApiBufferFree function. Note that you must free the buffer
|
||||
* even if the function fails with ERROR_MORE_DATA.
|
||||
* @param prefmaxlen
|
||||
* Specifies the preferred maximum length of returned data, in bytes. If you specify
|
||||
* MAX_PREFERRED_LENGTH, the function allocates the amount of memory required for the
|
||||
* data. If you specify another value in this parameter, it can restrict the number of
|
||||
* bytes that the function returns. If the buffer size is insufficient to hold all
|
||||
* entries, the function returns ERROR_MORE_DATA. For more information, see Network
|
||||
* Management Function Buffers and Network Management Function Buffer Lengths.
|
||||
* @param entriesread
|
||||
* Pointer to a value that receives the count of elements actually enumerated.
|
||||
* @param totalentries
|
||||
* Pointer to a value that receives the total number of entries that could have been enumerated.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserGetLocalGroups(String servername, String username, int level,
|
||||
int flags, PointerByReference bufptr, int prefmaxlen,
|
||||
IntByReference entriesread, IntByReference totalentries);
|
||||
|
||||
/**
|
||||
* The NetUserAdd function adds a user account and assigns a password and privilege level.
|
||||
* @param servername
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of the remote server
|
||||
* on which the function is to execute.
|
||||
* @param level
|
||||
* Specifies the information level of the data.
|
||||
* @param buf
|
||||
* Pointer to the buffer that specifies the data. The format of this data depends on the
|
||||
* value of the level parameter.
|
||||
* @param parm_err
|
||||
* Pointer to a value that receives the index of the first member of the user information
|
||||
* structure that causes ERROR_INVALID_PARAMETER. If this parameter is NULL, the index is
|
||||
* not returned on error.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserAdd(String servername, int level,
|
||||
Structure buf, IntByReference parm_err);
|
||||
|
||||
|
||||
/**
|
||||
* The NetUserDel function deletes a user account from a server.
|
||||
* @param servername
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of the remote
|
||||
* server on which the function is to execute. If this parameter is NULL, the local
|
||||
* computer is used.
|
||||
* @param username
|
||||
* Pointer to a constant string that specifies the name of the user account to delete.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserDel(String servername, String username);
|
||||
|
||||
/**
|
||||
* The NetUserChangePassword function changes a user's password for a specified
|
||||
* network server or domain.
|
||||
* @param domainname
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of a remote
|
||||
* server or domain on which the function is to execute. If this parameter is NULL,
|
||||
* the logon domain of the caller is used.
|
||||
* @param username
|
||||
* Pointer to a constant string that specifies a user name. The NetUserChangePassword
|
||||
* function changes the password for the specified user. If this parameter is NULL,
|
||||
* the logon name of the caller is used.
|
||||
* @param oldpassword
|
||||
* Pointer to a constant string that specifies the user's old password.
|
||||
* @param newpassword
|
||||
* Pointer to a constant string that specifies the user's new password.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserChangePassword(String domainname, String username,
|
||||
String oldpassword, String newpassword);
|
||||
|
||||
/**
|
||||
* The DsGetDcName function returns the name of a domain controller in a specified domain.
|
||||
* This function accepts additional domain controller selection criteria to indicate
|
||||
* preference for a domain controller with particular characteristics.
|
||||
* @param ComputerName
|
||||
* Pointer to a null-terminated string that specifies the name of the server to process
|
||||
* this function. Typically, this parameter is NULL, which indicates that the local
|
||||
* computer is used.
|
||||
* @param DomainName
|
||||
* Pointer to a null-terminated string that specifies the name of the domain or application
|
||||
* partition to query. This name can either be a DNS style name, for example, fabrikam.com,
|
||||
* or a flat-style name, for example, Fabrikam. If a DNS style name is specified, the name
|
||||
* may be specified with or without a trailing period.
|
||||
* @param DomainGuid
|
||||
* Pointer to a GUID structure that specifies the GUID of the domain queried. If DomainGuid
|
||||
* is not NULL and the domain specified by DomainName or ComputerName cannot be found,
|
||||
* DsGetDcName attempts to locate a domain controller in the domain having the GUID specified
|
||||
* by DomainGuid.
|
||||
* @param SiteName
|
||||
* Pointer to a null-terminated string that specifies the name of the site where the returned
|
||||
* domain controller should physically exist. If this parameter is NULL, DsGetDcName attempts
|
||||
* to return a domain controller in the site closest to the site of the computer specified by
|
||||
* ComputerName. This parameter should be NULL, by default.
|
||||
* @param Flags
|
||||
* Contains a set of flags that provide additional data used to process the request.
|
||||
* @param DomainControllerInfo
|
||||
* Pointer to a PDOMAIN_CONTROLLER_INFO value that receives a pointer to a
|
||||
* DOMAIN_CONTROLLER_INFO structure that contains data about the domain controller selected.
|
||||
* This structure is allocated by DsGetDcName. The caller must free the structure using
|
||||
* the NetApiBufferFree function when it is no longer required.
|
||||
* @return
|
||||
* If the function returns domain controller data, the return value is ERROR_SUCCESS.
|
||||
* If the function fails, the return code is one of ERROR_* values.
|
||||
*/
|
||||
public int DsGetDcName(String ComputerName, String DomainName, GUID DomainGuid,
|
||||
String SiteName, int Flags, PDOMAIN_CONTROLLER_INFO.ByReference DomainControllerInfo);
|
||||
|
||||
/**
|
||||
* The DsGetForestTrustInformationW function obtains forest trust data for a specified domain.
|
||||
* @param serverName
|
||||
* Contains the name of the domain controller that DsGetForestTrustInformationW
|
||||
* is connected to remotely. The caller must be an authenticated user on this server.
|
||||
* If this parameter is NULL, the local server is used.
|
||||
* @param trustedDomainName
|
||||
* Contains the NETBIOS or DNS name of the trusted domain that the forest trust data
|
||||
* is to be retrieved for. This domain must have the TRUST_ATTRIBUTE_FOREST_TRANSITIVE
|
||||
* trust attribute. If this parameter is NULL, the forest trust data for the domain
|
||||
* hosted by ServerName is retrieved.
|
||||
* @param Flags
|
||||
* Contains a set of flags that modify the behavior of this function.
|
||||
* DS_GFTI_UPDATE_TDO: If this flag is set, DsGetForestTrustInformationW will update the
|
||||
* forest trust data of the trusted domain identified by the TrustedDomainName parameter.
|
||||
* @param ForestTrustInfo
|
||||
* Pointer to an LSA_FOREST_TRUST_INFORMATION structure pointer that receives the forest
|
||||
* trust data that describes the namespaces claimed by the domain specified by
|
||||
* TrustedDomainName. The Time member of all returned records will be zero.
|
||||
* @return
|
||||
* Returns NO_ERROR if successful or a Win32 error code otherwise.
|
||||
*/
|
||||
public int DsGetForestTrustInformation(String serverName, String trustedDomainName, int Flags,
|
||||
PLSA_FOREST_TRUST_INFORMATION.ByReference ForestTrustInfo);
|
||||
|
||||
/**
|
||||
* The DsEnumerateDomainTrusts function obtains domain trust data for a specified domain.
|
||||
* @param serverName
|
||||
* Pointer to a null-terminated string that specifies the name of a computer in the domain to
|
||||
* obtain the trust information for. This computer must be running the Windows 2000 or later
|
||||
* operating system. If this parameter is NULL, the name of the local computer is used.
|
||||
* The caller must be an authenticated user in this domain.
|
||||
* @param Flags
|
||||
* Contains a set of flags that determines which domain trusts to enumerate.
|
||||
* @param Domains
|
||||
* Pointer to a PDS_DOMAIN_TRUSTS value that receives an array of DS_DOMAIN_TRUSTS structures.
|
||||
* Each structure in this array contains trust data about a domain. The caller must free this
|
||||
* memory when it is no longer required by calling NetApiBufferFree.
|
||||
* @param DomainCount
|
||||
* Pointer to a ULONG value that receives the number of elements returned in the Domains array.
|
||||
* @return
|
||||
* Returns ERROR_SUCCESS if successful or a Win32 error code otherwise.
|
||||
*/
|
||||
public int DsEnumerateDomainTrusts(String serverName, NativeLong Flags,
|
||||
PDS_DOMAIN_TRUSTS.ByReference Domains, NativeLongByReference DomainCount);
|
||||
}
|
||||
@@ -0,0 +1,605 @@
|
||||
/* 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.ArrayList;
|
||||
|
||||
import com.sun.jna.NativeLong;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.DsGetDC.DS_DOMAIN_TRUSTS;
|
||||
import com.sun.jna.platform.win32.DsGetDC.PDOMAIN_CONTROLLER_INFO;
|
||||
import com.sun.jna.platform.win32.DsGetDC.PDS_DOMAIN_TRUSTS;
|
||||
import com.sun.jna.platform.win32.Guid.GUID;
|
||||
import com.sun.jna.platform.win32.LMAccess.GROUP_USERS_INFO_0;
|
||||
import com.sun.jna.platform.win32.LMAccess.LOCALGROUP_INFO_1;
|
||||
import com.sun.jna.platform.win32.LMAccess.LOCALGROUP_USERS_INFO_0;
|
||||
import com.sun.jna.platform.win32.Secur32.EXTENDED_NAME_FORMAT;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.NativeLongByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* Netapi32 Utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Netapi32Util {
|
||||
|
||||
/**
|
||||
* A group.
|
||||
*/
|
||||
public static class Group {
|
||||
/**
|
||||
* Group name.
|
||||
*/
|
||||
public String name;
|
||||
}
|
||||
|
||||
/**
|
||||
* A user.
|
||||
*/
|
||||
public static class User {
|
||||
/**
|
||||
* The name of the user account.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* Contains a comment associated with the user account.
|
||||
*/
|
||||
public String comment;
|
||||
}
|
||||
/**
|
||||
* A local group.
|
||||
*/
|
||||
public static class LocalGroup extends Group {
|
||||
/**
|
||||
* Group comment.
|
||||
*/
|
||||
public String comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the primary domain controller (PDC) on the current computer.
|
||||
* @return The name of the primary domain controller.
|
||||
*/
|
||||
public static String getDCName() {
|
||||
return getDCName(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the primary domain controller (PDC).
|
||||
* @param serverName
|
||||
* Specifies the DNS or NetBIOS name of the remote server on which the function is
|
||||
* to execute.
|
||||
* @param domainName
|
||||
* Specifies the name of the domain.
|
||||
* @return
|
||||
* Name of the primary domain controller.
|
||||
*/
|
||||
public static String getDCName(String serverName, String domainName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetGetDCName(domainName, serverName, bufptr);
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return bufptr.getValue().getString(0, true);
|
||||
} finally {
|
||||
if (W32Errors.ERROR_SUCCESS != Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue())) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the domain/workgroup join status for a computer.
|
||||
* @return Join status.
|
||||
*/
|
||||
public static int getJoinStatus() {
|
||||
return getJoinStatus(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the domain/workgroup join status for a computer.
|
||||
* @param computerName Computer name.
|
||||
* @return Join status.
|
||||
*/
|
||||
public static int getJoinStatus(String computerName) {
|
||||
PointerByReference lpNameBuffer = new PointerByReference();
|
||||
IntByReference bufferType = new IntByReference();
|
||||
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetGetJoinInformation(computerName, lpNameBuffer, bufferType);
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return bufferType.getValue();
|
||||
} finally {
|
||||
if (lpNameBuffer.getPointer() != null) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(lpNameBuffer.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about a computer.
|
||||
* @param computerName
|
||||
* @return Domain or workgroup name.
|
||||
*/
|
||||
public static String getDomainName(String computerName) {
|
||||
PointerByReference lpNameBuffer = new PointerByReference();
|
||||
IntByReference bufferType = new IntByReference();
|
||||
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetGetJoinInformation(computerName, lpNameBuffer, bufferType);
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
// type of domain: bufferType.getValue()
|
||||
return lpNameBuffer.getValue().getString(0, true);
|
||||
} finally {
|
||||
if (lpNameBuffer.getPointer() != null) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(lpNameBuffer.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of local groups on the current computer.
|
||||
* @return An array of local group names.
|
||||
*/
|
||||
public static LocalGroup[] getLocalGroups() {
|
||||
return getLocalGroups(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of local groups on a computer.
|
||||
* @param serverName Name of the computer.
|
||||
* @return An array of local group names.
|
||||
*/
|
||||
public static LocalGroup[] getLocalGroups(String serverName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesRead = new IntByReference();
|
||||
IntByReference totalEntries = new IntByReference();
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetLocalGroupEnum(serverName, 1, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesRead, totalEntries, null);
|
||||
if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
LMAccess.LOCALGROUP_INFO_1 group = new LMAccess.LOCALGROUP_INFO_1(bufptr.getValue());
|
||||
LMAccess.LOCALGROUP_INFO_1[] groups = (LOCALGROUP_INFO_1[]) group.toArray(entriesRead.getValue());
|
||||
|
||||
ArrayList<LocalGroup> result = new ArrayList<LocalGroup>();
|
||||
for(LOCALGROUP_INFO_1 lgpi : groups) {
|
||||
LocalGroup lgp = new LocalGroup();
|
||||
lgp.name = lgpi.lgrui1_name.toString();
|
||||
lgp.comment = lgpi.lgrui1_comment.toString();;
|
||||
result.add(lgp);
|
||||
}
|
||||
return result.toArray(new LocalGroup[0]);
|
||||
} finally {
|
||||
if (bufptr.getValue() != Pointer.NULL) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of global groups on a computer.
|
||||
* @return An array of group names.
|
||||
*/
|
||||
public static Group[] getGlobalGroups() {
|
||||
return getGlobalGroups(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of global groups on a computer.
|
||||
* @param serverName Name of the computer.
|
||||
* @return An array of group names.
|
||||
*/
|
||||
public static Group[] getGlobalGroups(String serverName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesRead = new IntByReference();
|
||||
IntByReference totalEntries = new IntByReference();
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetGroupEnum(serverName, 1, bufptr,
|
||||
LMCons.MAX_PREFERRED_LENGTH, entriesRead,
|
||||
totalEntries, null);
|
||||
if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
LMAccess.GROUP_INFO_1 group = new LMAccess.GROUP_INFO_1(bufptr.getValue());
|
||||
LMAccess.GROUP_INFO_1[] groups = (LMAccess.GROUP_INFO_1[]) group.toArray(entriesRead.getValue());
|
||||
|
||||
ArrayList<LocalGroup> result = new ArrayList<LocalGroup>();
|
||||
for(LMAccess.GROUP_INFO_1 lgpi : groups) {
|
||||
LocalGroup lgp = new LocalGroup();
|
||||
lgp.name = lgpi.grpi1_name.toString();
|
||||
lgp.comment = lgpi.grpi1_comment.toString();;
|
||||
result.add(lgp);
|
||||
}
|
||||
return result.toArray(new LocalGroup[0]);
|
||||
} finally {
|
||||
if (bufptr.getValue() != Pointer.NULL) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of users on a local computer.
|
||||
* @return Users.
|
||||
*/
|
||||
public static User[] getUsers() {
|
||||
return getUsers(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of users on a computer.
|
||||
* @param serverName Name of the computer.
|
||||
* @return An array of users.
|
||||
*/
|
||||
public static User[] getUsers(String serverName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesRead = new IntByReference();
|
||||
IntByReference totalEntries = new IntByReference();
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetUserEnum(serverName, 1, 0, bufptr,
|
||||
LMCons.MAX_PREFERRED_LENGTH, entriesRead,
|
||||
totalEntries, null);
|
||||
if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
LMAccess.USER_INFO_1 user = new LMAccess.USER_INFO_1(bufptr.getValue());
|
||||
LMAccess.USER_INFO_1[] users = (LMAccess.USER_INFO_1[]) user.toArray(entriesRead.getValue());
|
||||
|
||||
ArrayList<User> result = new ArrayList<User>();
|
||||
for(LMAccess.USER_INFO_1 lu : users) {
|
||||
User auser = new User();
|
||||
auser.name = lu.usri1_name.toString();
|
||||
result.add(auser);
|
||||
}
|
||||
return result.toArray(new User[0]);
|
||||
} finally {
|
||||
if (bufptr.getValue() != Pointer.NULL) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local groups of the current user.
|
||||
* @return Local groups.
|
||||
*/
|
||||
public static Group[] getCurrentUserLocalGroups() {
|
||||
return getUserLocalGroups(Secur32Util.getUserNameEx(
|
||||
EXTENDED_NAME_FORMAT.NameSamCompatible));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local groups of a given user.
|
||||
* @param userName User name.
|
||||
* @return Local groups.
|
||||
*/
|
||||
public static Group[] getUserLocalGroups(String userName) {
|
||||
return getUserLocalGroups(userName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local groups of a given user on a given system.
|
||||
* @param userName User name.
|
||||
* @param serverName Server name.
|
||||
* @return Local groups.
|
||||
*/
|
||||
public static Group[] getUserLocalGroups(String userName, String serverName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesread = new IntByReference();
|
||||
IntByReference totalentries = new IntByReference();
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetUserGetLocalGroups(serverName, userName,
|
||||
0, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries);
|
||||
if (rc != LMErr.NERR_Success) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
LOCALGROUP_USERS_INFO_0 lgroup = new LOCALGROUP_USERS_INFO_0(bufptr.getValue());
|
||||
LOCALGROUP_USERS_INFO_0[] lgroups = (LOCALGROUP_USERS_INFO_0[]) lgroup.toArray(entriesread.getValue());
|
||||
ArrayList<Group> result = new ArrayList<Group>();
|
||||
for (LOCALGROUP_USERS_INFO_0 lgpi : lgroups) {
|
||||
LocalGroup lgp = new LocalGroup();
|
||||
lgp.name = lgpi.lgrui0_name.toString();
|
||||
result.add(lgp);
|
||||
}
|
||||
return result.toArray(new Group[0]);
|
||||
} finally {
|
||||
if (bufptr.getValue() != Pointer.NULL) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get groups of a given user.
|
||||
* @param userName User name.
|
||||
* @return Groups.
|
||||
*/
|
||||
public static Group[] getUserGroups(String userName) {
|
||||
return getUserGroups(userName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get groups of a given user on a given system.
|
||||
* @param userName User name.
|
||||
* @param serverName Server name.
|
||||
* @return Groups.
|
||||
*/
|
||||
public static Group[] getUserGroups(String userName, String serverName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesread = new IntByReference();
|
||||
IntByReference totalentries = new IntByReference();
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetUserGetGroups(serverName, userName,
|
||||
0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries);
|
||||
if (rc != LMErr.NERR_Success) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
GROUP_USERS_INFO_0 lgroup = new GROUP_USERS_INFO_0(bufptr.getValue());
|
||||
GROUP_USERS_INFO_0[] lgroups = (GROUP_USERS_INFO_0[]) lgroup.toArray(entriesread.getValue());
|
||||
ArrayList<Group> result = new ArrayList<Group>();
|
||||
for (GROUP_USERS_INFO_0 lgpi : lgroups) {
|
||||
Group lgp = new Group();
|
||||
lgp.name = lgpi.grui0_name.toString();
|
||||
result.add(lgp);
|
||||
}
|
||||
return result.toArray(new Group[0]);
|
||||
} finally {
|
||||
if (bufptr.getValue() != Pointer.NULL) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A domain controller.
|
||||
*/
|
||||
public static class DomainController {
|
||||
/**
|
||||
* Specifies the computer name of the discovered domain controller.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* Specifies the address of the discovered domain controller.
|
||||
*/
|
||||
public String address;
|
||||
/**
|
||||
* Indicates the type of WString that is contained in the
|
||||
* DomainControllerAddress member.
|
||||
*/
|
||||
public int addressType;
|
||||
/**
|
||||
* The GUID of the domain.
|
||||
*/
|
||||
public GUID domainGuid;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the domain.
|
||||
*/
|
||||
public String domainName;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the domain at the root
|
||||
* of the DS tree.
|
||||
*/
|
||||
public String dnsForestName;
|
||||
/**
|
||||
* Contains a set of flags that describe the domain controller.
|
||||
*/
|
||||
public int flags;
|
||||
/**
|
||||
* The name of the site that the computer belongs to.
|
||||
*/
|
||||
public String clientSiteName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the domain controller for a current computer.
|
||||
* @return
|
||||
* Domain controller information.
|
||||
*/
|
||||
public static DomainController getDC() {
|
||||
PDOMAIN_CONTROLLER_INFO.ByReference pdci = new PDOMAIN_CONTROLLER_INFO.ByReference();
|
||||
int rc = Netapi32.INSTANCE.DsGetDcName(null, null, null, null, 0, pdci);
|
||||
if (W32Errors.ERROR_SUCCESS != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
DomainController dc = new DomainController();
|
||||
dc.address = pdci.dci.DomainControllerAddress.toString();
|
||||
dc.addressType = pdci.dci.DomainControllerAddressType;
|
||||
dc.clientSiteName = pdci.dci.ClientSiteName.toString();
|
||||
dc.dnsForestName = pdci.dci.DnsForestName.toString();
|
||||
dc.domainGuid = pdci.dci.DomainGuid;
|
||||
dc.domainName = pdci.dci.DomainName.toString();
|
||||
dc.flags = pdci.dci.Flags;
|
||||
dc.name = pdci.dci.DomainControllerName.toString();
|
||||
rc = Netapi32.INSTANCE.NetApiBufferFree(pdci.getPointer());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return dc;
|
||||
}
|
||||
|
||||
/**
|
||||
* A domain trust relationship.
|
||||
*/
|
||||
public static class DomainTrust {
|
||||
/**
|
||||
* NetBIOS name of the domain.
|
||||
*/
|
||||
public String NetbiosDomainName;
|
||||
/**
|
||||
* DNS name of the domain.
|
||||
*/
|
||||
public String DnsDomainName;
|
||||
/**
|
||||
* Contains the security identifier of the domain represented by this structure.
|
||||
*/
|
||||
public PSID DomainSid;
|
||||
/**
|
||||
* Contains the string representation of the security identifier of the domain
|
||||
* represented by this structure.
|
||||
*/
|
||||
public String DomainSidString;
|
||||
/**
|
||||
* Contains the GUID of the domain represented by this structure.
|
||||
*/
|
||||
public GUID DomainGuid;
|
||||
/**
|
||||
* Contains the string representation of the GUID of the domain represented by
|
||||
* this structure.
|
||||
*/
|
||||
public String DomainGuidString;
|
||||
|
||||
/**
|
||||
* Contains a set of flags that specify more data about the domain trust.
|
||||
*/
|
||||
private int flags;
|
||||
|
||||
/**
|
||||
* The domain represented by this structure is a member of the same forest
|
||||
* as the server specified in the ServerName parameter of the
|
||||
* DsEnumerateDomainTrusts function.
|
||||
* @return
|
||||
* True or false.
|
||||
*/
|
||||
public boolean isInForest() {
|
||||
return (flags & DsGetDC.DS_DOMAIN_IN_FOREST) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The domain represented by this structure is directly trusted by the domain
|
||||
* that the server specified in the ServerName parameter of the
|
||||
* DsEnumerateDomainTrusts function is a member of.
|
||||
* @return
|
||||
* True or false.
|
||||
*/
|
||||
public boolean isOutbound() {
|
||||
return (flags & DsGetDC.DS_DOMAIN_DIRECT_OUTBOUND) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The domain represented by this structure is the root of a tree and a member
|
||||
* of the same forest as the server specified in the ServerName parameter of the
|
||||
* DsEnumerateDomainTrusts function.
|
||||
* @return
|
||||
* True or false.
|
||||
*/
|
||||
public boolean isRoot() {
|
||||
return (flags & DsGetDC.DS_DOMAIN_TREE_ROOT) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The domain represented by this structure is the primary domain of the server
|
||||
* specified in the ServerName parameter of the DsEnumerateDomainTrusts function.
|
||||
* @return
|
||||
* True or false.
|
||||
*/
|
||||
public boolean isPrimary() {
|
||||
return (flags & DsGetDC.DS_DOMAIN_PRIMARY) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The domain represented by this structure is running in the Windows 2000 native mode.
|
||||
* @return
|
||||
* True or false.
|
||||
*/
|
||||
public boolean isNativeMode() {
|
||||
return (flags & DsGetDC.DS_DOMAIN_NATIVE_MODE) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The domain represented by this structure directly trusts the domain that
|
||||
* the server specified in the ServerName parameter of the DsEnumerateDomainTrusts
|
||||
* function is a member of.
|
||||
* @return
|
||||
* True or false.
|
||||
*/
|
||||
public boolean isInbound() {
|
||||
return (flags & DsGetDC.DS_DOMAIN_DIRECT_INBOUND) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all domain trusts.
|
||||
* @return
|
||||
* An array of domain trusts.
|
||||
*/
|
||||
public static DomainTrust[] getDomainTrusts() {
|
||||
return getDomainTrusts(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all domain trusts for a given server.
|
||||
* @param serverName
|
||||
* Server name.
|
||||
* @return
|
||||
* An array of domain trusts.
|
||||
*/
|
||||
public static DomainTrust[] getDomainTrusts(String serverName) {
|
||||
NativeLongByReference domainCount = new NativeLongByReference();
|
||||
PDS_DOMAIN_TRUSTS.ByReference domains = new PDS_DOMAIN_TRUSTS.ByReference();
|
||||
int rc = Netapi32.INSTANCE.DsEnumerateDomainTrusts(
|
||||
serverName, new NativeLong(DsGetDC.DS_DOMAIN_VALID_FLAGS), domains, domainCount);
|
||||
if(W32Errors.NO_ERROR != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
int domainCountValue = domainCount.getValue().intValue();
|
||||
ArrayList<DomainTrust> trusts = new ArrayList<DomainTrust>(domainCountValue);
|
||||
for(DS_DOMAIN_TRUSTS trust : domains.getTrusts(domainCountValue)) {
|
||||
DomainTrust t = new DomainTrust();
|
||||
t.DnsDomainName = trust.DnsDomainName.toString();
|
||||
t.NetbiosDomainName = trust.NetbiosDomainName.toString();
|
||||
t.DomainSid = trust.DomainSid;
|
||||
t.DomainSidString = Advapi32Util.convertSidToStringSid(trust.DomainSid);
|
||||
t.DomainGuid = trust.DomainGuid;
|
||||
t.DomainGuidString = Ole32Util.getStringFromGUID(trust.DomainGuid);
|
||||
t.flags = trust.Flags.intValue();
|
||||
trusts.add(t);
|
||||
}
|
||||
return trusts.toArray(new DomainTrust[0]);
|
||||
} finally {
|
||||
rc = Netapi32.INSTANCE.NetApiBufferFree(domains.getPointer());
|
||||
if(W32Errors.NO_ERROR != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/* 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 com.sun.jna.Native;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* ntdll.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface NtDll extends StdCallLibrary {
|
||||
|
||||
NtDll INSTANCE = (NtDll) Native.loadLibrary("NtDll",
|
||||
NtDll.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* The ZwQueryKey routine provides information about the class of a registry key,
|
||||
* and the number and sizes of its subkeys.
|
||||
* @param KeyHandle
|
||||
* Handle to the registry key to obtain information about. This handle is created by
|
||||
* a successful call to ZwCreateKey or ZwOpenKey.
|
||||
* @param KeyInformationClass
|
||||
* Specifies a KEY_INFORMATION_CLASS value that determines the type of information
|
||||
* returned in the KeyInformation buffer.
|
||||
* @param KeyInformation
|
||||
* Pointer to a caller-allocated buffer that receives the requested information.
|
||||
* @param Length
|
||||
* Specifies the size, in bytes, of the KeyInformation buffer.
|
||||
* @param ResultLength
|
||||
* Pointer to a variable that receives the size, in bytes, of the requested key
|
||||
* information. If ZwQueryKey returns STATUS_SUCCESS, the variable contains the amount
|
||||
* of data returned. If ZwQueryKey returns STATUS_BUFFER_OVERFLOW or
|
||||
* STATUS_BUFFER_TOO_SMALL, you can use the value of the variable to determine the
|
||||
* required buffer size.
|
||||
* @return
|
||||
* ZwQueryKey returns STATUS_SUCCESS on success, or the appropriate error code on failure.
|
||||
*/
|
||||
public int ZwQueryKey(HANDLE KeyHandle, int KeyInformationClass,
|
||||
Structure KeyInformation, int Length, IntByReference ResultLength);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/* 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 com.sun.jna.platform.win32.Wdm.KEY_BASIC_INFORMATION;
|
||||
import com.sun.jna.platform.win32.Wdm.KEY_INFORMATION_CLASS;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEY;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
/**
|
||||
* NtDll Utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class NtDllUtil {
|
||||
|
||||
/**
|
||||
* Retrieve the name of an opened registry key.
|
||||
* @param hkey Opened registry key.
|
||||
* @return Basic key name, not including node information.
|
||||
*/
|
||||
public static String getKeyName(HKEY hkey) {
|
||||
IntByReference resultLength = new IntByReference();
|
||||
int rc = NtDll.INSTANCE.ZwQueryKey(hkey, KEY_INFORMATION_CLASS.KeyBasicInformation,
|
||||
null, 0, resultLength);
|
||||
if (rc != NTStatus.STATUS_BUFFER_TOO_SMALL || resultLength.getValue() <= 0) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
KEY_BASIC_INFORMATION keyInformation = new KEY_BASIC_INFORMATION(
|
||||
resultLength.getValue());
|
||||
rc = NtDll.INSTANCE.ZwQueryKey(hkey, KEY_INFORMATION_CLASS.KeyBasicInformation,
|
||||
keyInformation, resultLength.getValue(), resultLength);
|
||||
if (rc != NTStatus.STATUS_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return keyInformation.getName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010 Digital Rapids Corp.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2010 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.platform.win32.WTypes;
|
||||
|
||||
/**
|
||||
* Definitions from ObjBase.h
|
||||
* @author scott.palmer
|
||||
*/
|
||||
public interface ObjBase {
|
||||
|
||||
public static final int CLSCTX_INPROC = (WTypes.CLSCTX_INPROC_SERVER | WTypes.CLSCTX_INPROC_HANDLER);
|
||||
|
||||
// With DCOM, CLSCTX_REMOTE_SERVER should be included
|
||||
public static final int CLSCTX_ALL = (WTypes.CLSCTX_INPROC_SERVER
|
||||
| WTypes.CLSCTX_INPROC_HANDLER
|
||||
| WTypes.CLSCTX_LOCAL_SERVER
|
||||
| WTypes.CLSCTX_REMOTE_SERVER);
|
||||
|
||||
public static final int CLSCTX_SERVER = (WTypes.CLSCTX_INPROC_SERVER
|
||||
| WTypes.CLSCTX_LOCAL_SERVER
|
||||
| WTypes.CLSCTX_REMOTE_SERVER);
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/* 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 com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.Guid.GUID;
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Ole32.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Ole32 extends StdCallLibrary {
|
||||
|
||||
Ole32 INSTANCE = (Ole32) Native.loadLibrary(
|
||||
"Ole32", Ole32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* Creates a GUID, a unique 128-bit integer used for CLSIDs and interface identifiers.
|
||||
* @param pguid
|
||||
* A pointer to the requested GUID.
|
||||
* @return
|
||||
* S_OK if the GUID was successfully created.
|
||||
*/
|
||||
HRESULT CoCreateGuid(GUID.ByReference pguid);
|
||||
|
||||
/**
|
||||
* Converts a globally unique identifier (GUID) into a string of printable characters.
|
||||
* @param rguid
|
||||
* The GUID to be converted.
|
||||
* @param lpsz
|
||||
* A pointer to a caller-allocated string variable to receive the resulting string.
|
||||
* @param cchMax
|
||||
* The number of characters available in the lpsz buffer.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the number of characters in the
|
||||
* returned string, including the null terminator. If the buffer is too small to contain
|
||||
* the string, the return value is 0.
|
||||
*/
|
||||
int StringFromGUID2(GUID.ByReference rguid, char[] lpsz, int cchMax);
|
||||
|
||||
/**
|
||||
* Converts a string generated by the StringFromIID function back into the
|
||||
* original interface identifier (IID).
|
||||
* @param lpsz
|
||||
* A pointer to the string representation of the IID.
|
||||
* @param lpiid
|
||||
* A pointer to the requested IID on return.
|
||||
* @return
|
||||
* This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY,
|
||||
* and S_OK.
|
||||
*/
|
||||
HRESULT IIDFromString(String lpsz, GUID.ByReference lpiid);
|
||||
|
||||
/**
|
||||
* Initializes the COM library for use by the calling thread, sets the thread's
|
||||
* concurrency model, and creates a new apartment for the thread if one is required.
|
||||
* @param reserved This parameter is reserved and must be NULL.
|
||||
* @param dwCoInit The concurrency model and initialization options for the
|
||||
* thread. Values for this parameter are taken from the COINIT enumeration.
|
||||
* Any combination of values from COINIT can be used, except that the
|
||||
* COINIT_APARTMENTTHREADED and COINIT_MULTITHREADED flags cannot both be
|
||||
* set. The default (and only sane choice) is COINIT_MULTITHREADED.
|
||||
* @return This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values. S_OK, S_FALSE, RPC_E_CHANGED_MODE
|
||||
*/
|
||||
HRESULT CoInitializeEx(Pointer reserved, int dwCoInit);
|
||||
|
||||
/**
|
||||
* Closes the COM library on the current thread, unloads all DLLs loaded by
|
||||
* the thread, frees any other resources that the thread maintains, and
|
||||
* forces all RPC connections on the thread to close.
|
||||
*
|
||||
*/
|
||||
void CoUninitialize();
|
||||
|
||||
/**
|
||||
* Creates a single uninitialized object of the class associated with a specified CLSID.
|
||||
* @param rclsid The CLSID associated with the data and code that will be used to create the object.
|
||||
* @param pUnkOuter If NULL, indicates that the object is not being created as part of an aggregate. If non-NULL, pointer to the aggregate object's IUnknown interface (the controlling IUnknown).
|
||||
* @param dwClsContext Context in which the code that manages the newly created object will run. The values are taken from the enumeration CLSCTX defined in WTypes.
|
||||
* @param riid A reference to the identifier of the interface to be used to communicate with the object.
|
||||
* @param ppv Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppv contains the requested interface pointer. Upon failure, *ppv contains NULL.
|
||||
* @return an HRESULT
|
||||
*/
|
||||
HRESULT CoCreateInstance(
|
||||
GUID rclsid,
|
||||
Pointer pUnkOuter,
|
||||
int dwClsContext,
|
||||
GUID riid,
|
||||
PointerByReference ppv);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/* 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 com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.Guid.GUID;
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
|
||||
/**
|
||||
* Ole32 Utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Ole32Util {
|
||||
|
||||
/**
|
||||
* Convert a string to a GUID.
|
||||
* @param guidString
|
||||
* String representation of a GUID, including { }.
|
||||
* @return
|
||||
* A GUID.
|
||||
*/
|
||||
public static GUID getGUIDFromString(String guidString) {
|
||||
GUID.ByReference lpiid = new GUID.ByReference();
|
||||
HRESULT hr = Ole32.INSTANCE.IIDFromString(guidString, lpiid);
|
||||
if (! hr.equals(W32Errors.S_OK)) {
|
||||
throw new RuntimeException(hr.toString());
|
||||
}
|
||||
return lpiid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a GUID into a string.
|
||||
* @param guid
|
||||
* GUID.
|
||||
* @return
|
||||
* String representation of a GUID.
|
||||
*/
|
||||
public static String getStringFromGUID(GUID guid) {
|
||||
GUID.ByReference pguid = new GUID.ByReference(guid.getPointer());
|
||||
int max = 39;
|
||||
char[] lpsz = new char[max];
|
||||
int len = Ole32.INSTANCE.StringFromGUID2(pguid, lpsz, max);
|
||||
if (len == 0) {
|
||||
throw new RuntimeException("StringFromGUID2");
|
||||
}
|
||||
lpsz[len - 1] = 0;
|
||||
return Native.toString(lpsz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new GUID.
|
||||
* @return
|
||||
* New GUID.
|
||||
*/
|
||||
public static GUID generateGUID() {
|
||||
GUID.ByReference pguid = new GUID.ByReference();
|
||||
HRESULT hr = Ole32.INSTANCE.CoCreateGuid(pguid);
|
||||
if (! hr.equals(W32Errors.S_OK)) {
|
||||
throw new RuntimeException(hr.toString());
|
||||
}
|
||||
return pguid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2010 Digital Rapids Corp., All rights reserved.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2010 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.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Oleaut32.dll Interface.
|
||||
* @author scott.palmer
|
||||
*/
|
||||
public interface Oleaut32 extends StdCallLibrary {
|
||||
|
||||
Oleaut32 INSTANCE = (Oleaut32) Native.loadLibrary(
|
||||
"Oleaut32", Oleaut32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* This function allocates a new string and copies the passed string into it.
|
||||
* @param sz
|
||||
* Null-terminated UNICODE string to copy.
|
||||
* @return
|
||||
* Null if there is insufficient memory or if a null pointer is passed in.
|
||||
*/
|
||||
Pointer SysAllocString(String sz);
|
||||
|
||||
/**
|
||||
* This function frees a string allocated previously by SysAllocString,
|
||||
* SysAllocStringByteLen, SysReAllocString, SysAllocStringLen, or
|
||||
* SysReAllocStringLen.
|
||||
* @param bstr
|
||||
* Unicode string that was allocated previously, or NULL. Setting this parameter
|
||||
* to NULL causes the function to simply return.
|
||||
*/
|
||||
void SysFreeString(Pointer bstr);
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
/* 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 com.sun.jna.Native;
|
||||
import com.sun.jna.NativeLong;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.Sspi.CredHandle;
|
||||
import com.sun.jna.platform.win32.Sspi.CtxtHandle;
|
||||
import com.sun.jna.platform.win32.Sspi.PSecPkgInfo;
|
||||
import com.sun.jna.platform.win32.Sspi.SecBufferDesc;
|
||||
import com.sun.jna.platform.win32.Sspi.TimeStamp;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.LUID;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.NativeLongByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Secur32.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Secur32 extends StdCallLibrary {
|
||||
Secur32 INSTANCE = (Secur32) Native.loadLibrary(
|
||||
"Secur32", Secur32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* Specifies a format for a directory service object name.
|
||||
* http://msdn.microsoft.com/en-us/library/ms724268(VS.85).aspx
|
||||
*/
|
||||
public abstract class EXTENDED_NAME_FORMAT {
|
||||
public static final int NameUnknown = 0;
|
||||
public static final int NameFullyQualifiedDN = 1;
|
||||
public static final int NameSamCompatible = 2;
|
||||
public static final int NameDisplay = 3;
|
||||
public static final int NameUniqueId = 6;
|
||||
public static final int NameCanonical = 7;
|
||||
public static final int NameUserPrincipal = 8;
|
||||
public static final int NameCanonicalEx = 9;
|
||||
public static final int NameServicePrincipal = 10;
|
||||
public static final int NameDnsDomain = 12;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the name of the user or other security principal associated with
|
||||
* the calling thread. You can specify the format of the returned name.
|
||||
* @param nameFormat The format of the name.
|
||||
* @param lpNameBuffer A pointer to a buffer that receives the name in the specified format.
|
||||
* @param len On input, the size of the buffer, on output the number of characters copied into the buffer, not including the terminating null character.
|
||||
* @return True if the function succeeds. False otherwise.
|
||||
*/
|
||||
public boolean GetUserNameEx(int nameFormat, char[] lpNameBuffer, IntByReference len);
|
||||
|
||||
/**
|
||||
* The AcquireCredentialsHandle function acquires a handle to preexisting credentials
|
||||
* of a security principal. This handle is required by the AcceptSecurityContext
|
||||
* and InitializeSecurityContext functions. These can be either preexisting credentials,
|
||||
* which are established through a system logon that is not described here, or the
|
||||
* caller can provide alternative credentials.
|
||||
* @param pszPrincipal
|
||||
* A pointer to a null-terminated string that specifies the name of the principal whose
|
||||
* credentials the handle will reference.
|
||||
* @param pszPackage
|
||||
* A pointer to a null-terminated string that specifies the name of the security package
|
||||
* with which these credentials will be used.
|
||||
* @param fCredentialUse
|
||||
* A flag that indicates how these credentials will be used.
|
||||
* @param pvLogonID
|
||||
* A pointer to a locally unique identifier (LUID) that identifies the user.
|
||||
* @param pAuthData
|
||||
* A pointer to package-specific data. This parameter can be NULL, which indicates
|
||||
* that the default credentials for that package must be used. To use supplied
|
||||
* credentials, pass a SEC_WINNT_AUTH_IDENTITY structure that includes those credentials
|
||||
* in this parameter.
|
||||
* @param pGetKeyFn
|
||||
* This parameter is not used and should be set to NULL.
|
||||
* @param pvGetKeyArgument
|
||||
* This parameter is not used and should be set to NULL.
|
||||
* @param phCredential
|
||||
* A pointer to a CredHandle structure to receive the credential handle.
|
||||
* @param ptsExpiry
|
||||
* A pointer to a TimeStamp structure that receives the time at which the returned
|
||||
* credentials expire. The value returned in this TimeStamp structure depends on
|
||||
* the security package. The security package must return this value in local time.
|
||||
* @return
|
||||
* If the function succeeds, the function returns one of the SEC_I_ success codes.
|
||||
* If the function fails, the function returns one of the SEC_E_ error codes.
|
||||
*/
|
||||
public int AcquireCredentialsHandle(String pszPrincipal, String pszPackage,
|
||||
NativeLong fCredentialUse, LUID pvLogonID,
|
||||
Pointer pAuthData, Pointer pGetKeyFn, // TODO: SEC_GET_KEY_FN
|
||||
Pointer pvGetKeyArgument, CredHandle phCredential,
|
||||
TimeStamp ptsExpiry);
|
||||
|
||||
/**
|
||||
* The InitializeSecurityContext function initiates the client side, outbound security
|
||||
* context from a credential handle. The function is used to build a security context
|
||||
* between the client application and a remote peer. InitializeSecurityContext returns
|
||||
* a token that the client must pass to the remote peer, which the peer in turn submits
|
||||
* to the local security implementation through the AcceptSecurityContext call. The
|
||||
* token generated should be considered opaque by all callers.
|
||||
*
|
||||
* Typically, the InitializeSecurityContext function is called in a loop until a
|
||||
* sufficient security context is established.
|
||||
*
|
||||
* @param phCredential
|
||||
* A handle to the credentials returned by AcquireCredentialsHandle. This handle is
|
||||
* used to build the security context. The InitializeSecurityContext function requires
|
||||
* at least OUTBOUND credentials.
|
||||
* @param phContext
|
||||
* A pointer to a CtxtHandle structure. On the first call to InitializeSecurityContext,
|
||||
* this pointer is NULL. On the second call, this parameter is a pointer to the handle
|
||||
* to the partially formed context returned in the phNewContext parameter by the first
|
||||
* call.
|
||||
* @param pszTargetName
|
||||
* A pointer to a null-terminated string that indicates the target of the context.
|
||||
* The string contents are security-package specific.
|
||||
* @param fContextReq
|
||||
* Bit flags that indicate requests for the context. Not all packages can support all
|
||||
* requirements. Flags used for this parameter are prefixed with ISC_REQ_, for example,
|
||||
* ISC_REQ_DELEGATE.
|
||||
* @param Reserved1
|
||||
* This parameter is reserved and must be set to zero.
|
||||
* @param TargetDataRep
|
||||
* The data representation, such as byte ordering, on the target. This parameter can be
|
||||
* either SECURITY_NATIVE_DREP or SECURITY_NETWORK_DREP.
|
||||
* @param pInput
|
||||
* A pointer to a SecBufferDesc structure that contains pointers to the buffers supplied
|
||||
* as input to the package. The pointer must be NULL on the first call to the function.
|
||||
* On subsequent calls to the function, it is a pointer to a buffer allocated with enough
|
||||
* memory to hold the token returned by the remote peer.
|
||||
* @param Reserved2
|
||||
* This parameter is reserved and must be set to zero.
|
||||
* @param phNewContext
|
||||
* A pointer to a CtxtHandle structure. On the first call to InitializeSecurityContext,
|
||||
* this pointer receives the new context handle. On the second call, phNewContext can be
|
||||
* the same as the handle specified in the phContext parameter.
|
||||
* @param pOutput
|
||||
* A pointer to a SecBufferDesc structure that contains pointers to the SecBuffer structure
|
||||
* that receives the output data. If a buffer was typed as SEC_READWRITE in the input, it
|
||||
* will be there on output. The system will allocate a buffer for the security token if
|
||||
* requested (through ISC_REQ_ALLOCATE_MEMORY) and fill in the address in the buffer
|
||||
* descriptor for the security token.
|
||||
* @param pfContextAttr
|
||||
* A pointer to a variable to receive a set of bit flags that indicate the attributes of
|
||||
* the established context. Flags used for this parameter are prefixed with ISC_RET,
|
||||
* such as ISC_RET_DELEGATE.
|
||||
* @param ptsExpiry
|
||||
* A pointer to a TimeStamp structure that receives the expiration time of the context.
|
||||
* It is recommended that the security package always return this value in local time.
|
||||
* This parameter is optional and NULL should be passed for short-lived clients.
|
||||
* @return
|
||||
* If the function succeeds, the function returns one of the SEC_I_ success codes.
|
||||
* If the function fails, the function returns one of the SEC_E_ error codes.
|
||||
*/
|
||||
public int InitializeSecurityContext(CredHandle phCredential, CtxtHandle phContext,
|
||||
String pszTargetName, NativeLong fContextReq, NativeLong Reserved1,
|
||||
NativeLong TargetDataRep, SecBufferDesc pInput, NativeLong Reserved2,
|
||||
CtxtHandle phNewContext, SecBufferDesc pOutput, NativeLongByReference pfContextAttr,
|
||||
TimeStamp ptsExpiry);
|
||||
|
||||
/**
|
||||
* The DeleteSecurityContext function deletes the local data structures associated
|
||||
* with the specified security context.
|
||||
* @param phContext
|
||||
* Handle of the security context to delete.
|
||||
* @return
|
||||
* If the function succeeds, the return value is SEC_E_OK.
|
||||
* If the function fails, the return value is SEC_E_INVALID_HANDLE;
|
||||
*/
|
||||
public int DeleteSecurityContext(CtxtHandle phContext);
|
||||
|
||||
/**
|
||||
* The FreeCredentialsHandle function notifies the security system that the
|
||||
* credentials are no longer needed. An application calls this function to free
|
||||
* the credential handle acquired in the call to the AcquireCredentialsHandle
|
||||
* function. When all references to this credential set have been removed, the
|
||||
* credentials themselves can be removed.
|
||||
* @param phCredential
|
||||
* A pointer to the credential handle obtained by using the AcquireCredentialsHandle
|
||||
* function.
|
||||
* @return
|
||||
* If the function succeeds, the return value is SEC_E_OK.
|
||||
* If the function fails, the return value is SEC_E_INVALID_HANDLE;
|
||||
*/
|
||||
public int FreeCredentialsHandle(CredHandle phCredential);
|
||||
|
||||
/**
|
||||
* The AcceptSecurityContext function enables the server component of a transport
|
||||
* application to establish a security context between the server and a remote client.
|
||||
* The remote client uses the InitializeSecurityContext function to start the process
|
||||
* of establishing a security context. The server can require one or more reply tokens
|
||||
* from the remote client to complete establishing the security context.
|
||||
* @param phCredential
|
||||
* A handle to the credentials of the server. The server calls the AcquireCredentialsHandle
|
||||
* function with either the SECPKG_CRED_INBOUND or SECPKG_CRED_BOTH flag set to retrieve
|
||||
* this handle.
|
||||
* @param phContext
|
||||
* A pointer to a CtxtHandle structure. On the first call to AcceptSecurityContext,
|
||||
* this pointer is NULL. On subsequent calls, phContext is the handle to the partially
|
||||
* formed context that was returned in the phNewContext parameter by the first call.
|
||||
* @param pInput
|
||||
* A pointer to a SecBufferDesc structure generated by a client call to
|
||||
* InitializeSecurityContext that contains the input buffer descriptor.
|
||||
* @param fContextReq
|
||||
* Bit flags that specify the attributes required by the server to establish the
|
||||
* context. Bit flags can be combined by using bitwise-OR operations.
|
||||
* @param TargetDataRep
|
||||
* The data representation, such as byte ordering, on the target. This parameter can
|
||||
* be either SECURITY_NATIVE_DREP or SECURITY_NETWORK_DREP.
|
||||
* @param phNewContext
|
||||
* A pointer to a CtxtHandle structure. On the first call to AcceptSecurityContext,
|
||||
* this pointer receives the new context handle. On subsequent calls, phNewContext
|
||||
* can be the same as the handle specified in the phContext parameter.
|
||||
* @param pOutput
|
||||
* A pointer to a SecBufferDesc structure that contains the output buffer descriptor.
|
||||
* This buffer is sent to the client for input into additional calls to
|
||||
* InitializeSecurityContext. An output buffer may be generated even if the function
|
||||
* returns SEC_E_OK. Any buffer generated must be sent back to the client application.
|
||||
* @param pfContextAttr
|
||||
* A pointer to a variable that receives a set of bit flags that indicate the
|
||||
* attributes of the established context. For a description of the various attributes,
|
||||
* see Context Requirements. Flags used for this parameter are prefixed with ASC_RET,
|
||||
* for example, ASC_RET_DELEGATE.
|
||||
* @param ptsTimeStamp
|
||||
* A pointer to a TimeStamp structure that receives the expiration time of the context.
|
||||
* @return
|
||||
* This function returns one of SEC_* values.
|
||||
*/
|
||||
public int AcceptSecurityContext(CredHandle phCredential, CtxtHandle phContext,
|
||||
SecBufferDesc pInput, NativeLong fContextReq, NativeLong TargetDataRep,
|
||||
CtxtHandle phNewContext, SecBufferDesc pOutput, NativeLongByReference pfContextAttr,
|
||||
TimeStamp ptsTimeStamp);
|
||||
|
||||
/**
|
||||
* The EnumerateSecurityPackages function returns an array of SecPkgInfo structures that
|
||||
* describe the security packages available to the client.
|
||||
* @param pcPackages
|
||||
* A pointer to a ULONG variable that receives the number of packages returned.
|
||||
* @param ppPackageInfo
|
||||
* A pointer to a variable that receives a pointer to an array of SecPkgInfo structures.
|
||||
* Each structure contains information from the security support provider (SSP) that
|
||||
* describes a security package that is available within that SSP.
|
||||
* @return
|
||||
* If the function succeeds, the function returns SEC_E_OK.
|
||||
* If the function fails, it returns a nonzero error code.
|
||||
*/
|
||||
public int EnumerateSecurityPackages(IntByReference pcPackages,
|
||||
PSecPkgInfo.ByReference ppPackageInfo);
|
||||
|
||||
/**
|
||||
* The FreeContextBuffer function enables callers of security package functions to free a memory
|
||||
* buffer that was allocated by the security package as a result of calls to InitializeSecurityContext
|
||||
* and AcceptSecurityContext.
|
||||
* @param buffer
|
||||
* A pointer to memory allocated by the security package.
|
||||
* @return
|
||||
* If the function succeeds, the function returns SEC_E_OK.
|
||||
* If the function fails, it returns a nonzero error code.
|
||||
*/
|
||||
public int FreeContextBuffer(Pointer buffer);
|
||||
|
||||
/**
|
||||
* The QuerySecurityContextToken function obtains the access token for a client security context
|
||||
* and uses it directly.
|
||||
* @param phContext
|
||||
* Handle of the context to query.
|
||||
* @param phToken
|
||||
* Returned handle to the access token.
|
||||
* @return
|
||||
* If the function succeeds, the function returns SEC_E_OK.
|
||||
* If the function fails, it returns a nonzero error code. One possible error code return is
|
||||
* SEC_E_INVALID_HANDLE.
|
||||
*/
|
||||
public int QuerySecurityContextToken(CtxtHandle phContext,
|
||||
HANDLEByReference phToken);
|
||||
|
||||
/**
|
||||
* The ImpersonateSecurityContext function allows a server to impersonate a client by using
|
||||
* a token previously obtained by a call to AcceptSecurityContext or QuerySecurityContextToken.
|
||||
* This function allows the application server to act as the client, and thus all necessary
|
||||
* access controls are enforced.
|
||||
* @param phContext
|
||||
* The handle of the context to impersonate. This handle must have been obtained by a call
|
||||
* to the AcceptSecurityContext function.
|
||||
* @return
|
||||
* If the function succeeds, the function returns SEC_E_OK.
|
||||
* If the function fails, it returns a SEC_E_INVALID_HANDLE, SEC_E_NO_IMPERSONATION or
|
||||
* SEC_E_UNSUPPORTED_FUNCTION error code.
|
||||
*/
|
||||
public int ImpersonateSecurityContext(CtxtHandle phContext);
|
||||
|
||||
/**
|
||||
* Allows a security package to discontinue the impersonation of the caller and restore its
|
||||
* own security context.
|
||||
* @param phContext
|
||||
* Handle of the security context being impersonated. This handle must have been obtained in
|
||||
* the call to the AcceptSecurityContext function and used in the call to the
|
||||
* ImpersonateSecurityContext function.
|
||||
* @return
|
||||
* If the function succeeds, the return value is SEC_E_OK.
|
||||
* If the function fails, the return value can be either SEC_E_INVALID_HANDLE or SEC_E_UNSUPPORTED_FUNCTION.
|
||||
*/
|
||||
public int RevertSecurityContext(CtxtHandle phContext);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/* 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.ArrayList;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.Sspi.PSecPkgInfo;
|
||||
import com.sun.jna.platform.win32.Sspi.SecPkgInfo;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
/**
|
||||
* Secur32 Utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Secur32Util {
|
||||
|
||||
/**
|
||||
* An SSPI package.
|
||||
*/
|
||||
public static class SecurityPackage {
|
||||
/**
|
||||
* Package name.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* Package comment.
|
||||
*/
|
||||
public String comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the name of the user or other security principal associated
|
||||
* with the calling thread.
|
||||
*
|
||||
* @param format User name format.
|
||||
* @return User name in a given format.
|
||||
*/
|
||||
public static String getUserNameEx(int format) {
|
||||
char[] buffer = new char[128];
|
||||
IntByReference len = new IntByReference(buffer.length);
|
||||
boolean result = Secur32.INSTANCE.GetUserNameEx(format, buffer, len);
|
||||
|
||||
if (! result) {
|
||||
|
||||
int rc = Kernel32.INSTANCE.GetLastError();
|
||||
|
||||
switch(rc) {
|
||||
case W32Errors.ERROR_MORE_DATA:
|
||||
buffer = new char[len.getValue() + 1];
|
||||
break;
|
||||
default:
|
||||
throw new Win32Exception(Native.getLastError());
|
||||
}
|
||||
|
||||
result = Secur32.INSTANCE.GetUserNameEx(format, buffer, len);
|
||||
}
|
||||
|
||||
if (! result) {
|
||||
throw new Win32Exception(Native.getLastError());
|
||||
}
|
||||
|
||||
return Native.toString(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the security packages installed on the current computer.
|
||||
* @return
|
||||
* An array of SSPI security packages.
|
||||
*/
|
||||
public static SecurityPackage[] getSecurityPackages() {
|
||||
IntByReference pcPackages = new IntByReference();
|
||||
PSecPkgInfo.ByReference pPackageInfo = new PSecPkgInfo.ByReference();
|
||||
int rc = Secur32.INSTANCE.EnumerateSecurityPackages(pcPackages, pPackageInfo);
|
||||
if(W32Errors.SEC_E_OK != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
SecPkgInfo[] packagesInfo = pPackageInfo.toArray(pcPackages.getValue());
|
||||
ArrayList<SecurityPackage> packages = new ArrayList<SecurityPackage>(pcPackages.getValue());
|
||||
for(SecPkgInfo packageInfo : packagesInfo) {
|
||||
SecurityPackage securityPackage = new SecurityPackage();
|
||||
securityPackage.name = packageInfo.Name.toString();
|
||||
securityPackage.comment = packageInfo.Comment.toString();
|
||||
packages.add(securityPackage);
|
||||
}
|
||||
rc = Secur32.INSTANCE.FreeContextBuffer(pPackageInfo.pPkgInfo.getPointer());
|
||||
if(W32Errors.SEC_E_OK != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return packages.toArray(new SecurityPackage[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/* 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.
|
||||
* <p/>
|
||||
* 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.platform.win32.ShellAPI.SHFILEOPSTRUCT;
|
||||
import com.sun.jna.platform.win32.WinDef.DWORD;
|
||||
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Shell32.dll Interface.
|
||||
*/
|
||||
public interface Shell32 extends StdCallLibrary {
|
||||
|
||||
Shell32 INSTANCE = (Shell32) Native.loadLibrary("shell32", Shell32.class,
|
||||
W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* This function can be used to copy, move, rename, or delete a file system object.
|
||||
* @param fileop
|
||||
* Address of an SHFILEOPSTRUCT structure that contains information this function
|
||||
* needs to carry out the specified operation.
|
||||
* @return
|
||||
* Returns zero if successful, or nonzero otherwise.
|
||||
*/
|
||||
int SHFileOperation(SHFILEOPSTRUCT fileop);
|
||||
|
||||
/**
|
||||
* Takes the CSIDL of a folder and returns the path.
|
||||
* @param hwndOwner
|
||||
* Handle to an owner window. This parameter is typically set to NULL. If it is not NULL,
|
||||
* and a dial-up connection needs to be made to access the folder, a user interface (UI)
|
||||
* prompt will appear in this window.
|
||||
* @param nFolder
|
||||
* A CSIDL value that identifies the folder whose path is to be retrieved. Only real
|
||||
* folders are valid. If a virtual folder is specified, this function will fail. You can
|
||||
* force creation of a folder with SHGetFolderPath by combining the folder's CSIDL with
|
||||
* CSIDL_FLAG_CREATE.
|
||||
* @param hToken
|
||||
* An access token that can be used to represent a particular user.
|
||||
* @param dwFlags
|
||||
* Flags to specify which path is to be returned.
|
||||
* @param pszPath
|
||||
* Pointer to a null-terminated string of length MAX_PATH which will receive the path.
|
||||
* If an error occurs or S_FALSE is returned, this string will be empty.
|
||||
* @return
|
||||
* Returns standard HRESULT codes.
|
||||
*/
|
||||
HRESULT SHGetFolderPath(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags,
|
||||
char[] pszPath);
|
||||
|
||||
/**
|
||||
* Retrieves the IShellFolder interface for the desktop folder, which is the root of the Shell's namespace.
|
||||
* The retrieved COM interface pointer can be used via Com4JNA's ComObject.wrapNativeInterface call
|
||||
* given a suitable interface definition for IShellFolder
|
||||
* @param ppshf A place to put the IShellFolder interface pointer
|
||||
* @return If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
|
||||
*/
|
||||
HRESULT SHGetDesktopFolder( PointerByReference ppshf );
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/* 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 com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.WinDef.DWORD;
|
||||
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
|
||||
/**
|
||||
* Shell32 Utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Shell32Util {
|
||||
|
||||
/**
|
||||
* Get a special folder path.
|
||||
* @param hwnd
|
||||
* Parent window.
|
||||
* @param nFolder
|
||||
* Folder CSLID.
|
||||
* @param dwFlags
|
||||
* Flags.
|
||||
* @return
|
||||
* Special folder.
|
||||
*/
|
||||
public static String getFolderPath(HWND hwnd, int nFolder, DWORD dwFlags) {
|
||||
char[] pszPath = new char[WinDef.MAX_PATH];
|
||||
HRESULT hr = Shell32.INSTANCE.SHGetFolderPath(hwnd,
|
||||
nFolder, null, dwFlags,
|
||||
pszPath);
|
||||
if (! hr.equals(W32Errors.S_OK)) {
|
||||
throw new Win32Exception(hr);
|
||||
}
|
||||
return Native.toString(pszPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a special folder path.
|
||||
* @param nFolder
|
||||
* Folder CSLID.
|
||||
* @return
|
||||
* Special folder path.
|
||||
*/
|
||||
public static String getFolderPath(int nFolder) {
|
||||
return getFolderPath(null, nFolder, ShlObj.SHGFP_TYPE_CURRENT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/* 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 com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from ShellAPI.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface ShellAPI extends StdCallLibrary {
|
||||
|
||||
int STRUCTURE_ALIGNMENT = Structure.ALIGN_NONE;
|
||||
|
||||
public static final int FO_MOVE = 0x0001;
|
||||
public static final int FO_COPY = 0x0002;
|
||||
public static final int FO_DELETE = 0x0003;
|
||||
public static final int FO_RENAME = 0x0004;
|
||||
|
||||
public static final int FOF_MULTIDESTFILES = 0x0001;
|
||||
public static final int FOF_CONFIRMMOUSE = 0x0002;
|
||||
public static final int FOF_SILENT = 0x0004; // don't display progress UI (confirm prompts may be displayed still)
|
||||
public static final int FOF_RENAMEONCOLLISION = 0x0008; // automatically rename the source files to avoid the collisions
|
||||
public static final int FOF_NOCONFIRMATION = 0x0010; // don't display confirmation UI, assume "yes" for cases that can be bypassed, "no" for those that can not
|
||||
public static final int FOF_WANTMAPPINGHANDLE = 0x0020; // Fill in SHFILEOPSTRUCT.hNameMappings
|
||||
public static final int FOF_ALLOWUNDO = 0x0040; // enable undo including Recycle behavior for IFileOperation::Delete()
|
||||
public static final int FOF_FILESONLY = 0x0080; // only operate on the files (non folders), both files and folders are assumed without this
|
||||
public static final int FOF_SIMPLEPROGRESS = 0x0100; // means don't show names of files
|
||||
public static final int FOF_NOCONFIRMMKDIR = 0x0200; // don't dispplay confirmatino UI before making any needed directories, assume "Yes" in these cases
|
||||
public static final int FOF_NOERRORUI = 0x0400; // don't put up error UI, other UI may be displayed, progress, confirmations
|
||||
public static final int FOF_NOCOPYSECURITYATTRIBS = 0x0800; // dont copy file security attributes (ACLs)
|
||||
public static final int FOF_NORECURSION = 0x1000; // don't recurse into directories for operations that would recurse
|
||||
public static final int FOF_NO_CONNECTED_ELEMENTS = 0x2000; // don't operate on connected elements ("xxx_files" folders that go with .htm files)
|
||||
public static final int FOF_WANTNUKEWARNING = 0x4000; // during delete operation, warn if nuking instead of recycling (partially overrides FOF_NOCONFIRMATION)
|
||||
public static final int FOF_NORECURSEREPARSE = 0x8000; // deprecated; the operations engine always does the right thing on FolderLink objects (symlinks, reparse points, folder shortcuts)
|
||||
public static final int FOF_NO_UI = (FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR); // don't display any UI at all
|
||||
|
||||
public static final int PO_DELETE = 0x0013; // printer is being deleted
|
||||
public static final int PO_RENAME = 0x0014; // printer is being renamed
|
||||
public static final int PO_PORTCHANGE = 0x0020; // port this printer connected to is being changed
|
||||
public static final int PO_REN_PORT = 0x0034; // PO_RENAME and PO_PORTCHANGE at same time.
|
||||
|
||||
/**
|
||||
* Contains information that the SHFileOperation function uses to perform file operations.
|
||||
*/
|
||||
public static class SHFILEOPSTRUCT extends Structure {
|
||||
/**
|
||||
* A window handle to the dialog box to display information about
|
||||
* the status of the file operation.
|
||||
*/
|
||||
public HANDLE hwnd;
|
||||
/**
|
||||
* An FO_* value that indicates which operation to perform.
|
||||
*/
|
||||
public int wFunc;
|
||||
/**
|
||||
* A pointer to one or more source file names, double null-terminated.
|
||||
*/
|
||||
public WString pFrom;
|
||||
/**
|
||||
* A pointer to the destination file or directory name.
|
||||
*/
|
||||
public WString pTo;
|
||||
/**
|
||||
* Flags that control the file operation.
|
||||
*/
|
||||
public short fFlags;
|
||||
/**
|
||||
* When the function returns, this member contains TRUE if any file operations
|
||||
* were aborted before they were completed; otherwise, FALSE. An operation can
|
||||
* be manually aborted by the user through UI or it can be silently aborted by
|
||||
* the system if the FOF_NOERRORUI or FOF_NOCONFIRMATION flags were set.
|
||||
*/
|
||||
public boolean fAnyOperationsAborted;
|
||||
/**
|
||||
* When the function returns, this member contains a handle to a name mapping
|
||||
* object that contains the old and new names of the renamed files. This member
|
||||
* is used only if the fFlags member includes the FOF_WANTMAPPINGHANDLE flag.
|
||||
*/
|
||||
public Pointer pNameMappings;
|
||||
/**
|
||||
* A pointer to the title of a progress dialog box. This is a null-terminated string.
|
||||
*/
|
||||
public WString lpszProgressTitle;
|
||||
|
||||
/** Use this to encode <code>pFrom/pTo</code> paths. */
|
||||
public String encodePaths(String[] paths) {
|
||||
String encoded = "";
|
||||
for (int i=0; i < paths.length;i++) {
|
||||
encoded += paths[i];
|
||||
encoded += "\0";
|
||||
}
|
||||
return encoded + "\0";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/* 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 com.sun.jna.platform.win32.WinDef.DWORD;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from ShlObj.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface ShlObj extends StdCallLibrary {
|
||||
|
||||
public static final DWORD SHGFP_TYPE_CURRENT = new DWORD(0); // current value for user, verify it exists
|
||||
public static final DWORD SHGFP_TYPE_DEFAULT = new DWORD(1); // default value, may not exist
|
||||
|
||||
public static final int CSIDL_DESKTOP = 0x0000; // <desktop>
|
||||
public static final int CSIDL_INTERNET = 0x0001; // Internet Explorer (icon on desktop)
|
||||
public static final int CSIDL_PROGRAMS = 0x0002; // Start Menu\Programs
|
||||
public static final int CSIDL_CONTROLS = 0x0003; // My Computer\Control Panel
|
||||
public static final int CSIDL_PRINTERS = 0x0004; // My Computer\Printers
|
||||
public static final int CSIDL_PERSONAL = 0x0005; // My Documents
|
||||
public static final int CSIDL_FAVORITES = 0x0006; // <user name>\Favorites
|
||||
public static final int CSIDL_STARTUP = 0x0007; // Start Menu\Programs\Startup
|
||||
public static final int CSIDL_RECENT = 0x0008; // <user name>\Recent
|
||||
public static final int CSIDL_SENDTO = 0x0009; // <user name>\SendTo
|
||||
public static final int CSIDL_BITBUCKET = 0x000a; // <desktop>\Recycle Bin
|
||||
public static final int CSIDL_STARTMENU = 0x000b; // <user name>\Start Menu
|
||||
public static final int CSIDL_MYDOCUMENTS = CSIDL_PERSONAL; // Personal was just a silly name for My Documents
|
||||
public static final int CSIDL_MYMUSIC = 0x000d; // "My Music" folder
|
||||
public static final int CSIDL_MYVIDEO = 0x000e; // "My Videos" folder
|
||||
public static final int CSIDL_DESKTOPDIRECTORY = 0x0010; // <user name>\Desktop
|
||||
public static final int CSIDL_DRIVES = 0x0011; // My Computer
|
||||
public static final int CSIDL_NETWORK = 0x0012; // Network Neighborhood (My Network Places)
|
||||
public static final int CSIDL_NETHOOD = 0x0013; // <user name>\nethood
|
||||
public static final int CSIDL_FONTS = 0x0014; // windows\fonts
|
||||
public static final int CSIDL_TEMPLATES = 0x0015;
|
||||
public static final int CSIDL_COMMON_STARTMENU = 0x0016; // All Users\Start Menu
|
||||
public static final int CSIDL_COMMON_PROGRAMS = 0X0017; // All Users\Start Menu\Programs
|
||||
public static final int CSIDL_COMMON_STARTUP = 0x0018; // All Users\Startup
|
||||
public static final int CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019; // All Users\Desktop
|
||||
public static final int CSIDL_APPDATA = 0x001a; // <user name>\Application Data
|
||||
public static final int CSIDL_PRINTHOOD = 0x001b; // <user name>\PrintHood
|
||||
public static final int CSIDL_LOCAL_APPDATA = 0x001c; // <user name>\Local Settings\Applicaiton Data (non roaming)
|
||||
public static final int CSIDL_ALTSTARTUP = 0x001d; // non localized startup
|
||||
public static final int CSIDL_COMMON_ALTSTARTUP = 0x001e; // non localized common startup
|
||||
public static final int CSIDL_COMMON_FAVORITES = 0x001f;
|
||||
public static final int CSIDL_INTERNET_CACHE = 0x0020;
|
||||
public static final int CSIDL_COOKIES = 0x0021;
|
||||
public static final int CSIDL_HISTORY = 0x0022;
|
||||
public static final int CSIDL_COMMON_APPDATA = 0x0023; // All Users\Application Data
|
||||
public static final int CSIDL_WINDOWS = 0x0024; // GetWindowsDirectory()
|
||||
public static final int CSIDL_SYSTEM = 0x0025; // GetSystemDirectory()
|
||||
public static final int CSIDL_PROGRAM_FILES = 0x0026; // C:\Program Files
|
||||
public static final int CSIDL_MYPICTURES = 0x0027; // C:\Program Files\My Pictures
|
||||
public static final int CSIDL_PROFILE = 0x0028; // USERPROFILE
|
||||
public static final int CSIDL_SYSTEMX86 = 0x0029; // x86 system directory on RISC
|
||||
public static final int CSIDL_PROGRAM_FILESX86 = 0x002a; // x86 C:\Program Files on RISC
|
||||
public static final int CSIDL_PROGRAM_FILES_COMMON = 0x002b; // C:\Program Files\Common
|
||||
public static final int CSIDL_PROGRAM_FILES_COMMONX86 = 0x002c; // x86 Program Files\Common on RISC
|
||||
public static final int CSIDL_COMMON_TEMPLATES = 0x002d; // All Users\Templates
|
||||
public static final int CSIDL_COMMON_DOCUMENTS = 0x002e; // All Users\Documents
|
||||
public static final int CSIDL_COMMON_ADMINTOOLS = 0x002f; // All Users\Start Menu\Programs\Administrative Tools
|
||||
public static final int CSIDL_ADMINTOOLS = 0x0030; // <user name>\Start Menu\Programs\Administrative Tools
|
||||
public static final int CSIDL_CONNECTIONS = 0x0031; // Network and Dial-up Connections
|
||||
public static final int CSIDL_COMMON_MUSIC = 0x0035; // All Users\My Music
|
||||
public static final int CSIDL_COMMON_PICTURES = 0x0036; // All Users\My Pictures
|
||||
public static final int CSIDL_COMMON_VIDEO = 0x0037; // All Users\My Video
|
||||
public static final int CSIDL_RESOURCES = 0x0038; // Resource Direcotry
|
||||
public static final int CSIDL_RESOURCES_LOCALIZED = 0x0039; // Localized Resource Direcotry
|
||||
public static final int CSIDL_COMMON_OEM_LINKS = 0x003a; // Links to All Users OEM specific apps
|
||||
public static final int CSIDL_CDBURN_AREA = 0x003b; // USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
|
||||
public static final int CSIDL_COMPUTERSNEARME = 0x003d; // Computers Near Me (computered from Workgroup membership)
|
||||
}
|
||||
@@ -0,0 +1,467 @@
|
||||
/* 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 com.sun.jna.Memory;
|
||||
import com.sun.jna.NativeLong;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from Sspi.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Sspi extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* Maximum size in bytes of a security token.
|
||||
*/
|
||||
public static final int MAX_TOKEN_SIZE = 12288;
|
||||
|
||||
// Flags for the fCredentialUse parameter of AcquireCredentialsHandle
|
||||
|
||||
/**
|
||||
* Validate an incoming server credential. Inbound credentials might be validated
|
||||
* by using an authenticating authority when InitializeSecurityContext or
|
||||
* AcceptSecurityContext is called. If such an authority is not available, the function will
|
||||
* fail and return SEC_E_NO_AUTHENTICATING_AUTHORITY. Validation is package specific.
|
||||
*/
|
||||
public static final int SECPKG_CRED_INBOUND = 1;
|
||||
|
||||
/**
|
||||
* Allow a local client credential to prepare an outgoing token.
|
||||
*/
|
||||
public static final int SECPKG_CRED_OUTBOUND = 2;
|
||||
|
||||
|
||||
// Flags for the TargetDataRep parameter of AcceptSecurityContext and InitializeSecurityContext
|
||||
|
||||
/**
|
||||
* Specifies Native data representation.
|
||||
*/
|
||||
public static final int SECURITY_NATIVE_DREP = 0x10;
|
||||
|
||||
|
||||
// Flags for the fContextReq parameter of InitializeSecurityContext or AcceptSecurityContext.
|
||||
|
||||
/**
|
||||
* The security package allocates output buffers for you.
|
||||
* When you have finished using the output buffers, free them by calling the FreeContextBuffer function.
|
||||
*/
|
||||
public static final int ISC_REQ_ALLOCATE_MEMORY = 0x00000100;
|
||||
|
||||
/**
|
||||
* Encrypt messages by using the EncryptMessage function.
|
||||
*/
|
||||
public static final int ISC_REQ_CONFIDENTIALITY = 0x00000010;
|
||||
|
||||
/**
|
||||
* The security context will not handle formatting messages. This value is the default.
|
||||
*/
|
||||
public static final int ISC_REQ_CONNECTION = 0x00000800;
|
||||
|
||||
/**
|
||||
* The server can use the context to authenticate to other servers as the client.
|
||||
* The ISC_REQ_MUTUAL_AUTH flag must be set for this flag to work. Valid for Kerberos.
|
||||
* Ignore this flag for constrained delegation.
|
||||
*/
|
||||
public static final int ISC_REQ_DELEGATE = 0x00000001;
|
||||
|
||||
/**
|
||||
* When errors occur, the remote party will be notified.
|
||||
*/
|
||||
public static final int ISC_REQ_EXTENDED_ERROR = 0x00004000;
|
||||
|
||||
/**
|
||||
* Sign messages and verify signatures by using the EncryptMessage and MakeSignature functions.
|
||||
*/
|
||||
public static final int ISC_REQ_INTEGRITY = 0x00010000;
|
||||
|
||||
/**
|
||||
* The mutual authentication policy of the service will be satisfied.
|
||||
*/
|
||||
public static final int ISC_REQ_MUTUAL_AUTH = 0x00000002;
|
||||
|
||||
/**
|
||||
* Detect replayed messages that have been encoded by using the
|
||||
* EncryptMessage or MakeSignature functions.
|
||||
*/
|
||||
public static final int ISC_REQ_REPLAY_DETECT = 0x00000004;
|
||||
|
||||
/**
|
||||
* Detect messages received out of sequence.
|
||||
*/
|
||||
public static final int ISC_REQ_SEQUENCE_DETECT = 0x00000008;
|
||||
|
||||
/**
|
||||
* Support a stream-oriented connection.
|
||||
*/
|
||||
public static final int ISC_REQ_STREAM = 0x00008000;
|
||||
|
||||
/**
|
||||
* Version of the SecBuffer struct.
|
||||
*/
|
||||
public static final int SECBUFFER_VERSION = 0;
|
||||
|
||||
/**
|
||||
* This is a placeholder in the buffer array.
|
||||
*/
|
||||
public static final int SECBUFFER_EMPTY = 0;
|
||||
/**
|
||||
* This buffer type is used for common data. The security package can read
|
||||
* and write this data.
|
||||
*/
|
||||
public static final int SECBUFFER_DATA = 1;
|
||||
/**
|
||||
* This buffer type is used to indicate the security token portion of the message.
|
||||
* This is read-only for input parameters or read/write for output parameters.
|
||||
*/
|
||||
public static final int SECBUFFER_TOKEN = 2;
|
||||
|
||||
/**
|
||||
* Security handle.
|
||||
*/
|
||||
public static class SecHandle extends Structure {
|
||||
public Pointer dwLower;
|
||||
public Pointer dwUpper;
|
||||
|
||||
public static class ByReference extends SecHandle implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An empty SecHandle.
|
||||
*/
|
||||
public SecHandle() {
|
||||
dwLower = null;
|
||||
dwUpper = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the handle is NULL.
|
||||
* @return
|
||||
* True if NULL, False otherwise.
|
||||
*/
|
||||
public boolean isNull() {
|
||||
return dwLower == null && dwUpper == null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A pointer to a SecHandle
|
||||
*/
|
||||
public static class PSecHandle extends Structure {
|
||||
|
||||
public static class ByReference extends PSecHandle implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The first entry in an array of SecPkgInfo structures.
|
||||
*/
|
||||
public SecHandle.ByReference secHandle;
|
||||
|
||||
public PSecHandle() {
|
||||
|
||||
}
|
||||
|
||||
public PSecHandle(SecHandle h) {
|
||||
useMemory(h.getPointer());
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Credentials handle.
|
||||
*/
|
||||
public static class CredHandle extends SecHandle {
|
||||
}
|
||||
|
||||
/**
|
||||
* Security context handle.
|
||||
*/
|
||||
public static class CtxtHandle extends SecHandle {
|
||||
}
|
||||
|
||||
/**
|
||||
* The SecBuffer structure describes a buffer allocated by a transport application
|
||||
* to pass to a security package.
|
||||
*/
|
||||
public static class SecBuffer extends Structure {
|
||||
|
||||
/**
|
||||
* A ByReference SecBuffer.
|
||||
*/
|
||||
public static class ByReference extends SecBuffer implements Structure.ByReference {
|
||||
/**
|
||||
* Create a SECBUFFER_EMPTY SecBuffer.
|
||||
*/
|
||||
public ByReference() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SecBuffer of a given type and size.
|
||||
* @param type
|
||||
* Buffer type, one of SECBUFFER_EMTPY, etc.
|
||||
* @param size
|
||||
* Buffer size, eg. MAX_TOKEN_SIZE.
|
||||
*/
|
||||
public ByReference(int type, int size) {
|
||||
super(type, size);
|
||||
}
|
||||
|
||||
public ByReference(int type, byte[] token) {
|
||||
super(type, token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get buffer bytes.
|
||||
* @return
|
||||
* Raw buffer bytes.
|
||||
*/
|
||||
public byte[] getBytes() {
|
||||
return super.getBytes();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the size, in bytes, of the buffer pointed to by the pvBuffer member.
|
||||
*/
|
||||
public NativeLong cbBuffer;
|
||||
/**
|
||||
* Bit flags that indicate the type of buffer. Must be one of the values of
|
||||
* the SecBufferType enumeration.
|
||||
*/
|
||||
public NativeLong BufferType;
|
||||
/**
|
||||
* A pointer to a buffer.
|
||||
*/
|
||||
public Pointer pvBuffer;
|
||||
|
||||
/**
|
||||
* Create a new SECBUFFER_EMPTY buffer.
|
||||
*/
|
||||
public SecBuffer() {
|
||||
cbBuffer = new NativeLong(0);
|
||||
pvBuffer = null;
|
||||
BufferType = new NativeLong(SECBUFFER_EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SecBuffer of a given type and size.
|
||||
* @param type
|
||||
* Buffer type, one of SECBUFFER_EMTPY, etc.
|
||||
* @param size
|
||||
* Buffer size, eg. MAX_TOKEN_SIZE.
|
||||
*/
|
||||
public SecBuffer(int type, int size) {
|
||||
cbBuffer = new NativeLong(size);
|
||||
pvBuffer = new Memory(size);
|
||||
BufferType = new NativeLong(type);
|
||||
allocateMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SecBuffer of a given type with initial data.
|
||||
* @param type
|
||||
* Buffer type, one of SECBUFFER_EMTPY, etc.
|
||||
* @param token
|
||||
* Existing token.
|
||||
*/
|
||||
public SecBuffer(int type, byte[] token) {
|
||||
cbBuffer = new NativeLong(token.length);
|
||||
pvBuffer = new Memory(token.length);
|
||||
pvBuffer.write(0, token, 0, token.length);
|
||||
BufferType = new NativeLong(type);
|
||||
allocateMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get buffer bytes.
|
||||
* @return
|
||||
* Raw buffer bytes.
|
||||
*/
|
||||
public byte[] getBytes() {
|
||||
return pvBuffer.getByteArray(0, cbBuffer.intValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecBufferDesc extends Structure {
|
||||
|
||||
/**
|
||||
* Version number.
|
||||
*/
|
||||
public NativeLong ulVersion;
|
||||
/**
|
||||
* Number of buffers.
|
||||
*/
|
||||
public NativeLong cBuffers;
|
||||
/**
|
||||
* Pointer to array of buffers.
|
||||
*/
|
||||
public SecBuffer.ByReference[] pBuffers;
|
||||
|
||||
/**
|
||||
* Create a new SecBufferDesc with one SECBUFFER_EMPTY buffer.
|
||||
*/
|
||||
public SecBufferDesc() {
|
||||
ulVersion = new NativeLong(SECBUFFER_VERSION);
|
||||
cBuffers = new NativeLong(1);
|
||||
SecBuffer.ByReference secBuffer = new SecBuffer.ByReference();
|
||||
pBuffers = (SecBuffer.ByReference[]) secBuffer.toArray(1);
|
||||
allocateMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new SecBufferDesc with initial data.
|
||||
* @param type
|
||||
* Token type.
|
||||
* @param token
|
||||
* Initial token data.
|
||||
*/
|
||||
public SecBufferDesc(int type, byte[] token) {
|
||||
ulVersion = new NativeLong(SECBUFFER_VERSION);
|
||||
cBuffers = new NativeLong(1);
|
||||
SecBuffer.ByReference secBuffer = new SecBuffer.ByReference(type, token);
|
||||
pBuffers = (SecBuffer.ByReference[]) secBuffer.toArray(1);
|
||||
allocateMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new SecBufferDesc with one SecBuffer of a given type and size.
|
||||
* @param type
|
||||
* @param tokenSize
|
||||
*/
|
||||
public SecBufferDesc(int type, int tokenSize) {
|
||||
ulVersion = new NativeLong(SECBUFFER_VERSION);
|
||||
cBuffers = new NativeLong(1);
|
||||
SecBuffer.ByReference secBuffer = new SecBuffer.ByReference(type, tokenSize);
|
||||
pBuffers = (SecBuffer.ByReference[]) secBuffer.toArray(1);
|
||||
allocateMemory();
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
if (pBuffers == null || cBuffers == null) {
|
||||
throw new RuntimeException("pBuffers | cBuffers");
|
||||
}
|
||||
if (cBuffers.intValue() == 1) {
|
||||
return pBuffers[0].getBytes();
|
||||
}
|
||||
throw new RuntimeException("cBuffers > 1");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A security integer.
|
||||
*/
|
||||
public static class SECURITY_INTEGER extends Structure {
|
||||
public NativeLong dwLower;
|
||||
public NativeLong dwUpper;
|
||||
|
||||
/**
|
||||
* An security integer of 0.
|
||||
*/
|
||||
public SECURITY_INTEGER() {
|
||||
dwLower = new NativeLong(0);
|
||||
dwUpper = new NativeLong(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A timestamp.
|
||||
*/
|
||||
public static class TimeStamp extends SECURITY_INTEGER {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A pointer to an array of SecPkgInfo structures.
|
||||
*/
|
||||
public static class PSecPkgInfo extends Structure {
|
||||
|
||||
public static class ByReference extends PSecPkgInfo implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The first entry in an array of SecPkgInfo structures.
|
||||
*/
|
||||
public SecPkgInfo.ByReference pPkgInfo;
|
||||
|
||||
public PSecPkgInfo() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An array of SecPkgInfo structures.
|
||||
*/
|
||||
public SecPkgInfo.ByReference[] toArray(int size) {
|
||||
return (SecPkgInfo.ByReference[]) pPkgInfo.toArray(size);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The SecPkgInfo structure provides general information about a security package,
|
||||
* such as its name and capabilities.
|
||||
*/
|
||||
public static class SecPkgInfo extends Structure {
|
||||
|
||||
/**
|
||||
* A reference pointer to a SecPkgInfo structure.
|
||||
*/
|
||||
public static class ByReference extends SecPkgInfo implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set of bit flags that describes the capabilities of the security package.
|
||||
*/
|
||||
public NativeLong fCapabilities;
|
||||
/**
|
||||
* Specifies the version of the package protocol. Must be 1.
|
||||
*/
|
||||
public short wVersion;
|
||||
/**
|
||||
* Specifies a DCE RPC identifier, if appropriate. If the package does not implement one of
|
||||
* the DCE registered security systems, the reserved value SECPKG_ID_NONE is used.
|
||||
*/
|
||||
public short wRPCID;
|
||||
/**
|
||||
* Specifies the maximum size, in bytes, of the token.
|
||||
*/
|
||||
public NativeLong cbMaxToken;
|
||||
/**
|
||||
* Pointer to a null-terminated string that contains the name of the security package.
|
||||
*/
|
||||
public WString Name;
|
||||
/**
|
||||
* Pointer to a null-terminated string. This can be any additional string passed
|
||||
* back by the package.
|
||||
*/
|
||||
public WString Comment;
|
||||
|
||||
/**
|
||||
* Create a new package info.
|
||||
*/
|
||||
public SecPkgInfo() {
|
||||
fCapabilities = new NativeLong(0);
|
||||
wVersion = 1;
|
||||
wRPCID = 0;
|
||||
cbMaxToken = new NativeLong(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,735 @@
|
||||
/* 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.
|
||||
* <p/>
|
||||
* 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.platform.win32.BaseTSD.LONG_PTR;
|
||||
import com.sun.jna.platform.win32.WinDef.HDC;
|
||||
import com.sun.jna.platform.win32.WinDef.HICON;
|
||||
import com.sun.jna.platform.win32.WinDef.HINSTANCE;
|
||||
import com.sun.jna.platform.win32.WinDef.HRGN;
|
||||
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||
import com.sun.jna.platform.win32.WinDef.LPARAM;
|
||||
import com.sun.jna.platform.win32.WinDef.LRESULT;
|
||||
import com.sun.jna.platform.win32.WinDef.RECT;
|
||||
import com.sun.jna.platform.win32.WinDef.WPARAM;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinUser.BLENDFUNCTION;
|
||||
import com.sun.jna.platform.win32.WinUser.FLASHWINFO;
|
||||
import com.sun.jna.platform.win32.WinUser.GUITHREADINFO;
|
||||
import com.sun.jna.platform.win32.WinUser.HHOOK;
|
||||
import com.sun.jna.platform.win32.WinUser.HOOKPROC;
|
||||
import com.sun.jna.platform.win32.WinUser.MSG;
|
||||
import com.sun.jna.platform.win32.WinUser.POINT;
|
||||
import com.sun.jna.platform.win32.WinUser.SIZE;
|
||||
import com.sun.jna.platform.win32.WinUser.WINDOWINFO;
|
||||
import com.sun.jna.platform.win32.WinUser.WNDENUMPROC;
|
||||
import com.sun.jna.ptr.ByteByReference;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Provides access to the w32 user32 library. Incomplete implementation to
|
||||
* support demos.
|
||||
*
|
||||
* @author Todd Fast, todd.fast@sun.com
|
||||
* @author twalljava@dev.java.net
|
||||
*/
|
||||
public interface User32 extends StdCallLibrary {
|
||||
|
||||
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class,
|
||||
W32APIOptions.DEFAULT_OPTIONS);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -0,0 +1,258 @@
|
||||
/* 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.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.jna.platform.FileMonitor;
|
||||
import com.sun.jna.platform.win32.WinBase.OVERLAPPED;
|
||||
import com.sun.jna.platform.win32.WinNT.FILE_NOTIFY_INFORMATION;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
public class W32FileMonitor extends FileMonitor {
|
||||
|
||||
private static final int BUFFER_SIZE = 4096;
|
||||
|
||||
private class FileInfo {
|
||||
public final File file;
|
||||
public final HANDLE handle;
|
||||
public final int notifyMask;
|
||||
public final boolean recursive;
|
||||
public final FILE_NOTIFY_INFORMATION info = new FILE_NOTIFY_INFORMATION(BUFFER_SIZE);
|
||||
public final IntByReference infoLength = new IntByReference();
|
||||
public final OVERLAPPED overlapped = new OVERLAPPED();
|
||||
public FileInfo(File f, HANDLE h, int mask, boolean recurse) {
|
||||
this.file = f;
|
||||
this.handle = h;
|
||||
this.notifyMask = mask;
|
||||
this.recursive = recurse;
|
||||
}
|
||||
}
|
||||
private Thread watcher;
|
||||
private HANDLE port;
|
||||
private final Map<File, FileInfo> fileMap = new HashMap<File, FileInfo>();
|
||||
private final Map<HANDLE, FileInfo> handleMap = new HashMap<HANDLE, FileInfo>();
|
||||
private boolean disposing = false;
|
||||
|
||||
private void handleChanges(FileInfo finfo) throws IOException {
|
||||
Kernel32 klib = Kernel32.INSTANCE;
|
||||
FILE_NOTIFY_INFORMATION fni = finfo.info;
|
||||
// Need an explicit read, since data was filled in asynchronously
|
||||
fni.read();
|
||||
do {
|
||||
FileEvent event = null;
|
||||
File file = new File(finfo.file, fni.getFilename());
|
||||
switch(fni.Action) {
|
||||
case 0:
|
||||
break;
|
||||
case WinNT.FILE_ACTION_MODIFIED:
|
||||
event = new FileEvent(file, FILE_MODIFIED);
|
||||
break;
|
||||
case WinNT.FILE_ACTION_ADDED:
|
||||
event = new FileEvent(file, FILE_CREATED);
|
||||
break;
|
||||
case WinNT.FILE_ACTION_REMOVED:
|
||||
event = new FileEvent(file, FILE_DELETED);
|
||||
break;
|
||||
case WinNT.FILE_ACTION_RENAMED_OLD_NAME:
|
||||
event = new FileEvent(file, FILE_NAME_CHANGED_OLD);
|
||||
break;
|
||||
case WinNT.FILE_ACTION_RENAMED_NEW_NAME:
|
||||
event = new FileEvent(file, FILE_NAME_CHANGED_NEW);
|
||||
break;
|
||||
default:
|
||||
// TODO: other actions...
|
||||
System.err.println("Unrecognized file action '" + fni.Action + "'");
|
||||
}
|
||||
|
||||
if (event != null) {
|
||||
notify(event);
|
||||
}
|
||||
|
||||
fni = fni.next();
|
||||
} while (fni != null);
|
||||
|
||||
// trigger the next read
|
||||
if (!finfo.file.exists()) {
|
||||
unwatch(finfo.file);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!klib.ReadDirectoryChangesW(finfo.handle, finfo.info,
|
||||
finfo.info.size(), finfo.recursive, finfo.notifyMask,
|
||||
finfo.infoLength, finfo.overlapped, null)) {
|
||||
if (! disposing) {
|
||||
int err = klib.GetLastError();
|
||||
throw new IOException("ReadDirectoryChangesW failed on "
|
||||
+ finfo.file + ": '"
|
||||
+ Kernel32Util.formatMessageFromLastErrorCode(err)
|
||||
+ "' (" + err + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private FileInfo waitForChange() {
|
||||
Kernel32 klib = Kernel32.INSTANCE;
|
||||
IntByReference rcount = new IntByReference();
|
||||
HANDLEByReference rkey = new HANDLEByReference();
|
||||
PointerByReference roverlap = new PointerByReference();
|
||||
klib.GetQueuedCompletionStatus(port, rcount, rkey, roverlap, WinBase.INFINITE);
|
||||
|
||||
synchronized (this) {
|
||||
return (FileInfo)handleMap.get(rkey.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private int convertMask(int mask) {
|
||||
int result = 0;
|
||||
if ((mask & FILE_CREATED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_CREATION;
|
||||
}
|
||||
if ((mask & FILE_DELETED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_NAME;
|
||||
}
|
||||
if ((mask & FILE_MODIFIED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_LAST_WRITE;
|
||||
}
|
||||
if ((mask & FILE_RENAMED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_NAME;
|
||||
}
|
||||
if ((mask & FILE_SIZE_CHANGED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_SIZE;
|
||||
}
|
||||
if ((mask & FILE_ACCESSED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_LAST_ACCESS;
|
||||
}
|
||||
if ((mask & FILE_ATTRIBUTES_CHANGED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_ATTRIBUTES;
|
||||
}
|
||||
if ((mask & FILE_SECURITY_CHANGED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_SECURITY;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int watcherThreadID;
|
||||
|
||||
protected synchronized void watch(File file, int eventMask, boolean recursive) throws IOException {
|
||||
File dir = file;
|
||||
if (!dir.isDirectory()) {
|
||||
recursive = false;
|
||||
dir = file.getParentFile();
|
||||
}
|
||||
while (dir != null && !dir.exists()) {
|
||||
recursive = true;
|
||||
dir = dir.getParentFile();
|
||||
}
|
||||
if (dir == null) {
|
||||
throw new FileNotFoundException("No ancestor found for " + file);
|
||||
}
|
||||
Kernel32 klib = Kernel32.INSTANCE;
|
||||
int mask = WinNT.FILE_SHARE_READ
|
||||
| WinNT.FILE_SHARE_WRITE | WinNT.FILE_SHARE_DELETE;
|
||||
int flags = WinNT.FILE_FLAG_BACKUP_SEMANTICS
|
||||
| WinNT.FILE_FLAG_OVERLAPPED;
|
||||
HANDLE handle = klib.CreateFile(file.getAbsolutePath(),
|
||||
WinNT.FILE_LIST_DIRECTORY,
|
||||
mask, null, WinNT.OPEN_EXISTING,
|
||||
flags, null);
|
||||
if (WinBase.INVALID_HANDLE_VALUE.equals(handle)) {
|
||||
throw new IOException("Unable to open " + file + " ("
|
||||
+ klib.GetLastError() + ")");
|
||||
}
|
||||
int notifyMask = convertMask(eventMask);
|
||||
FileInfo finfo = new FileInfo(file, handle, notifyMask, recursive);
|
||||
fileMap.put(file, finfo);
|
||||
handleMap.put(handle, finfo);
|
||||
// Existing port is returned
|
||||
port = klib.CreateIoCompletionPort(handle, port, handle.getPointer(), 0);
|
||||
if (WinBase.INVALID_HANDLE_VALUE.equals(port)) {
|
||||
throw new IOException("Unable to create/use I/O Completion port "
|
||||
+ "for " + file + " ("
|
||||
+ klib.GetLastError() + ")");
|
||||
}
|
||||
// TODO: use FileIOCompletionRoutine callback method instead of a
|
||||
// dedicated thread
|
||||
if (!klib.ReadDirectoryChangesW(handle, finfo.info, finfo.info.size(),
|
||||
recursive, notifyMask, finfo.infoLength,
|
||||
finfo.overlapped, null)) {
|
||||
int err = klib.GetLastError();
|
||||
throw new IOException("ReadDirectoryChangesW failed on "
|
||||
+ finfo.file + ", handle " + handle
|
||||
+ ": '" + Kernel32Util.formatMessageFromLastErrorCode(err)
|
||||
+ "' (" + err + ")");
|
||||
}
|
||||
if (watcher == null) {
|
||||
watcher = new Thread("W32 File Monitor-" + (watcherThreadID++)) {
|
||||
public void run() {
|
||||
FileInfo finfo;
|
||||
while (true) {
|
||||
finfo = waitForChange();
|
||||
if (finfo == null) {
|
||||
synchronized(W32FileMonitor.this) {
|
||||
if (fileMap.isEmpty()) {
|
||||
watcher = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
handleChanges(finfo);
|
||||
}
|
||||
catch(IOException e) {
|
||||
// TODO: how is this best handled?
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
watcher.setDaemon(true);
|
||||
watcher.start();
|
||||
}
|
||||
}
|
||||
|
||||
protected synchronized void unwatch(File file) {
|
||||
FileInfo finfo = (FileInfo)fileMap.remove(file);
|
||||
if (finfo != null) {
|
||||
handleMap.remove(finfo.handle);
|
||||
Kernel32 klib = Kernel32.INSTANCE;
|
||||
// bug: the watcher may still be processing this file
|
||||
klib.CloseHandle(finfo.handle);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void dispose() {
|
||||
disposing = true;
|
||||
|
||||
// unwatch any remaining files in map, allows watcher thread to exit
|
||||
int i = 0;
|
||||
for (Object[] keys = fileMap.keySet().toArray(); !fileMap.isEmpty();) {
|
||||
unwatch((File)keys[i++]);
|
||||
}
|
||||
|
||||
Kernel32 klib = Kernel32.INSTANCE;
|
||||
klib.PostQueuedCompletionStatus(port, 0, null, null);
|
||||
klib.CloseHandle(port);
|
||||
port = null;
|
||||
watcher = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/* 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.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.FileUtils;
|
||||
|
||||
public class W32FileUtils extends FileUtils {
|
||||
|
||||
public boolean hasTrash() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void moveToTrash(File[] files) throws IOException {
|
||||
Shell32 shell = Shell32.INSTANCE;
|
||||
ShellAPI.SHFILEOPSTRUCT fileop = new ShellAPI.SHFILEOPSTRUCT();
|
||||
fileop.wFunc = ShellAPI.FO_DELETE;
|
||||
String[] paths = new String[files.length];
|
||||
for (int i=0;i < paths.length;i++) {
|
||||
paths[i] = files[i].getAbsolutePath();
|
||||
}
|
||||
fileop.pFrom = new WString(fileop.encodePaths(paths));
|
||||
fileop.fFlags = ShellAPI.FOF_ALLOWUNDO|ShellAPI.FOF_NOCONFIRMATION|ShellAPI.FOF_SILENT;
|
||||
int ret = shell.SHFileOperation(fileop);
|
||||
if (ret != 0) {
|
||||
throw new IOException("Move to trash failed: " +
|
||||
Kernel32Util.formatMessageFromLastErrorCode(ret));
|
||||
}
|
||||
if (fileop.fAnyOperationsAborted) {
|
||||
throw new IOException("Move to trash aborted");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010 Digital Rapids Corp.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2010 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;
|
||||
|
||||
/**
|
||||
* Constant defined in WTypes.h
|
||||
* @author scott.palmer
|
||||
*/
|
||||
public interface WTypes {
|
||||
public static final int CLSCTX_INPROC_SERVER = 0x1;
|
||||
public static final int CLSCTX_INPROC_HANDLER = 0x2;
|
||||
public static final int CLSCTX_LOCAL_SERVER = 0x4;
|
||||
public static final int CLSCTX_INPROC_SERVER16 = 0x8;
|
||||
public static final int CLSCTX_REMOTE_SERVER = 0x10;
|
||||
public static final int CLSCTX_INPROC_HANDLER16 = 0x20;
|
||||
public static final int CLSCTX_RESERVED1 = 0x40;
|
||||
public static final int CLSCTX_RESERVED2 = 0x80;
|
||||
public static final int CLSCTX_RESERVED3 = 0x100;
|
||||
public static final int CLSCTX_RESERVED4 = 0x200;
|
||||
public static final int CLSCTX_NO_CODE_DOWNLOAD = 0x400;
|
||||
public static final int CLSCTX_RESERVED5 = 0x800;
|
||||
public static final int CLSCTX_NO_CUSTOM_MARSHAL = 0x1000;
|
||||
public static final int CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000;
|
||||
public static final int CLSCTX_NO_FAILURE_LOG = 0x4000;
|
||||
public static final int CLSCTX_DISABLE_AAA = 0x8000;
|
||||
public static final int CLSCTX_ENABLE_AAA = 0x10000;
|
||||
public static final int CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000;
|
||||
public static final int CLSCTX_ACTIVATE_32_BIT_SERVER = 0x40000;
|
||||
public static final int CLSCTX_ACTIVATE_64_BIT_SERVER = 0x80000;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/* 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 com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from Wdm.h.
|
||||
* Microsoft Windows DDK.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Wdm extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* The KEY_BASIC_INFORMATION structure defines a subset of
|
||||
* the full information that is available for a registry key.
|
||||
*/
|
||||
public static class KEY_BASIC_INFORMATION extends Structure {
|
||||
public KEY_BASIC_INFORMATION() {
|
||||
super();
|
||||
}
|
||||
|
||||
public KEY_BASIC_INFORMATION(int size) {
|
||||
NameLength = size - 16; // write time, title index and name length
|
||||
Name = new char[NameLength];
|
||||
allocateMemory();
|
||||
}
|
||||
|
||||
public KEY_BASIC_INFORMATION(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* The last time the key or any of its values changed.
|
||||
*/
|
||||
public long LastWriteTime;
|
||||
/**
|
||||
* Device and intermediate drivers should ignore this member.
|
||||
*/
|
||||
public int TitleIndex;
|
||||
/**
|
||||
* Specifies the size in bytes of the following name.
|
||||
*/
|
||||
public int NameLength;
|
||||
/**
|
||||
* A string of Unicode characters naming the key.
|
||||
* The string is not null-terminated.
|
||||
*/
|
||||
public char[] Name;
|
||||
/**
|
||||
* Name of the key.
|
||||
* @return String.
|
||||
*/
|
||||
public String getName() {
|
||||
return Native.toString(Name);
|
||||
}
|
||||
|
||||
public void read() {
|
||||
super.read();
|
||||
Name = new char[NameLength / 2];
|
||||
readField("Name");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The KEY_INFORMATION_CLASS enumeration type represents
|
||||
* the type of information to supply about a registry key.
|
||||
*/
|
||||
public abstract class KEY_INFORMATION_CLASS {
|
||||
public static final int KeyBasicInformation = 0;
|
||||
public static final int KeyNodeInformation = 1;
|
||||
public static final int KeyFullInformation = 2;
|
||||
public static final int KeyNameInformation = 3;
|
||||
public static final int KeyCachedInformation = 4;
|
||||
public static final int KeyVirtualizationInformation = 5;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/* 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 com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
|
||||
/**
|
||||
* Win32 exception.
|
||||
* @author dblock[at]dblock[dot]org
|
||||
*/
|
||||
public class Win32Exception extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private HRESULT _hr;
|
||||
|
||||
/**
|
||||
* Returns the error code of the error.
|
||||
* @return
|
||||
* Error code.
|
||||
*/
|
||||
public HRESULT getHR() {
|
||||
return _hr;
|
||||
}
|
||||
|
||||
/**
|
||||
* New Win32 exception from HRESULT.
|
||||
* @param hr
|
||||
* HRESULT
|
||||
*/
|
||||
public Win32Exception(HRESULT hr) {
|
||||
super(Kernel32Util.formatMessageFromHR(hr));
|
||||
_hr = hr;
|
||||
}
|
||||
|
||||
/**
|
||||
* New Win32 exception from an error code, usually obtained from GetLastError.
|
||||
* @param code
|
||||
* Error code.
|
||||
*/
|
||||
public Win32Exception(int code) {
|
||||
this(W32Errors.HRESULT_FROM_WIN32(code));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,469 @@
|
||||
/* 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.Date;
|
||||
|
||||
import com.sun.jna.Platform;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.Union;
|
||||
import com.sun.jna.platform.win32.BaseTSD.DWORD_PTR;
|
||||
import com.sun.jna.platform.win32.BaseTSD.ULONG_PTR;
|
||||
import com.sun.jna.platform.win32.WinDef.DWORD;
|
||||
import com.sun.jna.platform.win32.WinDef.DWORDLONG;
|
||||
import com.sun.jna.platform.win32.WinDef.WORD;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
|
||||
/**
|
||||
* Ported from Winbase.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class WinBase {
|
||||
|
||||
/** Constant value representing an invalid HANDLE. */
|
||||
public static HANDLE INVALID_HANDLE_VALUE = new HANDLE(Pointer.createConstant(
|
||||
Pointer.SIZE == 8 ? -1 : 0xFFFFFFFFL));
|
||||
|
||||
public static final int WAIT_FAILED = 0xFFFFFFFF;
|
||||
public static final int WAIT_OBJECT_0 = ((NTStatus.STATUS_WAIT_0 ) + 0 );
|
||||
public static final int WAIT_ABANDONED = ((NTStatus.STATUS_ABANDONED_WAIT_0 ) + 0 );
|
||||
public static final int WAIT_ABANDONED_0 = ((NTStatus.STATUS_ABANDONED_WAIT_0 ) + 0 );
|
||||
|
||||
/**
|
||||
* Maximum computer name length.
|
||||
* @return 15 on MAC, 31 on everything else.
|
||||
*/
|
||||
public static int MAX_COMPUTERNAME_LENGTH() {
|
||||
if (Platform.isMac()) {
|
||||
return 15;
|
||||
} else {
|
||||
return 31;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This logon type is intended for users who will be interactively using the computer, such
|
||||
* as a user being logged on by a terminal server, remote shell, or similar process. This
|
||||
* logon type has the additional expense of caching logon information for disconnected operations;
|
||||
* therefore, it is inappropriate for some client/server applications, such as a mail server.
|
||||
*/
|
||||
public static final int LOGON32_LOGON_INTERACTIVE = 2;
|
||||
/**
|
||||
* This logon type is intended for high performance servers to authenticate plaintext passwords.
|
||||
* The LogonUser function does not cache credentials for this logon type.
|
||||
*/
|
||||
public static final int LOGON32_LOGON_NETWORK = 3;
|
||||
/**
|
||||
* This logon type is intended for batch servers, where processes may be executing on behalf
|
||||
* of a user without their direct intervention. This type is also for higher performance servers
|
||||
* that process many plaintext authentication attempts at a time, such as mail or Web servers.
|
||||
* The LogonUser function does not cache credentials for this logon type.
|
||||
*/
|
||||
public static final int LOGON32_LOGON_BATCH = 4;
|
||||
/**
|
||||
* Indicates a service-type logon. The account provided must have the service privilege enabled.
|
||||
*/
|
||||
public static final int LOGON32_LOGON_SERVICE = 5;
|
||||
/**
|
||||
* This logon type is for GINA DLLs that log on users who will be interactively using the computer.
|
||||
* This logon type can generate a unique audit record that shows when the workstation was unlocked.
|
||||
*/
|
||||
public static final int LOGON32_LOGON_UNLOCK = 7;
|
||||
/**
|
||||
* This logon type preserves the name and password in the authentication package, which allows the
|
||||
* server to make connections to other network servers while impersonating the client. A server can
|
||||
* accept plaintext credentials from a client, call LogonUser, verify that the user can access the
|
||||
* system across the network, and still communicate with other servers.
|
||||
*/
|
||||
public static final int LOGON32_LOGON_NETWORK_CLEARTEXT = 8;
|
||||
/**
|
||||
* This logon type allows the caller to clone its current token and specify new credentials for
|
||||
* outbound connections. The new logon session has the same local identifier but uses different
|
||||
* credentials for other network connections. This logon type is supported only by the
|
||||
* LOGON32_PROVIDER_WINNT50 logon provider.
|
||||
*/
|
||||
public static final int LOGON32_LOGON_NEW_CREDENTIALS = 9;
|
||||
|
||||
/**
|
||||
* Use the standard logon provider for the system. The default security provider is negotiate,
|
||||
* unless you pass NULL for the domain name and the user name is not in UPN format. In this case,
|
||||
* the default provider is NTLM.
|
||||
*/
|
||||
public static final int LOGON32_PROVIDER_DEFAULT = 0;
|
||||
|
||||
/**
|
||||
* Use the Windows NT 3.5 logon provider.
|
||||
*/
|
||||
public static final int LOGON32_PROVIDER_WINNT35 = 1;
|
||||
/**
|
||||
* Use the NTLM logon provider.
|
||||
*/
|
||||
public static final int LOGON32_PROVIDER_WINNT40 = 2;
|
||||
/**
|
||||
* Use the negotiate logon provider.
|
||||
*/
|
||||
public static final int LOGON32_PROVIDER_WINNT50 = 3;
|
||||
|
||||
|
||||
/**
|
||||
* The FILETIME structure is a 64-bit value representing the number of
|
||||
* 100-nanosecond intervals since January 1, 1601 (UTC).
|
||||
* Conversion code in this class Copyright 2002-2004 Apache Software Foundation.
|
||||
* @author Rainer Klute (klute@rainer-klute.de) for the Apache Software Foundation (org.apache.poi.hpsf)
|
||||
*/
|
||||
public static class FILETIME extends Structure {
|
||||
public int dwLowDateTime;
|
||||
public int dwHighDateTime;
|
||||
|
||||
/**
|
||||
* <p>The difference between the Windows epoch (1601-01-01
|
||||
* 00:00:00) and the Unix epoch (1970-01-01 00:00:00) in
|
||||
* milliseconds: 11644473600000L. (Use your favorite spreadsheet
|
||||
* program to verify the correctness of this value. By the way,
|
||||
* did you notice that you can tell from the epochs which
|
||||
* operating system is the modern one? :-))</p>
|
||||
*/
|
||||
private static final long EPOCH_DIFF = 11644473600000L;
|
||||
|
||||
/**
|
||||
* <p>Converts a Windows FILETIME into a {@link Date}. The Windows
|
||||
* FILETIME structure holds a date and time associated with a
|
||||
* file. The structure identifies a 64-bit integer specifying the
|
||||
* number of 100-nanosecond intervals which have passed since
|
||||
* January 1, 1601. This 64-bit value is split into the two double
|
||||
* words stored in the structure.</p>
|
||||
*
|
||||
* @param high The higher double word of the FILETIME structure.
|
||||
* @param low The lower double word of the FILETIME structure.
|
||||
* @return The Windows FILETIME as a {@link Date}.
|
||||
*/
|
||||
public static Date filetimeToDate(final int high, final int low) {
|
||||
final long filetime = (long) high << 32 | low & 0xffffffffL;
|
||||
final long ms_since_16010101 = filetime / (1000 * 10);
|
||||
final long ms_since_19700101 = ms_since_16010101 - EPOCH_DIFF;
|
||||
return new Date(ms_since_19700101);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Converts a {@link Date} into a filetime.</p>
|
||||
*
|
||||
* @param date The date to be converted
|
||||
* @return The filetime
|
||||
*
|
||||
* @see #filetimeToDate
|
||||
*/
|
||||
public static long dateToFileTime(final Date date) {
|
||||
final long ms_since_19700101 = date.getTime();
|
||||
final long ms_since_16010101 = ms_since_19700101 + EPOCH_DIFF;
|
||||
return ms_since_16010101 * 1000 * 10;
|
||||
}
|
||||
|
||||
public Date toDate() {
|
||||
return filetimeToDate(dwHighDateTime, dwLowDateTime);
|
||||
}
|
||||
|
||||
public long toLong() {
|
||||
return toDate().getTime();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ": " + toDate().toString(); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/* Local Memory Flags */
|
||||
public static final int LMEM_FIXED = 0x0000;
|
||||
public static final int LMEM_MOVEABLE = 0x0002;
|
||||
public static final int LMEM_NOCOMPACT = 0x0010;
|
||||
public static final int LMEM_NODISCARD = 0x0020;
|
||||
public static final int LMEM_ZEROINIT = 0x0040;
|
||||
public static final int LMEM_MODIFY = 0x0080;
|
||||
public static final int LMEM_DISCARDABLE = 0x0F00;
|
||||
public static final int LMEM_VALID_FLAGS = 0x0F72;
|
||||
public static final int LMEM_INVALID_HANDLE = 0x8000;
|
||||
|
||||
public static final int LHND = (LMEM_MOVEABLE | LMEM_ZEROINIT);
|
||||
public static final int LPTR = (LMEM_FIXED | LMEM_ZEROINIT);
|
||||
|
||||
/* Flags returned by LocalFlags (in addition to LMEM_DISCARDABLE) */
|
||||
public static final int LMEM_DISCARDED = 0x4000;
|
||||
public static final int LMEM_LOCKCOUNT = 0x00FF;
|
||||
|
||||
/**
|
||||
* Specifies a date and time, using individual members for the month,
|
||||
* day, year, weekday, hour, minute, second, and millisecond. The time
|
||||
* is either in coordinated universal time (UTC) or local time, depending
|
||||
* on the function that is being called.
|
||||
* http://msdn.microsoft.com/en-us/library/ms724950(VS.85).aspx
|
||||
*/
|
||||
public static class SYSTEMTIME extends Structure {
|
||||
// The year. The valid values for this member are 1601 through 30827.
|
||||
public short wYear;
|
||||
// The month. The valid values for this member are 1 through 12.
|
||||
public short wMonth;
|
||||
// The day of the week. The valid values for this member are 0 through 6.
|
||||
public short wDayOfWeek;
|
||||
// The day of the month. The valid values for this member are 1 through 31.
|
||||
public short wDay;
|
||||
// The hour. The valid values for this member are 0 through 23.
|
||||
public short wHour;
|
||||
// The minute. The valid values for this member are 0 through 59.
|
||||
public short wMinute;
|
||||
// The second. The valid values for this member are 0 through 59.
|
||||
public short wSecond;
|
||||
// The millisecond. The valid values for this member are 0 through 999.
|
||||
public short wMilliseconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* The lpBuffer parameter is a pointer to a PVOID pointer, and that the nSize
|
||||
* parameter specifies the minimum number of TCHARs to allocate for an output
|
||||
* message buffer. The function allocates a buffer large enough to hold the
|
||||
* formatted message, and places a pointer to the allocated buffer at the address
|
||||
* specified by lpBuffer. The caller should use the LocalFree function to free
|
||||
* the buffer when it is no longer needed.
|
||||
*/
|
||||
public static final int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
|
||||
/**
|
||||
* Insert sequences in the message definition are to be ignored and passed through
|
||||
* to the output buffer unchanged. This flag is useful for fetching a message for
|
||||
* later formatting. If this flag is set, the Arguments parameter is ignored.
|
||||
*/
|
||||
public static final int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
|
||||
/**
|
||||
* The lpSource parameter is a pointer to a null-terminated message definition.
|
||||
* The message definition may contain insert sequences, just as the message text
|
||||
* in a message table resource may. Cannot be used with FORMAT_MESSAGE_FROM_HMODULE
|
||||
* or FORMAT_MESSAGE_FROM_SYSTEM.
|
||||
*/
|
||||
public static final int FORMAT_MESSAGE_FROM_STRING = 0x00000400;
|
||||
/**
|
||||
* The lpSource parameter is a module handle containing the message-table
|
||||
* resource(s) to search. If this lpSource handle is NULL, the current process's
|
||||
* application image file will be searched. Cannot be used with
|
||||
* FORMAT_MESSAGE_FROM_STRING.
|
||||
*/
|
||||
public static final int FORMAT_MESSAGE_FROM_HMODULE = 0x00000800;
|
||||
/**
|
||||
* The function should search the system message-table resource(s) for the
|
||||
* requested message. If this flag is specified with FORMAT_MESSAGE_FROM_HMODULE,
|
||||
* the function searches the system message table if the message is not found in
|
||||
* the module specified by lpSource. Cannot be used with FORMAT_MESSAGE_FROM_STRING.
|
||||
* If this flag is specified, an application can pass the result of the
|
||||
* GetLastError function to retrieve the message text for a system-defined error.
|
||||
*/
|
||||
public static final int FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
|
||||
/**
|
||||
* The Arguments parameter is not a va_list structure, but is a pointer to an array
|
||||
* of values that represent the arguments. This flag cannot be used with 64-bit
|
||||
* argument values. If you are using 64-bit values, you must use the va_list
|
||||
* structure.
|
||||
*/
|
||||
public static final int FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000;
|
||||
|
||||
/**
|
||||
* The drive type cannot be determined.
|
||||
*/
|
||||
public static final int DRIVE_UNKNOWN = 0;
|
||||
/**
|
||||
* The root path is invalid, for example, no volume is mounted at the path.
|
||||
*/
|
||||
public static final int DRIVE_NO_ROOT_DIR = 1;
|
||||
/**
|
||||
* The drive is a type that has removable media, for example, a floppy drive
|
||||
* or removable hard disk.
|
||||
*/
|
||||
public static final int DRIVE_REMOVABLE = 2;
|
||||
/**
|
||||
* The drive is a type that cannot be removed, for example, a fixed hard drive.
|
||||
*/
|
||||
public static final int DRIVE_FIXED = 3;
|
||||
/**
|
||||
* The drive is a remote (network) drive.
|
||||
*/
|
||||
public static final int DRIVE_REMOTE = 4;
|
||||
/**
|
||||
* The drive is a CD-ROM drive.
|
||||
*/
|
||||
public static final int DRIVE_CDROM = 5;
|
||||
/**
|
||||
* The drive is a RAM disk.
|
||||
*/
|
||||
public static final int DRIVE_RAMDISK = 6;
|
||||
|
||||
/**
|
||||
* The OVERLAPPED structure contains information used in
|
||||
* asynchronous (or overlapped) input and output (I/O).
|
||||
*/
|
||||
public static class OVERLAPPED extends Structure {
|
||||
public ULONG_PTR Internal;
|
||||
public ULONG_PTR InternalHigh;
|
||||
public int Offset;
|
||||
public int OffsetHigh;
|
||||
public HANDLE hEvent;
|
||||
}
|
||||
|
||||
public static final int INFINITE = 0xFFFFFFFF;
|
||||
|
||||
/**
|
||||
* Contains information about the current computer system. This includes the architecture and
|
||||
* type of the processor, the number of processors in the system, the page size, and other such
|
||||
* information.
|
||||
*/
|
||||
public static class SYSTEM_INFO extends Structure {
|
||||
|
||||
public static class PI extends Structure {
|
||||
|
||||
public static class ByReference extends PI implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* System's processor architecture.
|
||||
* This value can be one of the following values:
|
||||
*
|
||||
* PROCESSOR_ARCHITECTURE_UNKNOWN
|
||||
* PROCESSOR_ARCHITECTURE_INTEL
|
||||
* PROCESSOR_ARCHITECTURE_IA64
|
||||
* PROCESSOR_ARCHITECTURE_AMD64
|
||||
*/
|
||||
public WORD wProcessorArchitecture;
|
||||
/**
|
||||
* Reserved for future use.
|
||||
*/
|
||||
public WORD wReserved;
|
||||
}
|
||||
|
||||
public static class UNION extends Union {
|
||||
|
||||
public static class ByReference extends UNION implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An obsolete member that is retained for compatibility with Windows NT 3.5 and earlier.
|
||||
* New applications should use the wProcessorArchitecture branch of the union.
|
||||
* Windows Me/98/95: The system always sets this member to zero, the value defined
|
||||
* for PROCESSOR_ARCHITECTURE_INTEL.
|
||||
*/
|
||||
public DWORD dwOemID;
|
||||
/**
|
||||
* Processor architecture.
|
||||
*/
|
||||
public PI.ByReference pi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processor architecture.
|
||||
*/
|
||||
public UNION.ByReference processorArchitecture;
|
||||
/**
|
||||
* Page size and the granularity of page protection and commitment.
|
||||
*/
|
||||
public DWORD dwPageSize;
|
||||
/**
|
||||
* Pointer to the lowest memory address accessible to applications and dynamic-link libraries (DLLs).
|
||||
*/
|
||||
public Pointer lpMinimumApplicationAddress;
|
||||
/**
|
||||
* Pointer to the highest memory address accessible to applications and DLLs.
|
||||
*/
|
||||
public Pointer lpMaximumApplicationAddress;
|
||||
/**
|
||||
* Mask representing the set of processors configured into the system. Bit 0 is processor 0; bit 31 is processor 31.
|
||||
*/
|
||||
public DWORD_PTR dwActiveProcessorMask;
|
||||
/**
|
||||
* Number of processors in the system.
|
||||
*/
|
||||
public DWORD dwNumberOfProcessors;
|
||||
/**
|
||||
* An obsolete member that is retained for compatibility with Windows NT 3.5 and Windows Me/98/95.
|
||||
* Use the wProcessorArchitecture, wProcessorLevel, and wProcessorRevision members to determine
|
||||
* the type of processor.
|
||||
* PROCESSOR_INTEL_386
|
||||
* PROCESSOR_INTEL_486
|
||||
* PROCESSOR_INTEL_PENTIUM
|
||||
*/
|
||||
public DWORD dwProcessorType;
|
||||
/**
|
||||
* Granularity for the starting address at which virtual memory can be allocated.
|
||||
*/
|
||||
public DWORD dwAllocationGranularity;
|
||||
/**
|
||||
* System's architecture-dependent processor level. It should be used only for display purposes.
|
||||
* To determine the feature set of a processor, use the IsProcessorFeaturePresent function.
|
||||
* If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_INTEL, wProcessorLevel is defined by the CPU vendor.
|
||||
* If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_IA64, wProcessorLevel is set to 1.
|
||||
*/
|
||||
public WORD wProcessorLevel;
|
||||
/**
|
||||
* Architecture-dependent processor revision.
|
||||
*/
|
||||
public WORD wProcessorRevision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains information about the current state of both physical and virtual memory, including
|
||||
* extended memory. The GlobalMemoryStatusEx function stores information in this structure.
|
||||
*/
|
||||
public static class MEMORYSTATUSEX extends Structure {
|
||||
/**
|
||||
* The size of the structure, in bytes.
|
||||
*/
|
||||
public DWORD dwLength;
|
||||
/**
|
||||
* A number between 0 and 100 that specifies the approximate percentage of physical memory
|
||||
* that is in use (0 indicates no memory use and 100 indicates full memory use).
|
||||
*/
|
||||
public DWORD dwMemoryLoad;
|
||||
/**
|
||||
* The amount of actual physical memory, in bytes.
|
||||
*/
|
||||
public DWORDLONG ullTotalPhys;
|
||||
/**
|
||||
* The amount of physical memory currently available, in bytes. This is the amount of physical
|
||||
* memory that can be immediately reused without having to write its contents to disk first.
|
||||
* It is the sum of the size of the standby, free, and zero lists.
|
||||
*/
|
||||
public DWORDLONG ullAvailPhys;
|
||||
/**
|
||||
* The current committed memory limit for the system or the current process, whichever is smaller, in bytes.
|
||||
*/
|
||||
public DWORDLONG ullTotalPageFile;
|
||||
/**
|
||||
* The maximum amount of memory the current process can commit, in bytes. This value is equal to or smaller
|
||||
* than the system-wide available commit value.
|
||||
*/
|
||||
public DWORDLONG ullAvailPageFile;
|
||||
/**
|
||||
* The size of the user-mode portion of the virtual address space of the calling process, in bytes.
|
||||
*/
|
||||
public DWORDLONG ullTotalVirtual;
|
||||
/**
|
||||
* The amount of unreserved and uncommitted memory currently in the user-mode portion of the
|
||||
* virtual address space of the calling process, in bytes.
|
||||
*/
|
||||
public DWORDLONG ullAvailVirtual;
|
||||
/**
|
||||
* Reserved. This value is always 0.
|
||||
*/
|
||||
public DWORDLONG ullAvailExtendedVirtual;
|
||||
|
||||
public MEMORYSTATUSEX() {
|
||||
dwLength = new DWORD(size());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/* 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 com.sun.jna.Memory;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from WinCrypt.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface WinCrypt extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* The CryptoAPI CRYPTOAPI_BLOB structure is used for an arbitrary array of bytes.
|
||||
*/
|
||||
public static class DATA_BLOB extends Structure {
|
||||
public DATA_BLOB() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DATA_BLOB(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public DATA_BLOB(byte [] data) {
|
||||
pbData = new Memory(data.length);
|
||||
pbData.write(0, data, 0, data.length);
|
||||
cbData = data.length;
|
||||
allocateMemory();
|
||||
}
|
||||
|
||||
public DATA_BLOB(String s) {
|
||||
this(Native.toByteArray(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* The count of bytes in the buffer pointed to by pbData.
|
||||
*/
|
||||
public int cbData;
|
||||
/**
|
||||
* A pointer to a block of data bytes.
|
||||
*/
|
||||
public Pointer pbData;
|
||||
|
||||
/**
|
||||
* Get byte data.
|
||||
* @return
|
||||
* Byte data or null.
|
||||
*/
|
||||
public byte[] getData() {
|
||||
return pbData == null ? null : pbData.getByteArray(0, cbData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The CRYPTPROTECT_PROMPTSTRUCT structure provides the text of a prompt and
|
||||
* information about when and where that prompt is to be displayed when using
|
||||
* the CryptProtectData and CryptUnprotectData functions.
|
||||
*/
|
||||
public static class CRYPTPROTECT_PROMPTSTRUCT extends Structure {
|
||||
public CRYPTPROTECT_PROMPTSTRUCT() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CRYPTPROTECT_PROMPTSTRUCT(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Size of this structure in bytes.
|
||||
*/
|
||||
public int cbSize;
|
||||
/**
|
||||
* DWORD flags that indicate when prompts to the user are to be displayed.
|
||||
*/
|
||||
public int dwPromptFlags;
|
||||
/**
|
||||
* Window handle to the parent window.
|
||||
*/
|
||||
public HWND hwndApp;
|
||||
/**
|
||||
* A string containing the text of a prompt to be displayed.
|
||||
*/
|
||||
public String szPrompt;
|
||||
}
|
||||
|
||||
//
|
||||
// CryptProtect PromptStruct dwPromtFlags
|
||||
//
|
||||
|
||||
/**
|
||||
* Prompt on unprotect.
|
||||
*/
|
||||
public static final int CRYPTPROTECT_PROMPT_ON_UNPROTECT = 0x1; // 1<<0
|
||||
/**
|
||||
* Prompt on protect.
|
||||
*/
|
||||
public static final int CRYPTPROTECT_PROMPT_ON_PROTECT = 0x2; // 1<<1
|
||||
/**
|
||||
* Reserved, don't use.
|
||||
*/
|
||||
public static final int CRYPTPROTECT_PROMPT_RESERVED = 0x04;
|
||||
/**
|
||||
* Default to strong variant UI protection (user supplied password currently).
|
||||
*/
|
||||
public static final int CRYPTPROTECT_PROMPT_STRONG = 0x08; // 1<<3
|
||||
/**
|
||||
* Require strong variant UI protection (user supplied password currently).
|
||||
*/
|
||||
public static final int CRYPTPROTECT_PROMPT_REQUIRE_STRONG = 0x10; // 1<<4
|
||||
|
||||
//
|
||||
// CryptProtectData and CryptUnprotectData dwFlags
|
||||
//
|
||||
/**
|
||||
* For remote-access situations where ui is not an option, if UI was specified
|
||||
* on protect or unprotect operation, the call will fail and GetLastError() will
|
||||
* indicate ERROR_PASSWORD_RESTRICTION.
|
||||
*/
|
||||
public static final int CRYPTPROTECT_UI_FORBIDDEN = 0x1;
|
||||
/**
|
||||
* Per machine protected data -- any user on machine where CryptProtectData
|
||||
* took place may CryptUnprotectData.
|
||||
*/
|
||||
public static final int CRYPTPROTECT_LOCAL_MACHINE = 0x4;
|
||||
/**
|
||||
* Force credential synchronize during CryptProtectData()
|
||||
* Synchronize is only operation that occurs during this operation.
|
||||
*/
|
||||
public static final int CRYPTPROTECT_CRED_SYNC = 0x8;
|
||||
/**
|
||||
* Generate an Audit on protect and unprotect operations.
|
||||
*/
|
||||
public static final int CRYPTPROTECT_AUDIT = 0x10;
|
||||
/**
|
||||
* Protect data with a non-recoverable key.
|
||||
*/
|
||||
public static final int CRYPTPROTECT_NO_RECOVERY = 0x20;
|
||||
/**
|
||||
* Verify the protection of a protected blob.
|
||||
*/
|
||||
public static final int CRYPTPROTECT_VERIFY_PROTECTION = 0x40;
|
||||
/**
|
||||
* Regenerate the local machine protection.
|
||||
*/
|
||||
public static final int CRYPTPROTECT_CRED_REGENERATE = 0x80;
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
/* 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.awt.Rectangle;
|
||||
|
||||
import com.sun.jna.IntegerType;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.BaseTSD.LONG_PTR;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from Windef.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public interface WinDef extends StdCallLibrary {
|
||||
|
||||
public static final int MAX_PATH = 260;
|
||||
|
||||
/**
|
||||
* 16-bit unsigned integer.
|
||||
*/
|
||||
public static class WORD extends IntegerType {
|
||||
public WORD() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public WORD(long value) {
|
||||
super(2, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 32-bit unsigned integer.
|
||||
*/
|
||||
public static class DWORD extends IntegerType {
|
||||
public DWORD() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public DWORD(long value) {
|
||||
super(4, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Low WORD.
|
||||
* @return
|
||||
* Low WORD.
|
||||
*/
|
||||
public WORD getLow() {
|
||||
return new WORD(longValue() & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* High WORD.
|
||||
* @return
|
||||
* High WORD.
|
||||
*/
|
||||
public WORD getHigh() {
|
||||
return new WORD((longValue() >> 8) & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 32-bit signed integer.
|
||||
*/
|
||||
public static class LONG extends IntegerType {
|
||||
public LONG() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public LONG(long value) {
|
||||
super(Native.LONG_SIZE, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a device context (DC).
|
||||
*/
|
||||
public static class HDC extends HANDLE {
|
||||
public HDC() {
|
||||
|
||||
}
|
||||
|
||||
public HDC(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to an icon.
|
||||
*/
|
||||
public static class HICON extends HANDLE {
|
||||
public HICON() {
|
||||
|
||||
}
|
||||
|
||||
public HICON(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a cursor.
|
||||
*/
|
||||
public static class HCURSOR extends HICON {
|
||||
public HCURSOR() {
|
||||
|
||||
}
|
||||
|
||||
public HCURSOR(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a cursor.
|
||||
*/
|
||||
public static class HMENU extends HANDLE {
|
||||
public HMENU() {
|
||||
|
||||
}
|
||||
|
||||
public HMENU(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a pen.
|
||||
*/
|
||||
public static class HPEN extends HANDLE {
|
||||
public HPEN() {
|
||||
|
||||
}
|
||||
|
||||
public HPEN(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a resource.
|
||||
*/
|
||||
public static class HRSRC extends HANDLE {
|
||||
public HRSRC() {
|
||||
|
||||
}
|
||||
|
||||
public HRSRC(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a palette.
|
||||
*/
|
||||
public static class HPALETTE extends HANDLE {
|
||||
public HPALETTE() {
|
||||
|
||||
}
|
||||
|
||||
public HPALETTE(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a bitmap.
|
||||
*/
|
||||
public static class HBITMAP extends HANDLE {
|
||||
public HBITMAP() {
|
||||
|
||||
}
|
||||
|
||||
public HBITMAP(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a region.
|
||||
*/
|
||||
public static class HRGN extends HANDLE {
|
||||
public HRGN() {
|
||||
|
||||
}
|
||||
|
||||
public HRGN(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a window.
|
||||
*/
|
||||
public static class HWND extends HANDLE {
|
||||
public HWND() {
|
||||
|
||||
}
|
||||
|
||||
public HWND(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to an instance.
|
||||
*/
|
||||
public static class HINSTANCE extends HANDLE {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a module. The value is the base address of the module.
|
||||
*/
|
||||
public static class HMODULE extends HINSTANCE {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a font.
|
||||
*/
|
||||
public static class HFONT extends HANDLE {
|
||||
public HFONT() {
|
||||
|
||||
}
|
||||
|
||||
public HFONT(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Message parameter.
|
||||
*/
|
||||
public static class LPARAM extends LONG_PTR {
|
||||
public LPARAM() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public LPARAM(long value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Signed result of message processing.
|
||||
*/
|
||||
public static class LRESULT extends LONG_PTR {
|
||||
public LRESULT() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public LRESULT(long value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsigned INT_PTR.
|
||||
*/
|
||||
public static class UINT_PTR extends IntegerType {
|
||||
public UINT_PTR() {
|
||||
super(Pointer.SIZE);
|
||||
}
|
||||
|
||||
public UINT_PTR(long value) {
|
||||
super(Pointer.SIZE, value);
|
||||
}
|
||||
|
||||
public Pointer toPointer() {
|
||||
return Pointer.createConstant(longValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Message parameter.
|
||||
*/
|
||||
public static class WPARAM extends UINT_PTR {
|
||||
public WPARAM() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public WPARAM(long value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
||||
|
||||
public class RECT extends Structure {
|
||||
public int left;
|
||||
public int top;
|
||||
public int right;
|
||||
public int bottom;
|
||||
|
||||
public Rectangle toRectangle() {
|
||||
return new Rectangle(left, top, right-left, bottom-top);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "[(" + left + "," + top + ")(" + right + "," + bottom + ")]";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 64-bit unsigned integer.
|
||||
*/
|
||||
public static class ULONGLONG extends IntegerType {
|
||||
public ULONGLONG() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public ULONGLONG(long value) {
|
||||
super(8, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 64-bit unsigned integer.
|
||||
*/
|
||||
public static class DWORDLONG extends IntegerType {
|
||||
public DWORDLONG() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public DWORDLONG(long value) {
|
||||
super(8, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/* 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 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;
|
||||
}
|
||||
|
||||
public class RGNDATA extends Structure {
|
||||
public RGNDATAHEADER rdh;
|
||||
public byte[] 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;
|
||||
}
|
||||
|
||||
public class RGBQUAD extends Structure {
|
||||
public byte rgbBlue;
|
||||
public byte rgbGreen;
|
||||
public byte rgbRed;
|
||||
public byte rgbReserved = 0;
|
||||
}
|
||||
|
||||
public class BITMAPINFO extends Structure {
|
||||
public BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
|
||||
public RGBQUAD[] bmiColors = new RGBQUAD[1];
|
||||
public BITMAPINFO() { this(1); }
|
||||
public BITMAPINFO(int size) {
|
||||
bmiColors = new RGBQUAD[size];
|
||||
}
|
||||
}
|
||||
|
||||
public int DIB_RGB_COLORS = 0;
|
||||
public int DIB_PAL_COLORS = 1;
|
||||
}
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -0,0 +1,70 @@
|
||||
/* 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 com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.ptr.ByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* This module contains the function prototypes and constant, type and structure
|
||||
* definitions for the Windows 32-Bit Registry API.
|
||||
* Ported from WinReg.h
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface WinReg extends StdCallLibrary {
|
||||
|
||||
public static class HKEY extends HANDLE {
|
||||
public HKEY() { }
|
||||
public HKEY(Pointer p) { super(p); }
|
||||
public HKEY(int value) { super(new Pointer(value)); }
|
||||
}
|
||||
|
||||
public static class HKEYByReference extends ByReference {
|
||||
public HKEYByReference() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public HKEYByReference(HKEY h) {
|
||||
super(Pointer.SIZE);
|
||||
setValue(h);
|
||||
}
|
||||
|
||||
public void setValue(HKEY h) {
|
||||
getPointer().setPointer(0, h != null ? h.getPointer() : null);
|
||||
}
|
||||
|
||||
public HKEY getValue() {
|
||||
Pointer p = getPointer().getPointer(0);
|
||||
if (p == null)
|
||||
return null;
|
||||
if (WinBase.INVALID_HANDLE_VALUE.getPointer().equals(p))
|
||||
return (HKEY) WinBase.INVALID_HANDLE_VALUE;
|
||||
HKEY h = new HKEY();
|
||||
h.setPointer(p);
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
public static final HKEY HKEY_CLASSES_ROOT = new HKEY(0x80000000);
|
||||
public static final HKEY HKEY_CURRENT_USER = new HKEY(0x80000001);
|
||||
public static final HKEY HKEY_LOCAL_MACHINE = new HKEY(0x80000002);
|
||||
public static final HKEY HKEY_USERS = new HKEY(0x80000003);
|
||||
public static final HKEY HKEY_PERFORMANCE_DATA= new HKEY(0x80000004);
|
||||
public static final HKEY HKEY_PERFORMANCE_TEXT= new HKEY(0x80000050);
|
||||
public static final HKEY HKEY_PERFORMANCE_NLSTEXT = new HKEY(0x80000060);
|
||||
public static final HKEY HKEY_CURRENT_CONFIG = new HKEY(0x80000005);
|
||||
public static final HKEY HKEY_DYN_DATA = new HKEY(0x80000006);
|
||||
}
|
||||
Alguns arquivos não foram exibidos porque demasiados arquivos foram alterados neste diff Mostrar Mais
Referência em uma Nova Issue
Bloquear um usuário