0
我正在嘗試註冊USB設備到達通知和設備從java swing應用程序中刪除完整的事件。JNA調用RegisterDeviceNotification失敗,錯誤1066
我已經成功地稱爲
SetWindowLong(hWnd, MyUser32.GWLP_WNDPROC, listener);
註冊一個偵聽和我正在WM_DEVICECHANGE
類型的通知。到現在爲止還挺好。
現在我想調用RegisterDeviceNotification來確保我收到設備到達通知並刪除完整的事件。這是我曾嘗試:
HWND hWnd = new HWND();
hWnd.setPointer(Native.getWindowPointer(frame));
DEV_BROADCAST_DEVICEINTERFACE filter = new DEV_BROADCAST_DEVICEINTERFACE();
filter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
filter.dbcc_name = new char[1];
filter.dbcc_reserved = new DWORD(0);
filter.dbcc_size = new DWORD(filter.size());
filter.dbcc_size = new DWORD(filter.size());
long retVal = MyUser32.MYINSTANCE.RegisterDeviceNotification(new HANDLE(hWnd.getPointer()), filter.getPointer(), DEVICE_NOTIFY_WINDOW_HANDLE);
if (retVal != 0) {
System.out.println("Error registering for usb: " + Native.getLastError());
}
我JNA聲明是:
public long RegisterDeviceNotification(HANDLE hRecipient, Pointer NotificationFilter, DWORD Flags);
public static class DEV_BROADCAST_DEVICEINTERFACE extends Structure {
public DWORD dbcc_size;
public DWORD dbcc_devicetype;
public DWORD dbcc_reserved;
public GUID dbcc_classguid;
public char[] dbcc_name;
}
public static final GUID GUID_DEVINTERFACE_USB_DEVICE = new GUID(new byte[] {
(byte)0xA5, (byte)0xDC, (byte)0xBF, 0x10, 0x65, 0x30, 0x11, (byte)0xD2, (byte)0x90, 0x1F, 0x00, (byte)0xC0, 0x4F, (byte)0xB9, 0x51, (byte)0xED
});
我總是收到錯誤1066.任何幫助,將不勝感激。如果需要更多信息,請告訴我,我可以包括它。