Skip to content

Commit

Permalink
Added JNA platform and used it to replace WinDef functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
kuznetsovmoci committed Dec 6, 2019
1 parent 4150a3d commit 5580ce7
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 36 deletions.
Binary file modified bin/purejavahidapi-src.jar
Binary file not shown.
Binary file modified bin/purejavahidapi.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions build-jars.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

<path id="compile">
<pathelement location="lib/jna-5.5.0.jar"/>
<pathelement location="lib/jna-platform-5.5.0.jar"/>
</path>

<path id="examples">
<pathelement location="lib/jna-5.5.0.jar"/>
<pathelement location="lib/jna-platform-5.5.0.jar"/>
<pathelement location="${class}"/>
</path>

Expand Down
Binary file added lib/jna-platform-5.5.0.jar
Binary file not shown.
19 changes: 13 additions & 6 deletions src/purejavahidapi/windows/DeviceRemovalHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@
*/
package purejavahidapi.windows;

import static com.sun.jna.platform.win32.DBT.*;
import static com.sun.jna.platform.win32.WinBase.INVALID_HANDLE_VALUE;
import static purejavahidapi.windows.SetupApiLibrary.*;

import com.sun.jna.WString;

import com.sun.jna.platform.win32.DBT.*;
import com.sun.jna.platform.win32.WinUser.*;
import com.sun.jna.platform.win32.WinDef.*;

import purejavahidapi.shared.SyncPoint;
import purejavahidapi.windows.WinDef.*;
import static purejavahidapi.windows.WinDef.*;
//import purejavahidapi.windows.WinDef.*;
//import static purejavahidapi.windows.WinDef.*;

