delphi – 在64位应用程序中使用SetupAPI枚举USB HID设备
发布时间:2020-12-15 09:45:17 所属栏目:大数据 来源:网络整理
导读:我正在使用Delphi XE2并尝试将我们的usb通信dll升级到64位.我们正在使用JVCL SetupAPI和Hid单元.所有工作完全使用32位编译器,可以看到我附加的HID设备.我切换到64位,我再也看不到任何我知道的HID设备了. 我遇到有人提到需要以64位不同的方式调整某些数据结构
我正在使用Delphi XE2并尝试将我们的usb通信dll升级到64位.我们正在使用JVCL SetupAPI和Hid单元.所有工作完全使用32位编译器,可以看到我附加的HID设备.我切换到64位,我再也看不到任何我知道的HID设备了.
我遇到有人提到需要以64位不同的方式调整某些数据结构的大小(见https://forums.embarcadero.com/thread.jspa?messageID=408473#408473),这有所帮助,但我现在正式感到难过. 目前我的代码返回从SetupDiGetDeviceInterfaceDetail函数读取的0字节.注释掉的SizeOf()适用于32位但不适用于64位. 任何帮助将非常感激. repeat TmpDeviceInterfaceData.cbSize := SizeOf(TSPDeviceInterfaceData); TmpDeviceInterfaceData.cbSize := 32; // SizeOf(TmpDeviceInterfaceData); TmpSuccess := SetupDiEnumDeviceInterfaces(TmpDevInfo,nil,TmpDevHidGuid,TmpDevn,TmpDeviceInterfaceData); if TmpSuccess then begin TmpDevData.cbSize := 32; //SizeOf(TmpDevData); showmessage(inttostr(tmpdevdata.cbsize)); TmpBytesReturned := 0; SetupDiGetDeviceInterfaceDetail(TmpDevInfo,@TmpDeviceInterfaceData,TmpBytesReturned,@TmpDevData); showmessage('bytes returned = ' + inttostr(TmpBytesReturned)); if (TmpBytesReturned <> 0) and (GetLastError = ERROR_INSUFFICIENT_BUFFER) then begin // showmessage('hello'); TmpFunctionClassDeviceData := AllocMem(TmpBytesReturned); TmpFunctionClassDeviceData.cbSize := sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A); TmpFunctionClassDeviceData.cbSize := 8; // showmessage(inttostr(TmpFunctionClassDeviceData.cbSize)); if SetupDiGetDeviceInterfaceDetail(TmpDevInfo,TmpFunctionClassDeviceData,@TmpDevData) then begin // showmessage('here'); try begin //try to obtain PID and VID information about the HID devices TmpDeviceHandle := CreateFile(@TmpFunctionClassDeviceData.DevicePath,GENERIC_READ OR GENERIC_WRITE,FILE_SHARE_READ OR FILE_SHARE_WRITE,NIL,OPEN_EXISTING,0); TmpAttributes.Size := Sizeof(TmpAttributes); HidD_GetAttributes(TmpDeviceHandle,TmpAttributes); If (vid = TmpAttributes.VendorID) then begin PIDlistStr := PIDlistStr + Inttostr(TmpAttributes.ProductID) + ','; end ; if TmpDeviceHandle <> INVALID_HANDLE_VALUE then begin CloseHandle(TmpDeviceHandle); TmpAttributes.ProductID := 0; TmpAttributes.VendorID := 0; end; TmpDeviceHandle := INVALID_HANDLE_VALUE; end except // ignore device if unreadable end; Inc(TmpDevn); end else showmessage('error in SetupDiGetDeviceInterfaceDetails'); FreeMem(TmpFunctionClassDeviceData); end; end; until not TmpSuccess; 解决方法
现在更改是在JVCL中,请使用最新的SVN内容.
基本上,需要修复SetupApi,以便它在x64中使用“填充”进行对齐. 这已经过测试,在这里运行良好. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |