阅读:1327回复:1
用delphi开发usb应用程序疑难!
我用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; |
|
沙发#
发布于:2003-11-26 09:36
可是在retb := SetupDiEnumDeviceInterfaces (hardwareDeviceInfo这一步时,SetupDiEnumDeviceInterfaces总是返回false,我百思不得其解,不知道错在哪里。请各位高手大侠给些指点,帮我度过难关!先表示感谢!
|
|