diff --git a/.classpath b/.classpath deleted file mode 100644 index 7518ee3..0000000 --- a/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/.gitignore b/.gitignore index d271ce5..878b094 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ /target/ /classes/ +/.classpath +/.project +/.settings/ +/build/ diff --git a/.project b/.project deleted file mode 100644 index 67f7d5c..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - PureJavaHidApi - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/bin/purejavahidapi-src.jar b/bin/purejavahidapi-src.jar index e28c52e..ed5f7ee 100644 Binary files a/bin/purejavahidapi-src.jar and b/bin/purejavahidapi-src.jar differ diff --git a/bin/purejavahidapi.jar b/bin/purejavahidapi.jar index f91bb0a..ee14f2b 100644 Binary files a/bin/purejavahidapi.jar and b/bin/purejavahidapi.jar differ diff --git a/pom.xml b/pom.xml index cd7c2c5..9e46eca 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ purejavahidapi purejavahidapi - 0.0.2 + 0.0.3-SNAPSHOT jar Pure Java HID-API diff --git a/src/purejavahidapi/windows/HidDevice.java b/src/purejavahidapi/windows/HidDevice.java index fde2a39..f25df94 100644 --- a/src/purejavahidapi/windows/HidDevice.java +++ b/src/purejavahidapi/windows/HidDevice.java @@ -2,36 +2,41 @@ * Copyright (c) 2014, Kustaa Nyholm / SpareTimeLabs * All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - * Redistributions of source code must retain the above copyright notice, this list + * Redistributions of source code must retain the above copyright notice, this list * of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, this + * + * Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or other * materials provided with the distribution. - * - * Neither the name of the Kustaa Nyholm or SpareTimeLabs nor the names of its - * contributors may be used to endorse or promote products derived from this software + * + * Neither the name of the Kustaa Nyholm or SpareTimeLabs nor the names of its + * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ package purejavahidapi.windows; -import static purejavahidapi.windows.HidLibrary.*; +import static purejavahidapi.windows.HidLibrary.HidD_FreePreparsedData; +import static purejavahidapi.windows.HidLibrary.HidD_GetAttributes; +import static purejavahidapi.windows.HidLibrary.HidD_GetPreparsedData; +import static purejavahidapi.windows.HidLibrary.HidD_SetFeature; +import static purejavahidapi.windows.HidLibrary.HidD_SetOutputReport; +import static purejavahidapi.windows.HidLibrary.HidP_GetCaps; import static purejavahidapi.windows.Kernel32Library.*; -import static purejavahidapi.windows.SetupApiLibrary.*; +import static purejavahidapi.windows.SetupApiLibrary.HIDP_STATUS_SUCCESS; import static purejavahidapi.windows.WinDef.INVALID_HANDLE_VALUE; import com.sun.jna.Memory; @@ -41,9 +46,13 @@ import purejavahidapi.shared.SyncPoint; import purejavahidapi.windows.HidLibrary.HIDD_ATTRIBUTES; import purejavahidapi.windows.HidLibrary.HIDP_CAPS; +import purejavahidapi.windows.HidLibrary.HIDP_PREPARSED_DATA; import purejavahidapi.windows.WinDef.HANDLE; import purejavahidapi.windows.WinDef.OVERLAPPED; +import java.io.BufferedWriter; +import java.io.FileWriter; + public class HidDevice extends purejavahidapi.HidDevice { private WindowsBackend m_Backend; private HANDLE m_Handle; @@ -52,18 +61,14 @@ public class HidDevice extends purejavahidapi.HidDevice { private OVERLAPPED m_OutputReportOverlapped; private int[] m_OutputReportBytesWritten; private int m_InputReportLength; - private OVERLAPPED m_InputReportOverlapped = new OVERLAPPED(); - private Memory m_InputReportMemory; - private byte[] m_InputReportBytes; - private int[] m_InputReportBytesRead = { 0 }; private Thread m_Thread; private SyncPoint m_SyncStart; private SyncPoint m_SyncShutdown; private boolean m_StopThread; private boolean m_ForceControlOutput; - /* package */HidDevice(purejavahidapi.HidDeviceInfo deviceInfo, WindowsBackend backend) { - HANDLE handle = backend.openDeviceHandle(deviceInfo.getPath(), false); + /* package */ HidDevice(purejavahidapi.HidDeviceInfo deviceInfo, WindowsBackend backend) { + HANDLE handle = WindowsBackend.openDeviceHandle(deviceInfo.getPath(), false); if (handle == INVALID_HANDLE_VALUE) return; @@ -91,16 +96,11 @@ public class HidDevice extends purejavahidapi.HidDevice { if (m_OutputReportLength > 0) m_OutputReportMemory = new Memory(m_OutputReportLength); m_OutputReportOverlapped = new OVERLAPPED(); - m_OutputReportBytesWritten = new int[] { 0 }; + m_OutputReportBytesWritten = new int[] { + 0 + }; m_InputReportLength = caps.InputReportByteLength; - m_InputReportOverlapped = new OVERLAPPED(); - if (m_InputReportLength > 0) { - m_InputReportMemory = new Memory(m_InputReportLength); - m_InputReportBytes = new byte[m_InputReportLength]; - } - m_InputReportBytesRead = new int[] { 0 }; - HidD_FreePreparsedData(ppd[0]); m_SyncStart = new SyncPoint(2); @@ -124,6 +124,9 @@ public void run() { } m_ForceControlOutput = System.getProperty("purejavahidapi.forceControlOutput") != null; + + // bManualReset parameter has to be set to true to work with WaitForSingleObject + m_OutputReportOverlapped.hEvent = CreateEvent(null, true, false, null); } @Override @@ -137,6 +140,7 @@ synchronized public void close() { m_Thread.interrupt(); m_SyncShutdown.waitAndSync(); } + CloseHandle(m_OutputReportOverlapped.hEvent); CloseHandle(m_Handle); m_Backend.removeDevice(m_HidDeviceInfo.getDeviceId()); m_Open = false; @@ -147,32 +151,49 @@ synchronized public int setOutputReport(byte reportID, byte[] data, int length) if (!m_Open) throw new IllegalStateException("device not open"); if (m_OutputReportLength == 0) - throw new IllegalArgumentException("this device supportst no output reports"); - // In Windows writeFile() to HID device data has to be preceded with the report number, regardless - m_OutputReportMemory.write(0, new byte[] { reportID }, 0, 1); + throw new IllegalArgumentException("this device supports no output reports"); + // In Windows writeFile() to HID device data has to be preceded with the report + // number, regardless + m_OutputReportMemory.write(0, new byte[] { + reportID + }, 0, 1); m_OutputReportMemory.write(1, data, 0, length); if (!m_ForceControlOutput) { - // In windows always attempt to write as many bytes as there are in the longest report plus one for the report number (even if zero ie not used) + ResetEvent(m_OutputReportOverlapped.hEvent); + m_OutputReportOverlapped.Internal = null; + m_OutputReportOverlapped.InternalHigh = null; + m_OutputReportOverlapped.Offset = 0; + m_OutputReportOverlapped.OffsetHigh = 0; + + // In windows always attempt to write as many bytes as there are in the longest + // report plus one for the report number (even if zero ie not used) if (!WriteFile(m_Handle, m_OutputReportMemory, m_OutputReportLength, null, m_OutputReportOverlapped)) { if (GetLastError() != ERROR_IO_PENDING) { // WriteFile() failed. Return error. - //register_error(dev, "WriteFile"); + // register_error(dev, "WriteFile"); return -1; } } - if (!GetOverlappedResult(m_Handle, m_OutputReportOverlapped, m_OutputReportBytesWritten, true/* wait */)) { + if (WAIT_OBJECT_0 != WaitForSingleObject(m_OutputReportOverlapped.hEvent, 1000)) { + return -1; + } + + // Update structure from native code + m_OutputReportOverlapped.read(); + + if (!GetOverlappedResult(m_Handle, m_OutputReportOverlapped, m_OutputReportBytesWritten, false/* don't need to wait */)) { // The Write operation failed. - //register_error(dev, "WriteFile"); - return 0; + // register_error(dev, "WriteFile"); + return -1; } return m_OutputReportBytesWritten[0] - 1; } else { if (!HidD_SetOutputReport(m_Handle, m_OutputReportMemory.getByteArray(0, length + 1), length + 1)) { // HidD_SetOutputReport() failed. Return error. - //register_error(dev, "HidD_SetOutputReport"); + // register_error(dev, "HidD_SetOutputReport"); return -1; } @@ -180,6 +201,7 @@ synchronized public int setOutputReport(byte reportID, byte[] data, int length) } } + @Override synchronized public int setFeatureReport(byte reportId, byte[] data, int length) { if (!m_Open) @@ -188,7 +210,7 @@ synchronized public int setFeatureReport(byte reportId, byte[] data, int length) buffer[0] = reportId; System.arraycopy(data, 0, buffer, 1, length); if (!HidD_SetFeature(m_Handle, buffer, length + 1)) { - //register_error(dev, "HidD_SetFeature"); + // register_error(dev, "HidD_SetFeature"); return -1; } @@ -200,7 +222,7 @@ synchronized public int setFeatureReport(byte[] data, int length) { if (!m_Open) throw new IllegalStateException("device not open"); if (!HidD_SetFeature(m_Handle, data, length)) { - //register_error(dev, "HidD_SetFeature"); + // register_error(dev, "HidD_SetFeature"); return -1; } @@ -211,71 +233,99 @@ synchronized public int setFeatureReport(byte[] data, int length) { synchronized public int getFeatureReport(byte[] data, int length) { if (!m_Open) throw new IllegalStateException("device not open"); - if (false) { // can't use this as it will not return the size of the report - if (!HidD_GetFeature(m_Handle, data, length)) { - //register_error(dev, "HidD_SetFeature"); - System.out.println(GetLastError()); + int[] bytes = { + 0 + }; + + OVERLAPPED ol = new OVERLAPPED(); + Pointer buffer = new Memory(data.length); + if (!DeviceIoControl(m_Handle, IOCTL_HID_GET_FEATURE, buffer, length, buffer, length, bytes, ol)) { + // System.out.println(GetLastError()); + if (GetLastError() != ERROR_IO_PENDING) return -1; - } - } else { - int[] bytes = { 0 }; - - OVERLAPPED ol = new OVERLAPPED(); - Pointer buffer = new Memory(data.length); - if (!DeviceIoControl(m_Handle, IOCTL_HID_GET_FEATURE, buffer, length, buffer, length, bytes, ol)) { - //System.out.println(GetLastError()); - if (GetLastError() != ERROR_IO_PENDING) - return -1; - } - - if (!GetOverlappedResult(m_Handle, ol, bytes, true/* wait */)) - return -1; - int n = bytes[0] + 1; - byte[] t = buffer.getByteArray(0, n); - System.arraycopy(t, 0, data, 0, n); - return n; } - return -1; // Eclipse says this is unreachable (it is), but won't compile without it ... go figure + if (!GetOverlappedResult(m_Handle, ol, bytes, true/* wait */)) + return -1; + int n = bytes[0] + 1; + byte[] t = buffer.getByteArray(0, n); + System.arraycopy(t, 0, data, 0, n); + return n; } private void runReadOnBackground() { m_SyncStart.waitAndSync(); - while (!m_StopThread) { - m_InputReportBytesRead[0] = 0; - ResetEvent(m_InputReportOverlapped.hEvent); - // In Windos ReadFile() from a HID device Windows expects us to attempt to read as much bytes as there are - // in the longest report plus one for the report number (even if not used) and the data is always - // preceded with the report number (even if not used in case of which it is zero) - if (!ReadFile(m_Handle, m_InputReportMemory, m_InputReportLength, null, m_InputReportOverlapped)) { + int[] numBytesRead = { 0 }; + OVERLAPPED overlapped = new OVERLAPPED(); + overlapped.hEvent = CreateEvent(null, true, true, null); + Memory readBuffer = new Memory(m_InputReportLength); + + while (!m_StopThread) { + ResetEvent(overlapped.hEvent); + numBytesRead[0] = 0; + overlapped.Internal = null; + overlapped.InternalHigh = null; + overlapped.Offset = 0; + overlapped.OffsetHigh = 0; + + // In Windows ReadFile() from a HID device Windows expects us to + // attempt to read as much many as there are in the longest report + // plus one for the report number (even if not used) and the data + // is always preceded with the report number (even if not used in + // case of which it is zero) + if (!ReadFile(m_Handle, readBuffer, m_InputReportLength, numBytesRead, overlapped)) { if (GetLastError() == ERROR_DEVICE_NOT_CONNECTED) break; // early exit if the device disappears if (GetLastError() != ERROR_IO_PENDING) { CancelIo(m_Handle); - System.out.println("ReadFile failed with GetLastError()==" + GetLastError()); + System.err.println("ReadFile failed with GetLastError()==" + GetLastError()); } - } - if (!GetOverlappedResult(m_Handle, m_InputReportOverlapped, m_InputReportBytesRead, true/* wait */)) { - if (GetLastError() == ERROR_DEVICE_NOT_CONNECTED) - break; // early exit if the device disappears - System.out.println("GetOverlappedResult failed with GetLastError()==" + GetLastError()); - } - // Avoid duplicate packet - if (m_InputReportOverlapped.Internal != null) { - continue; - } - if (m_InputReportBytesRead[0] > 0) { - byte reportID = m_InputReportMemory.getByte(0); - m_InputReportBytesRead[0]--; - m_InputReportMemory.read(1, m_InputReportBytes, 0, m_InputReportBytesRead[0]); - - if (m_InputReportListener != null) - m_InputReportListener.onInputReport(this, reportID, m_InputReportBytes, m_InputReportBytesRead[0]); + if (WAIT_OBJECT_0 != WaitForSingleObject(overlapped.hEvent, INFINITE)) { + System.err.println("WaitForSingleObject failed with GetLastError()==" + GetLastError()); + } + + // Update structure from native code + overlapped.read(); + + if (!GetOverlappedResult(m_Handle, overlapped, numBytesRead, false/* don't need to wait */)) { + if (GetLastError() == ERROR_DEVICE_NOT_CONNECTED) + break; // early exit if the device disappears + if (m_StopThread && GetLastError() == ERROR_OPERATION_ABORTED) + break; // on close + System.err.println("GetOverlappedResult failed with GetLastError()==" + GetLastError()); + } } + processInputReport(readBuffer, numBytesRead[0]); } + + CloseHandle(overlapped.hEvent); m_SyncShutdown.waitAndSync(); } + + private void processInputReport(Memory readBuffer, int numBytesRead) { + if (numBytesRead > 0) { + byte reportID = readBuffer.getByte(0); + int len = numBytesRead - 1; + byte[] inputReport = new byte[len]; + readBuffer.read(1, inputReport, 0, len); + if (m_InputReportListener != null) { + m_InputReportListener.onInputReport(this, reportID, inputReport, len); + } + } + } + + private void Log(String sMessage) { + try { + String fileName = "C:\\Temp\\bmx.txt"; + BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true)); + writer.write(sMessage + "\n"); + writer.close(); + } catch (Exception e) { + + } + } + } diff --git a/src/purejavahidapi/windows/HidDeviceInfo.java b/src/purejavahidapi/windows/HidDeviceInfo.java index 5d67944..5d787fd 100644 --- a/src/purejavahidapi/windows/HidDeviceInfo.java +++ b/src/purejavahidapi/windows/HidDeviceInfo.java @@ -29,20 +29,21 @@ */ package purejavahidapi.windows; -import static purejavahidapi.windows.HidLibrary.*; +import static purejavahidapi.windows.HidLibrary.HidD_FreePreparsedData; +import static purejavahidapi.windows.HidLibrary.HidD_GetManufacturerString; +import static purejavahidapi.windows.HidLibrary.HidD_GetPreparsedData; +import static purejavahidapi.windows.HidLibrary.HidD_GetProductString; +import static purejavahidapi.windows.HidLibrary.HidD_GetSerialNumberString; +import static purejavahidapi.windows.HidLibrary.HidP_GetCaps; import static purejavahidapi.windows.SetupApiLibrary.HIDP_STATUS_SUCCESS; -import java.nio.ByteBuffer; - import com.sun.jna.Memory; + import purejavahidapi.windows.HidLibrary.HIDD_ATTRIBUTES; import purejavahidapi.windows.HidLibrary.HIDP_CAPS; +import purejavahidapi.windows.HidLibrary.HIDP_PREPARSED_DATA; import purejavahidapi.windows.WinDef.HANDLE; -import com.sun.jna.Native; -import com.sun.jna.NativeLong; -import com.sun.jna.Pointer; - /* package*/class HidDeviceInfo extends purejavahidapi.HidDeviceInfo { public HidDeviceInfo(String path, String deviceId, HANDLE handle, HIDD_ATTRIBUTES attrib) { diff --git a/src/purejavahidapi/windows/HidLibrary.java b/src/purejavahidapi/windows/HidLibrary.java index 7303fe6..3e00d4e 100644 --- a/src/purejavahidapi/windows/HidLibrary.java +++ b/src/purejavahidapi/windows/HidLibrary.java @@ -38,10 +38,9 @@ import com.sun.jna.PointerType; import com.sun.jna.Structure; import com.sun.jna.Union; -import com.sun.jna.Memory; import com.sun.jna.win32.StdCallLibrary; -import static purejavahidapi.windows.WinDef.HANDLE; +import purejavahidapi.windows.WinDef.HANDLE; public class HidLibrary { static HidLibraryInterface INSTANCE = (HidLibraryInterface) Native.loadLibrary("hid", HidLibraryInterface.class); diff --git a/src/purejavahidapi/windows/Kernel32Library.java b/src/purejavahidapi/windows/Kernel32Library.java index 9b027fc..82ac4f6 100644 --- a/src/purejavahidapi/windows/Kernel32Library.java +++ b/src/purejavahidapi/windows/Kernel32Library.java @@ -29,16 +29,16 @@ */ package purejavahidapi.windows; -import purejavahidapi.windows.WinDef.HANDLE; -import purejavahidapi.windows.WinDef.HMODULE; -import purejavahidapi.windows.WinDef.OVERLAPPED; -import purejavahidapi.windows.WinDef.SECURITY_ATTRIBUTES; - import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.win32.StdCallLibrary; import com.sun.jna.win32.W32APIOptions; +import purejavahidapi.windows.WinDef.HANDLE; +import purejavahidapi.windows.WinDef.HMODULE; +import purejavahidapi.windows.WinDef.OVERLAPPED; +import purejavahidapi.windows.WinDef.SECURITY_ATTRIBUTES; + public class Kernel32Library { static Kernel32Interface INSTANCE = (Kernel32Interface) Native.loadLibrary("kernel32", Kernel32Interface.class, W32APIOptions.UNICODE_OPTIONS); @@ -110,6 +110,8 @@ public interface Kernel32Interface extends StdCallLibrary { HMODULE GetModuleHandle(String name); boolean DeviceIoControl(HANDLE hDevice, int dwIoControlCode, Pointer lpInBuffer, int nInBufferSize, Pointer lpOutBuffer, int nOutBufferSize, int[] lpBytesReturned, OVERLAPPED lpOverlapped); + + HANDLE CreateEvent(SECURITY_ATTRIBUTES lpEventAttributes, boolean bManualReset, boolean bInitialState, String lpName); } public static HANDLE CreateFile(String name, int access, int sharing, SECURITY_ATTRIBUTES security, int create, int attribs, Pointer template) { @@ -162,4 +164,9 @@ public static HMODULE GetModuleHandle(String name) { public static boolean DeviceIoControl(HANDLE hDevice, int dwIoControlCode, Pointer lpInBuffer, int nInBufferSize, Pointer lpOutBuffer, int nOutBufferSize, int[] lpBytesReturned, OVERLAPPED lpOverlapped) { return INSTANCE.DeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped); } + + public static HANDLE CreateEvent(SECURITY_ATTRIBUTES lpEventAttributes, boolean bManualReset, boolean bInitialState, String lpName) { + HANDLE h = INSTANCE.CreateEvent(lpEventAttributes, bManualReset, bInitialState, lpName); + return h; + } } diff --git a/src/purejavahidapi/windows/SetupApiLibrary.java b/src/purejavahidapi/windows/SetupApiLibrary.java index 851ef85..40afd64 100644 --- a/src/purejavahidapi/windows/SetupApiLibrary.java +++ b/src/purejavahidapi/windows/SetupApiLibrary.java @@ -121,15 +121,18 @@ import java.util.Arrays; import java.util.List; -import purejavahidapi.windows.CfgmgrLibrary.CfgmgrInterface; +import com.sun.jna.Library; +import com.sun.jna.Native; +import com.sun.jna.Pointer; +import com.sun.jna.Structure; +import com.sun.jna.win32.W32APIOptions; + import purejavahidapi.windows.WinDef.HANDLE; import purejavahidapi.windows.WinDef.HWND; -import com.sun.jna.*; -import com.sun.jna.win32.W32APIOptions; - public class SetupApiLibrary { - static SetupApiInterface INSTANCE = (SetupApiInterface) Native.loadLibrary("setupapi", SetupApiInterface.class, W32APIOptions.UNICODE_OPTIONS); + static SetupApiInterface INSTANCE = (SetupApiInterface) Native.loadLibrary("setupapi", SetupApiInterface.class, + W32APIOptions.UNICODE_OPTIONS); public static final int DIGCF_PRESENT = 2; public static final int DIGCF_ALLCLASSES = 4; @@ -266,23 +269,30 @@ public interface SetupApiInterface extends Library { HDEVINFO SetupDiGetClassDevs(GUID ClassGuid, String Enumerator, HWND hwndParent, int Flags); - boolean SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, GUID InterfaceClassGuid, int MemberIndex, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData); + boolean SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, + GUID InterfaceClassGuid, int MemberIndex, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData); - boolean SetupDiGetDeviceInterfaceDetail(HDEVINFO DeviceInfoSet, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData, SP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData, int DeviceInterfaceDetailDataSize, int[] RequiredSize, SP_DEVINFO_DATA DeviceInfoData); + boolean SetupDiGetDeviceInterfaceDetail(HDEVINFO DeviceInfoSet, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData, + SP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData, int DeviceInterfaceDetailDataSize, + int[] RequiredSize, SP_DEVINFO_DATA DeviceInfoData); boolean SetupDiEnumDeviceInfo(HDEVINFO DeviceInfoSet, int MemberIndex, SP_DEVINFO_DATA DeviceInfoData); - boolean SetupDiGetDeviceRegistryProperty(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, int Property, int[] PropertyRegDataType, char[] PropertyBuffer, int PropertyBufferSize, int[] RequiredSize); + boolean SetupDiGetDeviceRegistryProperty(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, int Property, + int[] PropertyRegDataType, char[] PropertyBuffer, int PropertyBufferSize, int[] RequiredSize); boolean SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet); - boolean SetupDiGetDeviceInstanceId(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, char[] DeviceInstanceId, int DeviceInstanceIdSize, int[] RequiredSize); + boolean SetupDiGetDeviceInstanceId(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, + char[] DeviceInstanceId, int DeviceInstanceIdSize, int[] RequiredSize); - boolean SetupDiOpenDeviceInterface(HDEVINFO DeviceInfoSet, String DevicePath, int OpenFlags, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData); + boolean SetupDiOpenDeviceInterface(HDEVINFO DeviceInfoSet, String DevicePath, int OpenFlags, + SP_DEVICE_INTERFACE_DATA DeviceInterfaceData); boolean SetupDiDeleteDeviceInterfaceData(HDEVINFO DeviceInfoSet, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData); - boolean SetupDiOpenDeviceInfo(HDEVINFO DeviceInfoSet, String DeviceInstanceId, HWND hwndParent, int OpenFlags, SP_DEVINFO_DATA DeviceInfoData); + boolean SetupDiOpenDeviceInfo(HDEVINFO DeviceInfoSet, String DeviceInstanceId, HWND hwndParent, int OpenFlags, + SP_DEVINFO_DATA DeviceInfoData); } public static HDEVINFO SetupDiCreateDeviceInfoList(GUID ClassGuid, HWND hwndParent) { @@ -293,39 +303,53 @@ public static HDEVINFO SetupDiGetClassDevs(GUID ClassGuid, String Enumerator, HW return INSTANCE.SetupDiGetClassDevs(ClassGuid, Enumerator, hwndParent, Flags); } - public static boolean SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, GUID InterfaceClassGuid, int MemberIndex, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData) { - return INSTANCE.SetupDiEnumDeviceInterfaces(DeviceInfoSet, DeviceInfoData, InterfaceClassGuid, MemberIndex, DeviceInterfaceData); + public static boolean SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, + GUID InterfaceClassGuid, int MemberIndex, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData) { + return INSTANCE.SetupDiEnumDeviceInterfaces(DeviceInfoSet, DeviceInfoData, InterfaceClassGuid, MemberIndex, + DeviceInterfaceData); } - public static boolean SetupDiEnumDeviceInfo(HDEVINFO DeviceInfoSet, int MemberIndex, SP_DEVINFO_DATA DeviceInfoData) { + public static boolean SetupDiEnumDeviceInfo(HDEVINFO DeviceInfoSet, int MemberIndex, + SP_DEVINFO_DATA DeviceInfoData) { return INSTANCE.SetupDiEnumDeviceInfo(DeviceInfoSet, MemberIndex, DeviceInfoData); } - public static boolean SetupDiGetDeviceInterfaceDetail(HDEVINFO DeviceInfoSet, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData, SP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData, int DeviceInterfaceDetailDataSize, int[] RequiredSize, SP_DEVINFO_DATA DeviceInfoData) { - return INSTANCE.SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, DeviceInterfaceData, DeviceInterfaceDetailData, DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData); + public static boolean SetupDiGetDeviceInterfaceDetail(HDEVINFO DeviceInfoSet, + SP_DEVICE_INTERFACE_DATA DeviceInterfaceData, SP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData, + int DeviceInterfaceDetailDataSize, int[] RequiredSize, SP_DEVINFO_DATA DeviceInfoData) { + return INSTANCE.SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, DeviceInterfaceData, DeviceInterfaceDetailData, + DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData); } - public static boolean SetupDiGetDeviceRegistryProperty(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, int Property, int[] PropertyRegDataType, char[] PropertyBuffer, int PropertyBufferSize, int[] RequiredSize) { - return INSTANCE.SetupDiGetDeviceRegistryProperty(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize); + public static boolean SetupDiGetDeviceRegistryProperty(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, + int Property, int[] PropertyRegDataType, char[] PropertyBuffer, int PropertyBufferSize, + int[] RequiredSize) { + return INSTANCE.SetupDiGetDeviceRegistryProperty(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, + PropertyBuffer, PropertyBufferSize, RequiredSize); } static public boolean SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet) { return INSTANCE.SetupDiDestroyDeviceInfoList(DeviceInfoSet); } - static public boolean SetupDiGetDeviceInstanceId(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, char[] DeviceInstanceId, int DeviceInstanceIdSize, int[] RequiredSize) { - return INSTANCE.SetupDiGetDeviceInstanceId(DeviceInfoSet, DeviceInfoData, DeviceInstanceId, DeviceInstanceIdSize, RequiredSize); + static public boolean SetupDiGetDeviceInstanceId(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA DeviceInfoData, + char[] DeviceInstanceId, int DeviceInstanceIdSize, int[] RequiredSize) { + return INSTANCE.SetupDiGetDeviceInstanceId(DeviceInfoSet, DeviceInfoData, DeviceInstanceId, + DeviceInstanceIdSize, RequiredSize); } - static public boolean SetupDiOpenDeviceInterface(HDEVINFO DeviceInfoSet, String DevicePath, int OpenFlags, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData) { + static public boolean SetupDiOpenDeviceInterface(HDEVINFO DeviceInfoSet, String DevicePath, int OpenFlags, + SP_DEVICE_INTERFACE_DATA DeviceInterfaceData) { return INSTANCE.SetupDiOpenDeviceInterface(DeviceInfoSet, DevicePath, OpenFlags, DeviceInterfaceData); } - static public boolean SetupDiDeleteDeviceInterfaceData(HDEVINFO DeviceInfoSet, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData) { + static public boolean SetupDiDeleteDeviceInterfaceData(HDEVINFO DeviceInfoSet, + SP_DEVICE_INTERFACE_DATA DeviceInterfaceData) { return INSTANCE.SetupDiDeleteDeviceInterfaceData(DeviceInfoSet, DeviceInterfaceData); } - static public boolean SetupDiOpenDeviceInfo(HDEVINFO DeviceInfoSet, String DeviceInstanceId, HWND hwndParent, int OpenFlags, SP_DEVINFO_DATA DeviceInfoData) { + static public boolean SetupDiOpenDeviceInfo(HDEVINFO DeviceInfoSet, String DeviceInstanceId, HWND hwndParent, + int OpenFlags, SP_DEVINFO_DATA DeviceInfoData) { return INSTANCE.SetupDiOpenDeviceInfo(DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, DeviceInfoData); } diff --git a/src/purejavahidapi/windows/User32Library.java b/src/purejavahidapi/windows/User32Library.java index 9626882..92108df 100644 --- a/src/purejavahidapi/windows/User32Library.java +++ b/src/purejavahidapi/windows/User32Library.java @@ -32,6 +32,14 @@ import java.util.Arrays; import java.util.List; +import com.sun.jna.Callback; +import com.sun.jna.Native; +import com.sun.jna.Pointer; +import com.sun.jna.Structure; +import com.sun.jna.WString; +import com.sun.jna.win32.StdCallLibrary; +import com.sun.jna.win32.W32APIOptions; + import purejavahidapi.windows.WinDef.ATOM; import purejavahidapi.windows.WinDef.HANDLE; import purejavahidapi.windows.WinDef.HBRUSH; @@ -47,15 +55,6 @@ import purejavahidapi.windows.WinDef.PVOID; import purejavahidapi.windows.WinDef.WPARAM; -import com.sun.jna.Callback; -import com.sun.jna.IntegerType; -import com.sun.jna.Native; -import com.sun.jna.Pointer; -import com.sun.jna.Structure; -import com.sun.jna.WString; -import com.sun.jna.win32.StdCallLibrary; -import com.sun.jna.win32.W32APIOptions; - @SuppressWarnings("serial") public class User32Library { static User32Interface INSTANCE = (User32Interface) Native.loadLibrary("user32", User32Interface.class, W32APIOptions.UNICODE_OPTIONS);