Forum > General

FPC-USB-HID library doesn't work when compiled to 64-bit under Windows

(1/3) > >>

kovalsky:
Try to use FPC-USB-HID library https://github.com/LongDirtyAnimAlf/FPC-USB-HID
I found that the test examples do not work when compiled to 64-bit under Windows. The problem is that
SizeOf(TSPDeviceInterfaceDetailData) returns 7 instead of 8 in the enumeration HID device method.
This library use modified version of JvSetupApi.pas unit in which a definition for alignment has been added:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$IFDEF FPC}  {$IFDEF CPU64}    {$PACKRECORDS 8}  {$ELSE}    {$PACKRECORDS 1}  {$ENDIF CPU64}{$ELSE}{$A-}{$ENDIF FPC}Why SizeOf() still returns 7 as if the alignment is 1 byte?

jamie:
https://learn.microsoft.com/en-us/windows/win32/api/setupapi/ns-setupapi-sp_device_interface_detail_data_a

Looks like it can't be aligned, the first field must contain the current size of the record which includes the field plus a string that is NULL terminated.

kovalsky:

--- Quote from: jamie on December 01, 2022, 02:24:32 pm ---Looks like it can't be aligned, the first field must contain the current size of the record which includes the field plus a string that is NULL terminated.

--- End quote ---
Does this mean that the SP_DEVICE_INTERFACE_DETAIL_DATA record should be declared withoud packed keyword?
I removed it from record declaration in JvSetupApi.pas and the example started working fine in 64-bit.

jamie:
Looking at it, I would say it's a bad translation.

 You should be setting the field size to 0 and then pass that image to the Setup function for the details, it will fail because the record won't be large enough, but the return value will report to you how large it should be.

 With your now known value, you can either give it a record that has more than enough space or allocate one dynamically of the requested record size and then pass that pointer to the setup function.

 That isn't a fixed size record and I suppose if there is enough space in it the function will fill it up to the amount of space it needs, leaving the remainder undefined.

 That is a variable record with a variant tail size and the idea is that you can daisy chain these devices with a NULL separator, and in most cases, two NULLs will indicate the end of the line.


avra:

--- Quote from: kovalsky on December 01, 2022, 10:28:04 pm ---I removed it from record declaration in JvSetupApi.pas and the example started working fine in 64-bit.
--- End quote ---
Could you please report your findings at https://github.com/LongDirtyAnimAlf/FPC-USB-HID/issues so that others can also benefit if that turns out to be the right solution?

Navigation

[0] Message Index

[#] Next page

Go to full version