Перечисление всех устройств в системе
Код поможет перечислить все имеющиеся устройства в системе. Поскольку функции из библиотеки Cfgmgr32.dll не объявлены в FB, пришлось их самому декларировать. И тут почему-то функция CM_Get_DevNode_Registry_Property не декларировалась как другие, хотя вроде как я это делал по всем правилам. Пришлось вызывать ее с помощью динамического подключения библиотеки...
Платформа: Windows
#INCLUDE "windows.bi" #INCLUDE "crt.bi" Dim Shared CM_Get_DevNode_Registry_Property As Function (_ dnDevInst As Integer,_ ulProperty As UINT,_ pulRegDataType As UINT Ptr,_ Buffer As Any Ptr,_ pulLength As UINT Ptr,_ ulFlags As UINT) As Integer Declare Function CM_Locate_DevNodeA Lib "Cfgmgr32.dll" Alias "CM_Locate_DevNodeA"(_ pdnDevInst As Integer Ptr,_ pDeviceID As Zstring Ptr,_ ulFlags As Ulong) As Integer Declare Function CM_Get_Child Lib "Cfgmgr32.dll" Alias "CM_Get_Child"(_ pdnDevInst As Integer Ptr,_ dnDevInst As Integer,_ ulFlags As Ulong) As Integer Declare Function CM_Get_Parent Lib "Cfgmgr32.dll" Alias "CM_Get_Parent"(_ pdnDevInst As Integer Ptr,_ dnDevInst As Integer,_ ulFlags As Ulong) As Integer Declare Function CM_Get_Sibling Lib "Cfgmgr32.dll" Alias "CM_Get_Sibling"(_ pdnDevInst As Integer Ptr,_ DevInst As Integer,_ ulFlags As Ulong) As Integer Dim As Any Pointer hLib hLib = Dylibload( "Cfgmgr32.dll" ) If hLib = null Then Print "Dylibload failed" Sleep End Endif CM_Get_DevNode_Registry_Property = Dylibsymbol( hLib, "CM_Get_DevNode_Registry_PropertyA" ) If CM_Get_DevNode_Registry_Property = null Then Print "Dylibsymbol(CM_Get_DevNode_Registry_Property) failed" Sleep Dylibfree( hLib ) End Endif Dim As ZString*512 buf Dim As Integer devInst Dim As Integer devInstNext Dim As Integer cr Dim As Ulong walkDone = 0 Dim As Ulong len_ cr = CM_Locate_DevNodeA(@devInst,_ NULL,_ 0) If cr <> 0 Then ? "Error CM_Locate_DevNodeA":Sleep:End Endif While walkDone = 0 ' len_ = Sizeof(buf) cr = CM_Get_DevNode_Registry_Property(devInst,_ &hA,_ NULL,_ @buf,_ @len_,_ 0) If cr = 0 Then len_ = Sizeof(buf) cr = CM_Get_DevNode_Registry_Property(devInst,_ &h1,_ NULL,_ @buf,_ @len_,_ 0) If cr = 0 Then printf(!"%s\n", buf) Else Sleep End Endif Endif cr = CM_Get_Child(@devInstNext,_ devInst,_ 0) If cr = 0 Then devInst = devInstNext Continue While Endif Do cr = CM_Get_Sibling(@devInstNext,_ devInst,_ 0) If cr = 0 Then devInst = devInstNext Exit Do Endif cr = CM_Get_Parent(@devInstNext,_ devInst,_ 0) If cr = 0 Then devInst = devInstNext Else walkDone = 1 Exit Do Endif Loop Wend Dylibfree( hLib ) Sleep