zht_it
驱动牛犊
驱动牛犊
  • 注册日期2002-08-14
  • 最后登录2002-10-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1028回复:0

再问

楼主#
更多 发布于:2002-08-25 14:08
USB_HidFileHandle : THandle;
   hardwareDeviceInfo : HDEVINFO;
   functionClassDeviceData : PSPDeviceInterfaceDetailData;
   predictedLength : Dword;
   requiredLength : Dword;
   Success:LongBool;
   devicepath:String;
   deviceInfoData :_SP_DEVICE_INTERFACE_DATA;
   const LINK_GUID_V: TGUID =\'{D4ACFD5E-7710-4579-9B7D-9731967C3C5A}\';
   LINK_GUID : PGUID = @LINK_GUID_V;

begin
   hardwareDeviceInfo := SetupDiGetClassDevs (
                         Link_GUid,
                         nil, // Define no enumerator (global)
                         0, // Define no
                        (DIGCF_PRESENT or // Only Devices present
                         DIGCF_INTERFACEDEVICE)); // Function class devices.
   if hardwareDeviceInfo = Pointer(INVALID_HANDLE_VALUE) then  Exit;   //ADD

   deviceInfoData.cbSize := sizeof (_SP_DEVICE_INTERFACE_DATA);
   Success := SetupDiEnumDeviceInterfaces(hardwareDeviceInfo, nil, LINK_GUID^, 0, deviceInfoData);
   if Success then
   begin
     SetupDiGetInterfaceDeviceDetail(
                            hardwareDeviceInfo,
                            @deviceInfoData,
                            nil, // probing so no output buffer yet
                            0, // probing so output buffer length of zero
                            @requiredLength,
                            nil); // not interested in the specific dev-node

     predictedLength := requiredLength;
     functionClassDeviceData := AllocMem(predictedLength);
     functionClassDeviceData.cbSize := sizeof (_SP_DEVICE_INTERFACE_DETAIL_DATA_);

    if (not SetupDiGetInterfaceDeviceDetail (
                            HardwareDeviceInfo,
                            @DeviceInfoData,
                            functionClassDeviceData,
                            predictedLength,
                            @requiredLength,
                            nil)) then
     begin
       freeMem(functionClassDeviceData);
       exit;
     end;

     devicepath:=functionClassDeviceData.DevicePath;
     //取得DevicePath后,打开设备
     USB_HidFileHandle := CreateFile(
   PChar(devicepath),
   GENERIC_READ or GENERIC_WRITE,
   FILE_SHARE_READ or FILE_SHARE_WRITE,
   nil,
   OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL,
   0);
     if USB_HidFileHandle = INVALID_HANDLE_VALUE then

上面所取得devicepath总是为\'\\\'空,请问是哪里出错?

最新喜欢:

Jkw_DevJkw_De...
游客

返回顶部