Does anyone know why the code in this (by mskuma) thread may not enumerate / display devices correctly in Windows XP ?
I'll duplicate it here with minor changes since I don't need a fingerprint. I'm just looking for certain equipment. This code does not enumerate all connected equipment and truncates the lines.

Code: Select all
; How to enumerate hardware devices by using SetupDi calls
; mskuma 26 June 2006
; adapted from http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q259695
; (Windows only)
#DIGCF_PRESENT = $00000002
#DIGCF_ALLCLASSES = $00000004
#SPDRP_DEVICEDESC = $00000000
Structure SP_DEVINFO_DATA
cbSize.l
ClassGuid.GUID
DevInst.l; // DEVINST handle
Reserved.l;
EndStructure
Procedure EnumHardwareDevices()
hDevInfo.l = 0
DeviceInfoData.SP_DEVINFO_DATA
i.l = 0
devicesList.s = ""
; Create a HDEVINFO with all present devices
hDevInfo = SetupDiGetClassDevs_(#Null,0, 0, #DIGCF_PRESENT | #DIGCF_ALLCLASSES)
If hDevInfo = #INVALID_HANDLE_VALUE
ProcedureReturn
EndIf
; Enumerate through all devices in Set
DeviceInfoData\cbSize = SizeOf(SP_DEVINFO_DATA)
While SetupDiEnumDeviceInfo_(hDevInfo, i, @DeviceInfoData)
DataT.l
*buffer = #Null
buffersize.l = 0
; Call function with null to begin with,
; then use the returned buffer size (doubled)
; to allocate the buffer. Keep calling until
; success Or an unknown failure.
;
; Double the returned buffersize to correct
; For underlying legacy CM functions that
; Return an incorrect buffersize value on
; DBCS/MBCS systems.
While Not SetupDiGetDeviceRegistryProperty_(hDevInfo,@DeviceInfoData,#SPDRP_DEVICEDESC,@DataT,*buffer,buffersize,@buffersize)
If (GetLastError_() = #ERROR_INSUFFICIENT_BUFFER)
; Allocate the buffer size, using twice the size to avoid problems on W2k MBCS systems per KB 888609
*buffer = AllocateMemory(buffersize*2)
Else
; Insert error handling here
Break
EndIf
Wend
Debug PeekS(*buffer)
devicesList + PeekS(*buffer) ; build a string for purposes of doing a hash later
If (*buffer)
FreeMemory(*buffer)
EndIf
i+1 ; increment to next device
Wend
; finish up
If ( GetLastError_() <> #NO_ERROR And GetLastError_() <> #ERROR_NO_MORE_ITEMS )
; Insert error handling here
ProcedureReturn
EndIf
; Cleanup
SetupDiDestroyDeviceInfoList_(hDevInfo)
EndProcedure
; testing
EnumHardwareDevices()
Thank you.