[Solved] About using 'setupapi.dll'
Posted: Mon Mar 07, 2022 1:20 pm
Hello!
I ran into a problem getting detailed device information. I took the AAT code as a basis and slightly modified it to fit my needs. I also looked at the code section of interest from another member of our forum (which has the function SetupDiGetDeviceInterfaceDetail working). I tried to combine them but failed. I left comments in the code so you can understand what I want to do.
I also saw other codes on this topic and everywhere the SetupDiGetDeviceInterfaceDetail function came after the enumeration of the interfaces. In this case it worked. But I also want to get the VID and PID of the device, which requires using the SetupDiGetDeviceRegistryProperty function. I was not able to combine these two codes together.
Does anyone have any ideas?
added:
I will also need 'devinst' for further action. To get it, you need to call the "CM_Locate_DevNodeW" function and to use this feature you must know the HARDWAREID. Everything is interconnected.
P.S. To be honest, I'm a bit confused.
P.S.2 Yes, you guessed it, I aimed for this:
PeekS(@*pdidd\DevicePath)
I ran into a problem getting detailed device information. I took the AAT code as a basis and slightly modified it to fit my needs. I also looked at the code section of interest from another member of our forum (which has the function SetupDiGetDeviceInterfaceDetail working). I tried to combine them but failed. I left comments in the code so you can understand what I want to do.
Code: Select all
Prototype SetupDiGetDeviceRegistryProperty(a, b, c, d, e, f, g)
Prototype SetupDiEnumDeviceInterfaces(a, b, c, d, e)
Prototype SetupDiGetDeviceInterfaceDetail(a, b, c, d, e, f)
Define setupapi
setupapi = OpenLibrary(#PB_Any, "setupapi.dll")
If setupapi
SetupDiGetDeviceRegistryProperty.SetupDiGetDeviceRegistryProperty = GetFunction(setupapi, "SetupDiGetDeviceRegistryPropertyW")
SetupDiEnumDeviceInterfaces.SetupDiEnumDeviceInterfaces = GetFunction(setupapi, "SetupDiEnumDeviceInterfaces")
SetupDiGetDeviceInterfaceDetail.SetupDiGetDeviceInterfaceDetail = GetFunction(setupapi, "SetupDiGetDeviceInterfaceDetailW")
Else
MessageRequester("Error", "Can't open library setupapi.dll")
End
EndIf
Structure SP_DEVICE_INTERFACE_DETAIL_DATA
cbSize.l
DevicePath.c[0]
EndStructure
Define hDevInfo
Define *pGUID = ?GUID_USB_DEVICE
hDevInfo = SetupDiGetClassDevs_(*pGUID, #Null, #Null, #DIGCF_PRESENT | #DIGCF_ALLCLASSES)
If hDevInfo = #INVALID_HANDLE_VALUE
MessageRequester("Error", "Inavlid handle value")
End
EndIf
#MAX_CLASS_NAME_LEN = 32
#MAX_DEV_NAME_LEN = 512
#SPDRP_HARDWAREID = 1
#SPDRP_SERVICE = 4
Define Index.i, cbRequired.l
Define.s DevName = Space(#MAX_DEV_NAME_LEN), DevClass = Space(#MAX_CLASS_NAME_LEN)
Define DeviceInfoData.SP_DEVICE_INTERFACE_DATA
DeviceInfoData\cbSize = SizeOf(SP_DEVICE_INTERFACE_DATA)
Define *pdidd.SP_DEVICE_INTERFACE_DETAIL_DATA
While SetupDiEnumDeviceInfo_(hDevInfo, Index, @DeviceInfoData)
SetupDiGetDeviceRegistryProperty(hDevInfo, @DeviceInfoData, #SPDRP_SERVICE, #Null, @DevClass, #MAX_CLASS_NAME_LEN, #Null)
If DevClass = "USBSTOR"
SetupDiGetDeviceRegistryProperty(hDevInfo, @DeviceInfoData, #SPDRP_HARDWAREID, #Null, @DevName, #MAX_DEV_NAME_LEN, #Null)
Debug "Device Name: " + DevName
;It looks like SetupDiGetDeviceInterfaceDetail should come after SetupDiEnumDeviceInterfaces.
;But I already have a SetupDiEnumDeviceInfo enum loop.
;How can I get the required size for the SP_DEVICE_INTERFACE DETAIL DATA structure, for getting more detail info about device ???
;I always get zero :(
cbRequired = 0
If SetupDiEnumDeviceInterfaces(hDevInfo, #Null, *pGUID, Index, @DeviceInfoData)
SetupDiGetDeviceInterfaceDetail(hDevInfo, @DeviceInfoData, #Null, #Null, @cbRequired, #Null)
Else
SetupDiGetDeviceInterfaceDetail(hDevInfo, @DeviceInfoData, #Null, #Null, @cbRequired, #Null)
EndIf
Debug "cbRequired = " + Str(cbRequired)
;Err = GetLastError_()
;If Err = #ERROR_INSUFFICIENT_BUFFER
;*pdidd = LocalAlloc_(#LPTR, cbRequired)
;*pdidd\cbSize=SizeOf(SP_DEVICE_INTERFACE_DETAIL_DATA)+SizeOf(character)
;If *pdidd
;some code
; LocalFree_(*pdidd)
; *pdidd=0
;EndIf
EndIf
Index + 1
Wend
SetupDiDestroyDeviceInfoList_(hDeviceInfoSet)
CloseLibrary(setupapi)
DataSection
GUID_USB_DEVICE:
Data.l $53f56307
Data.w $b6bf, $11d0
Data.b $94, $f2, $00, $a0, $c9, $1e, $fb, $8b
EndDataSection
Does anyone have any ideas?
added:
I will also need 'devinst' for further action. To get it, you need to call the "CM_Locate_DevNodeW" function and to use this feature you must know the HARDWAREID. Everything is interconnected.
P.S. To be honest, I'm a bit confused.
P.S.2 Yes, you guessed it, I aimed for this:
PeekS(@*pdidd\DevicePath)