私はDelphi XE2を使用しており、usb comms dllを64ビットにアップグレードしようとしています。 JVCL SetupAPIとHidユニットを使用しています。すべてが32ビットコンパイラを使用して完全に動作し、付属のHIDデバイスを見ることができます。 64ビットに切り替えると、私が知っているHIDデバイスが見えなくなります。64ビットアプリケーションでSetupAPIを使用してUSB 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, 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;
> DevicePathのMSは、ここで言うように、明示的に をコピーする必要がある理由: http://msdn.microsoft.com/en-us/library/windows/hardware/ff552343%28v=vs.85%29 .aspx > DevicePath >デバイスインターフェイスパスを含むNULLで終了する文字列。このパスは、CreateFileなどのWin32関数に渡すことができます。 szDevicePath:= PChar(@ TmpFunctionClassDeviceData.DevicePath [0]); は、その値をCreateFileに渡すために使用します。 –