Advertisement
Anton0093

Usb_id

Feb 18th, 2022
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <stdio.h>
  5. #include <windows.h>
  6. #include <Setupapi.h>
  7. #include <devguid.h>
  8. #include "conio.h"
  9. #include "tchar.h"
  10. //#include <devguid.h>
  11. DEFINE_GUID( GUID_DEVCLASS_USB,0x36FC9E60, 0xC465, 0x11CF, 0x80, 0x56, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 );
  12. #include "Unit1.h"
  13. //---------------------------------------------------------------------------
  14. #pragma package(smart_init)
  15. #pragma resource "*.dfm"
  16. TForm1 *Form1;
  17. //---------------------------------------------------------------------------
  18. __fastcall TForm1::TForm1(TComponent* Owner)
  19.         : TForm(Owner)
  20. {
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TForm1::Button1Click(TObject *Sender)
  24. {
  25. HDEVINFO deviceInfoSet;
  26. GUID *guidDev = (GUID*) &GUID_DEVCLASS_USB;
  27. deviceInfoSet = SetupDiGetClassDevs(guidDev, NULL, NULL, DIGCF_PRESENT | DIGCF_PROFILE);
  28. TCHAR buffer [4000];
  29. int memberIndex = 0;
  30. while (true)
  31.         {
  32.         SP_DEVINFO_DATA deviceInfoData;
  33.         ZeroMemory(&deviceInfoData, sizeof(SP_DEVINFO_DATA));
  34.         deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
  35.         if (SetupDiEnumDeviceInfo(deviceInfoSet, memberIndex, &deviceInfoData) == FALSE)
  36.                 {
  37.                 if (GetLastError() == ERROR_NO_MORE_ITEMS)
  38.                         {
  39.                         break;
  40.                         }
  41.                 }
  42.         DWORD nSize=0 ;
  43.         SetupDiGetDeviceInstanceId (deviceInfoSet, &deviceInfoData, buffer, sizeof(buffer), &nSize);
  44.         buffer [nSize] ='\0';
  45.         _tprintf (_T("%s\n"), buffer);
  46.         memberIndex++;
  47.         //Label1->Caption=String(buffer);
  48.         if (String(buffer).SubString(1,8)=="USB\\VID_")
  49.         ShowMessage(String(buffer));  // AnsiString dsa; dsa=dsa.SubString(dsa.Pos("USB\\"),)
  50.         }
  51. if (deviceInfoSet)
  52.         {
  53.         SetupDiDestroyDeviceInfoList(deviceInfoSet);
  54.         }
  55.        
  56. }
  57. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement