Tôi đang sử dụng Delphi XE2 và cố gắng nâng cấp dll usb của chúng tôi lên 64 bit. Chúng tôi đang sử dụng các thiết bị JVCL SetupAPI và Hid. Tất cả các công trình hoàn hảo bằng cách sử dụng trình biên dịch 32 bit và có thể nhìn thấy thiết bị HID kèm theo của tôi. Tôi chuyển sang 64 bit và tôi không thể nhìn thấy bất kỳ thiết bị HID nào mà tôi biết được đính kèm.Liệt kê các thiết bị USB HID bằng SetupAPI trong ứng dụng 64 bit
Tôi đã bắt gặp mọi người đề cập đến sự cần thiết phải thay đổi kích thước một số cấu trúc dữ liệu khác nhau cho 64 bit (xem https://forums.embarcadero.com/thread.jspa?messageID=408473#408473) và điều này đã giúp nhưng tôi bây giờ chính thức stumped.
Hiện tại mã của tôi đang trả về 0 byte được đọc từ hàm SetupDiGetDeviceInterfaceDetail. Các nhận xét ra SizeOf() đã làm việc cho 32 bit nhưng không cho 64 bit.
Mọi trợ giúp sẽ được đánh giá cao.
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, nil, 0, 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, @TmpDeviceInterfaceData, TmpFunctionClassDeviceData, TmpBytesReturned, TmpBytesReturned, @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 , 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;
> tại sao DevicePath cần phải được sao chép một cách rõ ràng như ms nói ở đây: http://msdn.microsoft.com/en-us/library/windows/hardware/ff552343%28v=vs.85%29 .aspx > DevicePath > Chuỗi bị chấm dứt NULL chứa đường dẫn giao diện thiết bị. Đường dẫn này có thể được chuyển tới các hàm Win32 như CreateFile. szDevicePath: = PChar (@ TmpFunctionClassDeviceData.DevicePath [0]); sử dụng giá trị đó để chuyển đến CreateFile. –