Permalink
Browse files

address issue #84

  • Loading branch information...
1 parent b83e977 commit a947dfdac53e91e78ff72fcc28f3995efe292ce1 @twall twall committed Aug 11, 2012
Showing with 2,711 additions and 2,021 deletions.
  1. +179 −195 contrib/ntservice/src/jnacontrib/jna/Advapi32.java
  2. +8 −4 contrib/platform/src/com/sun/jna/platform/mac/Carbon.java
  3. +146 −50 contrib/platform/src/com/sun/jna/platform/unix/X11.java
  4. +15 −23 contrib/platform/src/com/sun/jna/platform/win32/DsGetDC.java
  5. +7 −0 contrib/platform/src/com/sun/jna/platform/win32/Guid.java
  6. +46 −1 contrib/platform/src/com/sun/jna/platform/win32/LMAccess.java
  7. +32 −2 contrib/platform/src/com/sun/jna/platform/win32/NTSecApi.java
  8. +0 −1 contrib/platform/src/com/sun/jna/platform/win32/Netapi32.java
  9. +11 −0 contrib/platform/src/com/sun/jna/platform/win32/SetupApi.java
  10. +7 −0 contrib/platform/src/com/sun/jna/platform/win32/ShellAPI.java
  11. +34 −23 contrib/platform/src/com/sun/jna/platform/win32/Sspi.java
  12. +7 −0 contrib/platform/src/com/sun/jna/platform/win32/Tlhelp32.java
  13. +7 −0 contrib/platform/src/com/sun/jna/platform/win32/VerRsrc.java
  14. +7 −0 contrib/platform/src/com/sun/jna/platform/win32/Wdm.java
  15. +39 −1 contrib/platform/src/com/sun/jna/platform/win32/WinBase.java
  16. +10 −0 contrib/platform/src/com/sun/jna/platform/win32/WinCrypt.java
  17. +6 −0 contrib/platform/src/com/sun/jna/platform/win32/WinDef.java
  18. +21 −0 contrib/platform/src/com/sun/jna/platform/win32/WinGDI.java
  19. +1,558 −1,459 contrib/platform/src/com/sun/jna/platform/win32/WinNT.java
  20. +47 −1 contrib/platform/src/com/sun/jna/platform/win32/WinUser.java
  21. +7 −0 contrib/platform/src/com/sun/jna/platform/win32/Winioctl.java
  22. +11 −2 contrib/platform/src/com/sun/jna/platform/win32/Winspool.java
  23. +11 −0 contrib/platform/src/com/sun/jna/platform/win32/Winsvc.java
  24. +5 −7 contrib/platform/test/com/sun/jna/platform/win32/Netapi32Test.java
  25. +8 −5 src/com/sun/jna/CallbackReference.java
  26. +104 −109 src/com/sun/jna/Structure.java
  27. +2 −6 src/com/sun/jna/Union.java
  28. +27 −13 test/com/sun/jna/ArgumentsMarshalTest.java
  29. +11 −1 test/com/sun/jna/CallbacksTest.java
  30. +9 −0 test/com/sun/jna/IntegerTypeTest.java
  31. +11 −1 test/com/sun/jna/NativeTest.java
  32. +15 −4 test/com/sun/jna/ReturnTypesTest.java
  33. +3 −6 test/com/sun/jna/StructureBufferFieldTest.java
  34. +21 −5 test/com/sun/jna/StructureByValueTest.java
  35. +236 −100 test/com/sun/jna/StructureTest.java
  36. +6 −0 test/com/sun/jna/TypeMapperTest.java
  37. +12 −1 test/com/sun/jna/UnionTest.java
  38. +8 −1 test/com/sun/jna/VarArgsTest.java
  39. +9 −0 test/com/sun/jna/win32/W32APIMapperTest.java
  40. +8 −0 test/com/sun/jna/win32/W32StdCallTest.java
@@ -9,204 +9,188 @@
package jnacontrib.jna;
-import com.sun.jna.*;
-import com.sun.jna.ptr.*;
-import com.sun.jna.win32.*;
+import java.util.Arrays;
+import java.util.List;
+
+import com.sun.jna.Native;
+import com.sun.jna.Pointer;
+import com.sun.jna.Structure;
+import com.sun.jna.WString;
+import com.sun.jna.ptr.IntByReference;
+import com.sun.jna.win32.StdCallLibrary;
+import com.sun.jna.win32.W32APIOptions;
/**
- *
+ *
* @author TB
*/
-public interface Advapi32 extends StdCallLibrary {
- Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32", Advapi32.class,
- W32APIOptions.UNICODE_OPTIONS);
-
-/*
-SC_HANDLE WINAPI OpenSCManager(
- LPCTSTR lpMachineName,
- LPCTSTR lpDatabaseName,
- DWORD dwDesiredAccess
-);*/
- public Pointer OpenSCManager(String lpMachineName, WString lpDatabaseName, int dwDesiredAccess);
-
-/*
-BOOL WINAPI CloseServiceHandle(
- SC_HANDLE hSCObject
-);*/
- public boolean CloseServiceHandle(Pointer hSCObject);
-
-/*
-SC_HANDLE WINAPI OpenService(
- SC_HANDLE hSCManager,
- LPCTSTR lpServiceName,
- DWORD dwDesiredAccess
-);*/
- public Pointer OpenService(Pointer hSCManager, String lpServiceName, int dwDesiredAccess);
-
-/*
-BOOL WINAPI StartService(
- SC_HANDLE hService,
- DWORD dwNumServiceArgs,
- LPCTSTR* lpServiceArgVectors
-);*/
- public boolean StartService(Pointer hService, int dwNumServiceArgs, char[] lpServiceArgVectors);
-
-/*
-BOOL WINAPI ControlService(
- SC_HANDLE hService,
- DWORD dwControl,
- LPSERVICE_STATUS lpServiceStatus
-);*/
- public boolean ControlService(Pointer hService, int dwControl, SERVICE_STATUS lpServiceStatus);
-
-/*
-BOOL WINAPI StartServiceCtrlDispatcher(
- const SERVICE_TABLE_ENTRY* lpServiceTable
-);*/
- public boolean StartServiceCtrlDispatcher(Structure[] lpServiceTable);
-
-/*
-SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandler(
- LPCTSTR lpServiceName,
- LPHANDLER_FUNCTION lpHandlerProc
-);*/
- public Pointer RegisterServiceCtrlHandler(String lpServiceName, Handler lpHandlerProc);
-
-/*
-SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerEx(
- LPCTSTR lpServiceName,
- LPHANDLER_FUNCTION_EX lpHandlerProc,
- LPVOID lpContext
-);*/
- public Pointer RegisterServiceCtrlHandlerEx(String lpServiceName, HandlerEx lpHandlerProc, Pointer lpContext);
-
-/*
-BOOL WINAPI SetServiceStatus(
- SERVICE_STATUS_HANDLE hServiceStatus,
- LPSERVICE_STATUS lpServiceStatus
-);*/
- public boolean SetServiceStatus(Pointer hServiceStatus, SERVICE_STATUS lpServiceStatus);
-
-/*
-SC_HANDLE WINAPI CreateService(
- SC_HANDLE hSCManager,
- LPCTSTR lpServiceName,
- LPCTSTR lpDisplayName,
- DWORD dwDesiredAccess,
- DWORD dwServiceType,
- DWORD dwStartType,
- DWORD dwErrorControl,
- LPCTSTR lpBinaryPathName,
- LPCTSTR lpLoadOrderGroup,
- LPDWORD lpdwTagId,
- LPCTSTR lpDependencies,
- LPCTSTR lpServiceStartName,
- LPCTSTR lpPassword
-);*/
- public Pointer CreateService(Pointer hSCManager, String lpServiceName, String lpDisplayName,
- int dwDesiredAccess, int dwServiceType, int dwStartType, int dwErrorControl,
- String lpBinaryPathName, String lpLoadOrderGroup, IntByReference lpdwTagId,
- String lpDependencies, String lpServiceStartName, String lpPassword);
-
-/*
-BOOL WINAPI DeleteService(
- SC_HANDLE hService
-);*/
- public boolean DeleteService(Pointer hService);
-
-/*
-BOOL WINAPI ChangeServiceConfig2(
- SC_HANDLE hService,
- DWORD dwInfoLevel,
- LPVOID lpInfo
-);*/
- public boolean ChangeServiceConfig2(Pointer hService, int dwInfoLevel, ChangeServiceConfig2Info lpInfo);
-
-/*
-LONG WINAPI RegEnumValue(
- HKEY hKey,
- DWORD dwIndex,
- LPTSTR lpValueName,
- LPDWORD lpcchValueName,
- LPDWORD lpReserved,
- LPDWORD lpType,
- LPBYTE lpData,
- LPDWORD lpcbData
-);*/
- public int RegEnumValue(int hKey, int dwIndex, char[] lpValueName, IntByReference lpcchValueName, IntByReference reserved,
- IntByReference lpType, byte[] lpData, IntByReference lpcbData);
-
- interface SERVICE_MAIN_FUNCTION extends StdCallCallback {
- /*
- VOID WINAPI ServiceMain(
- DWORD dwArgc,
- LPTSTR* lpszArgv
- );*/
- public void callback(int dwArgc, Pointer lpszArgv);
- }
-
- interface Handler extends StdCallCallback {
- /*
- VOID WINAPI Handler(
- DWORD fdwControl
- );*/
- public void callback(int fdwControl);
- }
-
- interface HandlerEx extends StdCallCallback {
- /*
- DWORD WINAPI HandlerEx(
- DWORD dwControl,
- DWORD dwEventType,
- LPVOID lpEventData,
- LPVOID lpContext
- );*/
- public int callback(int dwControl, int dwEventType, Pointer lpEventData, Pointer lpContext);
- }
-
-/*
-typedef struct _SERVICE_STATUS {
- DWORD dwServiceType;
- DWORD dwCurrentState;
- DWORD dwControlsAccepted;
- DWORD dwWin32ExitCode;
- DWORD dwServiceSpecificExitCode;
- DWORD dwCheckPoint;
- DWORD dwWaitHint;
-} SERVICE_STATUS,
- *LPSERVICE_STATUS;*/
- public static class SERVICE_STATUS extends Structure {
- public int dwServiceType;
- public int dwCurrentState;
- public int dwControlsAccepted;
- public int dwWin32ExitCode;
- public int dwServiceSpecificExitCode;
- public int dwCheckPoint;
- public int dwWaitHint;
- }
-
-/*
-typedef struct _SERVICE_TABLE_ENTRY {
- LPTSTR lpServiceName;
- LPSERVICE_MAIN_FUNCTION lpServiceProc;
-} SERVICE_TABLE_ENTRY,
- *LPSERVICE_TABLE_ENTRY;*/
- public static class SERVICE_TABLE_ENTRY extends Structure {
- public String lpServiceName;
- public SERVICE_MAIN_FUNCTION lpServiceProc;
- }
-
- public static class ChangeServiceConfig2Info extends Structure {
- }
-
-/*
- typedef struct _SERVICE_DESCRIPTION {
- LPTSTR lpDescription;
-} SERVICE_DESCRIPTION,
- *LPSERVICE_DESCRIPTION;*/
- public static class SERVICE_DESCRIPTION extends ChangeServiceConfig2Info {
- public String lpDescription;
- }
-}
+public interface Advapi32 extends StdCallLibrary {
+ Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32",
+ Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
+
+ /*
+ * SC_HANDLE WINAPI OpenSCManager( LPCTSTR lpMachineName, LPCTSTR
+ * lpDatabaseName, DWORD dwDesiredAccess );
+ */
+ public Pointer OpenSCManager(String lpMachineName, WString lpDatabaseName,
+ int dwDesiredAccess);
+
+ /*
+ * BOOL WINAPI CloseServiceHandle( SC_HANDLE hSCObject );
+ */
+ public boolean CloseServiceHandle(Pointer hSCObject);
+
+ /*
+ * SC_HANDLE WINAPI OpenService( SC_HANDLE hSCManager, LPCTSTR
+ * lpServiceName, DWORD dwDesiredAccess );
+ */
+ public Pointer OpenService(Pointer hSCManager, String lpServiceName,
+ int dwDesiredAccess);
+
+ /*
+ * BOOL WINAPI StartService( SC_HANDLE hService, DWORD dwNumServiceArgs,
+ * LPCTSTR* lpServiceArgVectors );
+ */
+ public boolean StartService(Pointer hService, int dwNumServiceArgs,
+ char[] lpServiceArgVectors);
+
+ /*
+ * BOOL WINAPI ControlService( SC_HANDLE hService, DWORD dwControl,
+ * LPSERVICE_STATUS lpServiceStatus );
+ */
+ public boolean ControlService(Pointer hService, int dwControl,
+ SERVICE_STATUS lpServiceStatus);
+
+ /*
+ * BOOL WINAPI StartServiceCtrlDispatcher( const SERVICE_TABLE_ENTRY*
+ * lpServiceTable );
+ */
+ public boolean StartServiceCtrlDispatcher(Structure[] lpServiceTable);
+
+ /*
+ * SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandler( LPCTSTR
+ * lpServiceName, LPHANDLER_FUNCTION lpHandlerProc );
+ */
+ public Pointer RegisterServiceCtrlHandler(String lpServiceName,
+ Handler lpHandlerProc);
+
+ /*
+ * SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerEx( LPCTSTR
+ * lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext );
+ */
+ public Pointer RegisterServiceCtrlHandlerEx(String lpServiceName,
+ HandlerEx lpHandlerProc, Pointer lpContext);
+
+ /*
+ * BOOL WINAPI SetServiceStatus( SERVICE_STATUS_HANDLE hServiceStatus,
+ * LPSERVICE_STATUS lpServiceStatus );
+ */
+ public boolean SetServiceStatus(Pointer hServiceStatus,
+ SERVICE_STATUS lpServiceStatus);
+
+ /*
+ * SC_HANDLE WINAPI CreateService( SC_HANDLE hSCManager, LPCTSTR
+ * lpServiceName, LPCTSTR lpDisplayName, DWORD dwDesiredAccess, DWORD
+ * dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCTSTR
+ * lpBinaryPathName, LPCTSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCTSTR
+ * lpDependencies, LPCTSTR lpServiceStartName, LPCTSTR lpPassword );
+ */
+ public Pointer CreateService(Pointer hSCManager, String lpServiceName,
+ String lpDisplayName, int dwDesiredAccess, int dwServiceType,
+ int dwStartType, int dwErrorControl, String lpBinaryPathName,
+ String lpLoadOrderGroup, IntByReference lpdwTagId,
+ String lpDependencies, String lpServiceStartName, String lpPassword);
+
+ /*
+ * BOOL WINAPI DeleteService( SC_HANDLE hService );
+ */
+ public boolean DeleteService(Pointer hService);
+ /*
+ * BOOL WINAPI ChangeServiceConfig2( SC_HANDLE hService, DWORD dwInfoLevel,
+ * LPVOID lpInfo );
+ */
+ public boolean ChangeServiceConfig2(Pointer hService, int dwInfoLevel,
+ ChangeServiceConfig2Info lpInfo);
+
+ /*
+ * LONG WINAPI RegEnumValue( HKEY hKey, DWORD dwIndex, LPTSTR lpValueName,
+ * LPDWORD lpcchValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE
+ * lpData, LPDWORD lpcbData );
+ */
+ public int RegEnumValue(int hKey, int dwIndex, char[] lpValueName,
+ IntByReference lpcchValueName, IntByReference reserved,
+ IntByReference lpType, byte[] lpData, IntByReference lpcbData);
+
+ interface SERVICE_MAIN_FUNCTION extends StdCallCallback {
+ /*
+ * VOID WINAPI ServiceMain( DWORD dwArgc, LPTSTR* lpszArgv );
+ */
+ public void callback(int dwArgc, Pointer lpszArgv);
+ }
+ interface Handler extends StdCallCallback {
+ /*
+ * VOID WINAPI Handler( DWORD fdwControl );
+ */
+ public void callback(int fdwControl);
+ }
+
+ interface HandlerEx extends StdCallCallback {
+ /*
+ * DWORD WINAPI HandlerEx( DWORD dwControl, DWORD dwEventType, LPVOID
+ * lpEventData, LPVOID lpContext );
+ */
+ public int callback(int dwControl, int dwEventType,
+ Pointer lpEventData, Pointer lpContext);
+ }
+
+ /*
+ * typedef struct _SERVICE_STATUS { DWORD dwServiceType; DWORD
+ * dwCurrentState; DWORD dwControlsAccepted; DWORD dwWin32ExitCode; DWORD
+ * dwServiceSpecificExitCode; DWORD dwCheckPoint; DWORD dwWaitHint; }
+ * SERVICE_STATUS,LPSERVICE_STATUS;
+ */
+ public static class SERVICE_STATUS extends Structure {
+ public int dwServiceType;
+ public int dwCurrentState;
+ public int dwControlsAccepted;
+ public int dwWin32ExitCode;
+ public int dwServiceSpecificExitCode;
+ public int dwCheckPoint;
+ public int dwWaitHint;
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "dwServiceType", "dwCurrentState", "dwControlsAccepted", "dwWin32ExitCode", "dwServiceSpecificExitCode", "dwCheckPoint", "dwWaitHint" });
+ }
+ }
+
+ /*
+ * typedef struct _SERVICE_TABLE_ENTRY { LPTSTR lpServiceName;
+ * LPSERVICE_MAIN_FUNCTION lpServiceProc; } SERVICE_TABLE_ENTRY,
+ * LPSERVICE_TABLE_ENTRY;
+ */
+ public static class SERVICE_TABLE_ENTRY extends Structure {
+ public String lpServiceName;
+ public SERVICE_MAIN_FUNCTION lpServiceProc;
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "lpServiceName", "lpServiceProc" });
+ }
+ }
+
+ public static abstract class ChangeServiceConfig2Info extends Structure {
+ }
+
+ /*
+ * typedef struct _SERVICE_DESCRIPTION { LPTSTR lpDescription; }
+ * SERVICE_DESCRIPTION,LPSERVICE_DESCRIPTION;
+ */
+ public static class SERVICE_DESCRIPTION extends ChangeServiceConfig2Info {
+ public String lpDescription;
+
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "lpDescription" });
+ }
+ }
+}
Oops, something went wrong.

3 comments on commit a947dfd

This looks good, but where are you preventing users from overriding setFieldOrder() in subclasses?

As a side-note, under Java6 you could replace Arrays.asList(new String[] { ... }) with Arrays.asList(...). The array creation is implicit.

Contributor

twall replied Aug 28, 2012

Please sign in to comment.