import static purejavahidapi.windows.Kernel32Library.*;
import static purejavahidapi.windows.User32Library.*;
import static purejavahidapi.windows.WtsApi32Library.*;
Expand All @@ -55,7 +62,7 @@ public void run() {
if (hInst == null)
reportLastError();

WNDCLASSEX wndClassEx = new WNDCLASSEX();
User32Library.WNDCLASSEX wndClassEx = new User32Library.WNDCLASSEX();
wndClassEx.hInstance = hInst;
wndClassEx.lpfnWndProc = DeviceRemovalHandler.this;
wndClassEx.lpszClassName = wndClassName;
Expand All @@ -77,13 +84,13 @@ public void run() {
notificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
notificationFilter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;

HDEVNOTIFY hDevNotify = RegisterDeviceNotification(hWnd, notificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);
User32Library.HDEVNOTIFY hDevNotify = RegisterDeviceNotification(hWnd, notificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);
if (hDevNotify == null)
reportLastError();

m_StartupSync.waitAndSync();

MSG msg = new MSG();
User32Library.MSG msg = new User32Library.MSG();
while (GetMessage(msg, hWnd, 0, 0) != 0) {
TranslateMessage(msg);
DispatchMessage(msg);
Expand Down Expand Up @@ -162,7 +169,7 @@ protected LRESULT onDeviceChangeArrivalOrRemoveComplete(LPARAM lParam, String ac
switch (bhdr.dbch_devicetype) {
case DBT_DEVTYP_DEVICEINTERFACE: {
DEV_BROADCAST_DEVICEINTERFACE bdif = new DEV_BROADCAST_DEVICEINTERFACE(bhdr.getPointer());
handleDeviceRemoval(bdif.get_dbcc_name());
handleDeviceRemoval(bdif.getDbcc_name());
break;
}
default:
Expand Down
9 changes: 6 additions & 3 deletions src/purejavahidapi/windows/HidDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
package purejavahidapi.windows;

import static com.sun.jna.platform.win32.WinBase.INVALID_HANDLE_VALUE;
import static purejavahidapi.windows.HidLibrary.HidD_FreePreparsedData;
import static purejavahidapi.windows.HidLibrary.HidD_GetAttributes;
import static purejavahidapi.windows.HidLibrary.HidD_GetPreparsedData;
Expand All @@ -37,18 +38,20 @@
import static purejavahidapi.windows.HidLibrary.HidP_GetCaps;
import static purejavahidapi.windows.Kernel32Library.*;
import static purejavahidapi.windows.SetupApiLibrary.HIDP_STATUS_SUCCESS;
import static purejavahidapi.windows.WinDef.INVALID_HANDLE_VALUE;
//import static purejavahidapi.windows.WinDef.INVALID_HANDLE_VALUE;

import com.sun.jna.Memory;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;

import com.sun.jna.platform.win32.WinBase.OVERLAPPED;
import com.sun.jna.platform.win32.WinNT.HANDLE;
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 purejavahidapi.windows.WinDef.HANDLE;
//import purejavahidapi.windows.WinDef.OVERLAPPED;

import java.io.BufferedWriter;
import java.io.FileWriter;
Expand Down
3 changes: 2 additions & 1 deletion src/purejavahidapi/windows/HidDeviceInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
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.HANDLE;
import com.sun.jna.platform.win32.WinNT.HANDLE;

/* package*/class HidDeviceInfo extends purejavahidapi.HidDeviceInfo {

Expand Down
3 changes: 2 additions & 1 deletion src/purejavahidapi/windows/HidLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
import com.sun.jna.Union;
import com.sun.jna.win32.StdCallLibrary;

import purejavahidapi.windows.WinDef.HANDLE;
//import purejavahidapi.windows.WinDef.HANDLE;
import com.sun.jna.platform.win32.WinNT.HANDLE;

public class HidLibrary {
static HidLibraryInterface INSTANCE = (HidLibraryInterface) Native.load("hid", HidLibraryInterface.class);
Expand Down
15 changes: 11 additions & 4 deletions src/purejavahidapi/windows/Kernel32Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@

import com.sun.jna.Native;
import com.sun.jna.Pointer;
//import com.sun.jna.platform.win32.WinBase;
//import com.sun.jna.platform.win32.WinDef;
//import com.sun.jna.platform.win32.WinNT;
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;
import com.sun.jna.platform.win32.WinNT.HANDLE;
import com.sun.jna.platform.win32.WinDef.HMODULE;
import com.sun.jna.platform.win32.WinBase.OVERLAPPED;
import com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES;
//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.load("kernel32", Kernel32Interface.class, W32APIOptions.UNICODE_OPTIONS);
Expand Down
7 changes: 4 additions & 3 deletions src/purejavahidapi/windows/SetupApiLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.win32.W32APIOptions;

import purejavahidapi.windows.WinDef.HANDLE;
import purejavahidapi.windows.WinDef.HWND;
import com.sun.jna.platform.win32.WinNT.HANDLE;
import com.sun.jna.platform.win32.WinDef.HWND;

public class SetupApiLibrary {
static SetupApiInterface INSTANCE = (SetupApiInterface) Native.load("setupapi", SetupApiInterface.class,
Expand Down Expand Up @@ -292,7 +293,7 @@ boolean SetupDiOpenDeviceInterface(HDEVINFO DeviceInfoSet, String DevicePath, in
boolean SetupDiDeleteDeviceInterfaceData(HDEVINFO DeviceInfoSet, SP_DEVICE_INTERFACE_DATA DeviceInterfaceData);

boolean SetupDiOpenDeviceInfo(HDEVINFO DeviceInfoSet, String DeviceInstanceId, HWND hwndParent, int OpenFlags,
SP_DEVINFO_DATA DeviceInfoData);
SP_DEVINFO_DATA DeviceInfoData);
}

public static HDEVINFO SetupDiCreateDeviceInfoList(GUID ClassGuid, HWND hwndParent) {
Expand Down
30 changes: 16 additions & 14 deletions src/purejavahidapi/windows/User32Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,22 @@
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;
import purejavahidapi.windows.WinDef.HCURSOR;
import purejavahidapi.windows.WinDef.HICON;
import purejavahidapi.windows.WinDef.HINSTANCE;
import purejavahidapi.windows.WinDef.HMENU;
import purejavahidapi.windows.WinDef.HWND;
import purejavahidapi.windows.WinDef.LPARAM;
import purejavahidapi.windows.WinDef.LPVOID;
import purejavahidapi.windows.WinDef.LRESULT;
import purejavahidapi.windows.WinDef.POINT;
import purejavahidapi.windows.WinDef.PVOID;
import purejavahidapi.windows.WinDef.WPARAM;
//import purejavahidapi.windows.WinDef.ATOM;
//import purejavahidapi.windows.WinDef.HANDLE;
//import purejavahidapi.windows.WinDef.HBRUSH;
//import purejavahidapi.windows.WinDef.HCURSOR;
//import purejavahidapi.windows.WinDef.HICON;
//import purejavahidapi.windows.WinDef.HINSTANCE;
//import purejavahidapi.windows.WinDef.HMENU;
//import purejavahidapi.windows.WinDef.HWND;
//import purejavahidapi.windows.WinDef.LPARAM;
//import purejavahidapi.windows.WinDef.LPVOID;
//import purejavahidapi.windows.WinDef.LRESULT;
//import purejavahidapi.windows.WinDef.POINT;
//import purejavahidapi.windows.WinDef.PVOID;
//import purejavahidapi.windows.WinDef.WPARAM;
import com.sun.jna.platform.win32.WinDef.*;
import com.sun.jna.platform.win32.WinNT.HANDLE;

@SuppressWarnings("serial")
public class User32Library {
Expand Down
3 changes: 2 additions & 1 deletion src/purejavahidapi/windows/WinDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import purejavahidapi.windows.SetupApiLibrary.GUID;

import com.sun.jna.win32.StdCallLibrary.StdCallCallback;

/*
public class WinDef {
public static final int DBT_DEVICEREMOVECOMPLETE = 0x8004;
Expand Down Expand Up @@ -388,3 +388,4 @@ public interface WindowProc extends StdCallCallback {
LRESULT callback(HWND hwnd, int uMsg, WPARAM wParam, LPARAM lParam);
}
}
*/
8 changes: 6 additions & 2 deletions src/purejavahidapi/windows/WindowsBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@
import purejavahidapi.windows.SetupApiLibrary.HDEVINFO;
import purejavahidapi.windows.SetupApiLibrary.SP_DEVICE_INTERFACE_DATA;
import purejavahidapi.windows.SetupApiLibrary.SP_DEVINFO_DATA;
import purejavahidapi.windows.WinDef.HANDLE;

//import purejavahidapi.windows.WinDef.HANDLE;
import com.sun.jna.platform.win32.WinNT.HANDLE;
import static com.sun.jna.platform.win32.WinBase.INVALID_HANDLE_VALUE;
import static purejavahidapi.windows.CfgmgrLibrary.*;
import static purejavahidapi.windows.WinDef.INVALID_HANDLE_VALUE;
//import static purejavahidapi.windows.WinDef.INVALID_HANDLE_VALUE;


import com.sun.jna.Native;
import com.sun.jna.NativeLong;
Expand Down
3 changes: 2 additions & 1 deletion src/purejavahidapi/windows/WtsApi32Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
*/
package purejavahidapi.windows;

import purejavahidapi.windows.WinDef.HWND;
//import purejavahidapi.windows.WinDef.HWND;
import com.sun.jna.platform.win32.WinDef.HWND;

import com.sun.jna.Native;
import com.sun.jna.win32.StdCallLibrary;
Expand Down

0 comments on commit 5580ce7

Please sign in to comment.