View Issue Details

IDProjectCategoryView StatusLast Update
0005706JEDI VCL01 Helppublic2012-09-10 14:15
ReportersmagnessAssigned ToChristianWimmer 
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Product Version3.45 
Target VersionFixed in Version3.46 
Summary0005706: USB HID enumeration using SetupAPI on 64 bit
DescriptionI have had some trouble enumerating HID devices on USB bus using the JVCL SetupAPI. 32 bit works fine but as soon as I switch to 64 bit some of the function calls to SetupAPI unit now fail... I have come across people mentioning the need to change 'cbsize' to nearest 8 bits of some of the Structures when using 64 bit compiler. Does anyone have any information on this and why this is necessary?

I am currently getting 0 bytes returned when calling SetupDiGetDeviceInterfaceDetail(), despite this working fine in 32 bit compiler.

Any help would be much appreciated.

TagsNo tags attached.

Activities

smagness

2011-11-08 16:21

reporter   ~0019100

Further to this I have now followed the SetupDiGetDeviceInterfaceDetail in to SetupAPI where there is a comment above the type definitions for TSetupDiGetDeviceInterfaceDetail:

//
// Backward compatibility--do not use.
//

How am I supposed to enumerate USB HID devices using SetupAPI if not using this function?

smagness

2011-11-08 16:21

reporter   ~0019101

Further to this I have now followed the SetupDiGetDeviceInterfaceDetail in to SetupAPI where there is a comment above the type definitions for TSetupDiGetDeviceInterfaceDetail:

//
// Backward compatibility--do not use.
//

How am I supposed to enumerate USB HID devices using SetupAPI if not using this function?

2011-11-10 16:22

 

SetupApi.pas (448,164 bytes)

smagness

2011-11-10 16:23

reporter   ~0019107

Fixed - a few of the variables in SetupAPI.pas have been changed from DWORD to NativeUInt and it now works as expected, although you have to be careful about sizing the PSPDeviceInterfaceDetailData structure (cbSize).

I have attached my updated SetupAPI if it wants to be integrated for the next release of the jvcl

ChristianWimmer

2011-11-27 16:55

manager   ~0019141

Hi

Where did you get this SetupApi.pas originally? I could not find it in JVCL SVN. You are posting this issue in "[JEDI VCL] 01 Help ", so I guess I didn't find it. Could you provide the absolute sourcepath to the file? Thx.

I checked your issue with SetupDiGetDeviceInterfaceDetail and compared your changes with the original.
You did a few DWORD changes but not all, e.g. in the parameter declaration of SetupDiGetDeviceInterfaceDetailA and W. However, you did change records that are used by this functions.

I also checked out the original setupapi.h from MS SDK 6.1 (Win7) and I think I found the problem. The problem is the alignment of members within structures in memory.
In 32bit version of setupapi (.h and .pas) all structures are aligned on a one byte boundary (for explanation see: http://www.delphibasics.co.uk/RTL.asp?Name=Packed). That means in Delphi we have to use the packed word on records.
On the other hand, setupapi changes this alignment for 64bit plattforms to an 8 byte boundary. So the packed keyword in Delphi cannot be applied.
Thus SetupApi.h defines for all structures:

#ifdef _WIN64
#include <pshpack8.h> // Assume 8-byte (64-bit) packing throughout
#else
#include <pshpack1.h> // Assume byte packing throughout (32-bit processor)
#endif

Your problem may come from this fact with a high probability, imo.

So remove the packed keyword on all records and defined $ALIGN 8 for 64bit plattform only (Use IFDEF). This should solve the problem.

BTW: If SetupDiGetDeviceInterfaceDetail returned false, what was the result of GetLastError???



About the issue : "// Backward compatibility--do not use."
It is not intended for you or any Delphi user.
The original comment looked like this:

//
// Backward compatibility--do not use.
//
#define SetupDiDeleteInterfaceDeviceData SetupDiDeleteDeviceInterfaceData

So the comment addresses this define which declares another (old) name of the function SetupDiDeleteInterfaceDeviceData. The comment should have been removed on conversion. The original function SetupDiGetDeviceInterfaceDetail is fine to use.


Currently, there is a process of migrating this unit to 64bit and also updating it to the newest MS header version. Maybe you can test this new version when the conversion is finished.
Please contact me at : mail(at_replaceby@)delphi-jedi.net
The version will be available throught the JEDI Windows API Project.

ChristianWimmer

2011-12-09 18:01

manager   ~0019198

See my comment above.

smagness

2011-12-12 14:03

reporter   ~0019204

Christian, I believe the original SetupAPI.pas file came from downloading JVCL v3.45 from sourceforge via the JEDI page http://jvcl.delphi-jedi.org/. We did have trouble at first when I was trying to upgrade from v3.38 so perhaps it didn't update correctly?

You mention a 64Bit version may be on it's way at some point, is this imminent?

Unfortunately I have other work to get on with at the minute so I don't have time to test the $ALIGN 8 suggestion, but I will let you know when I do.

ChristianWimmer

2011-12-31 14:37

manager   ~0019286

I don't know why there is a SetupApi in JVCL. I would have believed to find it in the Windows API conversion project JEDI API. Well, it is there but I don't know the differences. However, a member of JEDI API is updating the SetupApi at the moment.

obones

2012-02-24 13:57

administrator   ~0019533

So guys, what should be done here?
Do we, as the JVCL, need to update our copy?
Must we wait for something?
Must we change something in our own copy?

ChristianWimmer

2012-02-25 12:29

manager   ~0019551

Last edited: 2012-02-25 12:30

How is the the SetupApi used in JVCL? I suggest to mark it as an internally used library that should not be used by 3rd parties. Also add a comment and point to the JEDI API version.
In this way the user can decide which version is appropriate for her.

obones

2012-02-27 10:01

administrator   ~0019559

It is being used by quite a few files actually:
CfgMgr32
JvCabFile
JvCommonDialogD
JvCopyError
JvDeleteError
JvDiskPrompt
JvHidControllerClass
JvRenameError

Might be that some don't need it, but I believe that most do.
What we could do is rename the file and add a comment at the top mentioning your remarks.

obones

2012-06-13 15:58

administrator   ~0019959

Ok, then, changes are in SVN
I have renamed SetupAPI to JvSetupAPI and made changes inside it so that it also works under x64.

Issue History

Date Modified Username Field Change
2011-11-08 12:09 smagness New Issue
2011-11-08 16:21 smagness Note Added: 0019100
2011-11-08 16:21 smagness Note Added: 0019101
2011-11-10 16:22 smagness File Added: SetupApi.pas
2011-11-10 16:23 smagness Note Added: 0019107
2011-11-27 16:55 ChristianWimmer Note Added: 0019141
2011-12-09 18:01 ChristianWimmer Note Added: 0019198
2011-12-09 18:01 ChristianWimmer Assigned To => ChristianWimmer
2011-12-09 18:01 ChristianWimmer Status new => feedback
2011-12-12 14:03 smagness Note Added: 0019204
2011-12-31 14:37 ChristianWimmer Note Added: 0019286
2012-02-17 14:18 ChristianWimmer Status feedback => assigned
2012-02-24 13:57 obones Note Added: 0019533
2012-02-25 12:29 ChristianWimmer Note Added: 0019551
2012-02-25 12:30 ChristianWimmer Note Edited: 0019551
2012-02-27 10:01 obones Note Added: 0019559
2012-06-13 15:58 obones Note Added: 0019959
2012-06-13 15:58 obones Status assigned => resolved
2012-06-13 15:58 obones Fixed in Version => Daily / SVN
2012-06-13 15:58 obones Resolution open => fixed
2012-09-10 14:15 obones Fixed in Version Daily / SVN => 3.46