Author Topic: USB HID - Communicating with a 64 bit dll  (Read 14002 times)

smagness

  • Member
  • ***
  • Posts: 4
USB HID - Communicating with a 64 bit dll
« on: November 09, 2011, 04:37:45 am »
We have a working HID device that has been using a 32 bit dll to talk to and read from the device for a number of years. We now have a customer who wants to update their application to 64 bits and therefore requires that we upgrade our usb comms dll to 64 bits. We are using Delphi XE2 and the JEDI component library (HID and SetupAPI) to communicate with the HID devices but I cannot get the 64 bit dll to see the device.

Doe anyone have any experience of this side of things? Is it possible, how did you get it to work?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB HID - Communicating with a 64 bit dll
« Reply #1 on: November 09, 2011, 11:11:33 am »
I believe my latest HID code works under 64 bits:

http://www.lvr.com/hidpage.htm#MyExampleCode

Jan

smagness

  • Member
  • ***
  • Posts: 4
Re: USB HID - Communicating with a 64 bit dll
« Reply #2 on: November 10, 2011, 04:29:35 am »
Jan, I can confirm that the VB projects work in 64 bits, but I was hoping for a Delphi solution. I have tried the Delphi HIDTest program and updating it to 64 bits but I can see no HID devices. Would it be possible to take a look at the Delphi version, or at least point me in the right direction as to how to convert the VB solution in to a Delphi app?

Any help would be much appreciated.

Steve

smagness

  • Member
  • ***
  • Posts: 4
Re: USB HID - Communicating with a 64 bit dll
« Reply #3 on: November 10, 2011, 05:01:48 am »
It's really the cbSize of the various structures that I am not quite getting to grips with. Is there an easy way to determine these values for 32 or 64 bits?

SP_DEVICE_INTERFACE_DATA = 28 in 32 bits, and 32 in 64 bits - is this correct?
SP_DEVINFO_DATA = 28 in 32 bits, and 32 in 64 bits - is this correct?
SP_DEVICE_INTERFACE_DETAIL_DATA_A - entirely unsure of this, currently 6 works for for 32 bits, but no success with 64 bits, error returned from SetupDiGetDeviceInterfaceDetail

When I make the first call to SetupDiGetDeviceInterfaceDetail in 32 bits I get 170 bytes returned. When I convert this to 64 bits and update the first two cbSize to 32 instead of 28 I get 87 bytes returned.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB HID - Communicating with a 64 bit dll
« Reply #4 on: November 10, 2011, 10:10:38 am »
The API functions are the same no matter what programming language you use. I have VB and C# versions but no Delphi so you'll need to do that translation.

For SP_DEVICE_INTERFACE_DATA, my code says:

'The cbSize element of the MyDeviceInterfaceData structure must be set to
         'the structure's size in bytes.
         ' The size is 28 bytes for 32-bit code and 32 bits for 64-bit code.

         myDeviceInterfaceData.cbSize = Marshal.SizeOf(myDeviceInterfaceData)


My code doesn't use SP_DEVINFO_DATA.

Get the size of SP_DEVICE_INTERFACE_DETAIL_DATA by calling SetupDiGetDeviceInterfaceDetail. Then allocate a buffer and retrieve the structure. See my code for an example.

Jan




smagness

  • Member
  • ***
  • Posts: 4
Re: USB HID - Communicating with a 64 bit dll
« Reply #5 on: November 10, 2011, 10:35:28 am »
I have literally this minute got it working. I had to update the JVCL SetupAPI.pas: it was using DWORD and returning the wrong size for the structures. I updated this to NativeUInt and it now works, with a couple of other tweaks.

Thanks very much for your pointers, the VB code did help, if nothing else it proved to me that it was possible using those API calls.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB HID - Communicating with a 64 bit dll
« Reply #6 on: November 10, 2011, 06:02:46 pm »
I'm glad to hear you got it working!

Jan