gehuadongqq
驱动牛犊
驱动牛犊
  • 注册日期2003-03-27
  • 最后登录2004-06-18
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1326回复:1

用delphi开发usb应用程序疑难!

楼主#
更多 发布于:2003-11-26 09:32
我用delphi开发usb应用程序,想要获取设备的路径名,进行了如下操作:
var
  hardwareDeviceInfo      : HDevInfo ;
  functionClassDeviceData : PSPDeviceInterfaceDetailData ;
  predictedLength         : Dword ;
  requiredLength          : Dword ;
  deviceInfoData          : TSPDeviceInterfaceData ;
  devName                 : string ;
  InterfaceClassGuid    : TGUID = \'{36FC9E60-C465-11CF-8056-444553540000}\' ;
  const LINK_GUID_V       : TGUID = \'{36FC9E60-C465-11CF-8056-444553540000}\' ;
    LINK_GUID             : PGUID = @LINK_GUID_V ;
      ......
var
  ErrorCode   : DWORD;
  retb        : BOOLEAN;
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 THandle(hardwareDeviceInfo) = INVALID_HANDLE_VALUE then
  begin
    ShowMessage(\'SetupDiGetClassDevs INVALID_HANDLE_VALUE \' + IntToHex(GetLastError(),4));
  end;

  deviceInfoData.cbSize := sizeof (_SP_DEVICE_INTERFACE_DATA);
  retb := SetupDiEnumDeviceInterfaces (hardwareDeviceInfo,
                                             nil, // We don\'t care about specific PDOs
                                             InterfaceClassGuid,
                                             0,
                                             deviceInfoData);
  if GetLastError() = ERROR_NO_MORE_ITEMS then
  begin
    ShowMessage(\'SetupDiEnumDeviceInterfaces ERROR_NO_MORE_ITEMS \' + IntToHex(GetLastError(),4));
  end;

  if retb 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;

    devName := functionClassDeviceData.DevicePath ;
  end;
  ErrorCode := GetLastError();
end;
gehuadongqq
驱动牛犊
驱动牛犊
  • 注册日期2003-03-27
  • 最后登录2004-06-18
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-11-26 09:36
可是在retb := SetupDiEnumDeviceInterfaces (hardwareDeviceInfo这一步时,SetupDiEnumDeviceInterfaces总是返回false,我百思不得其解,不知道错在哪里。请各位高手大侠给些指点,帮我度过难关!先表示感谢!
游客

返回顶部