nyholku / purejavahidapi

Other
120 stars 69 forks source link

PureJavaHidApi.enumerateDevices(); fails on Win 7/64 #33

Closed marek-trmac closed 7 years ago

marek-trmac commented 8 years ago

I have Win7 64 bit, Java 8, and the following code: List<HidDeviceInfo> hidDevices = PureJavaHidApi.enumerateDevices(); fails with error:

java.lang.RuntimeException: GetLastError() == 1784 at WindowsBackend.java:151
    at purejavahidapi.windows.WindowsBackend.reportLastError(WindowsBackend.java:102)
    at purejavahidapi.windows.WindowsBackend.enumerateDevices(WindowsBackend.java:151)
    at purejavahidapi.PureJavaHidApi.enumerateDevices(PureJavaHidApi.java:80)
    at ddr.DDRMainWindow.main(DDRMainWindow.java:43)

Is Win7 64 bit supported?

nyholku commented 8 years ago

On 19 Aug 2016, at 16:50, Marek Trmac notifications@github.com wrote:

I have Win7 64 bit, Java 8, and the following code: List hidDevices = PureJavaHidApi.enumerateDevices(); fails with error:

java.lang.RuntimeException: GetLastError() == 1784 at WindowsBackend.java:151 at purejavahidapi.windows.WindowsBackend.reportLastError(WindowsBackend.java:102) at purejavahidapi.windows.WindowsBackend.enumerateDevices(WindowsBackend.java:151) at purejavahidapi.PureJavaHidApi.enumerateDevices(PureJavaHidApi.java:80) at ddr.DDRMainWindow.main(DDRMainWindow.java:43)

Is Win7 64 bit supported?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Yes, I develop on W7/64 bit.

What devices do you have attached to your USB bus?

wbr Kusti

marek-trmac commented 8 years ago

Mouse and keyboard. The problem appears if any of these devices is connected.

marek-trmac commented 8 years ago

The problem is probably in SetupApiLibrary, field cbSize:

    static public class SP_DEVICE_INTERFACE_DETAIL_DATA_A extends Structure {
        public int cbSize = Pointer.SIZE == 8 ? 8 : 5; // Note 1
        // Note 1, I believe this structure is packed in Windows API and as this field
        // is initialized with sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) it gets the size
        // 5 in 32 bit process **but 8 in 64 bit process**...i think! Nasty little detail
        // when accessing C API from Java with JNA

On my machine (win7, 64 bit), Pointer.SIZE is 4, e.g. cbSize is 5. If I change cbSize to 6, the problem disapperas.

nyholku commented 8 years ago

Hi, thanks for debugging.

Interesting! So is your JVM code 32 bit though your machine is 64 bit?

Can you check if 8 instead of 6 works in your machine?

It has been a while but I put that code [Pointer.SIZE == 8 ? 8 : 5] there for a reason, i.e. meaning that in the system I was using at the time it was necessary to get the code working...

I will try to find some more information about this.

marek-trmac commented 8 years ago

Yes, you are right - I have used 32bit JVM for this project.

Can you check if 8 instead of 6 works in your machine?

8 does not work

nyholku commented 8 years ago

Ok, thanks for testing.

This is weird because I must have tested this code when I wrote it.

nyholku commented 8 years ago

Can you test with the latest code please?

nyholku commented 7 years ago

This has been addressed (I hope) in the latest release (0.0.7->) so I'm closing this, feel free to open if it comes back to haunt us.