Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <stdio.h>
- #include <windows.h>
- #include <Setupapi.h>
- #include <devguid.h>
- #include "conio.h"
- #include "tchar.h"
- //#include <devguid.h>
- DEFINE_GUID( GUID_DEVCLASS_USB,0x36FC9E60, 0xC465, 0x11CF, 0x80, 0x56, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 );
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- HDEVINFO deviceInfoSet;
- GUID *guidDev = (GUID*) &GUID_DEVCLASS_USB;
- deviceInfoSet = SetupDiGetClassDevs(guidDev, NULL, NULL, DIGCF_PRESENT | DIGCF_PROFILE);
- TCHAR buffer [4000];
- int memberIndex = 0;
- while (true)
- {
- SP_DEVINFO_DATA deviceInfoData;
- ZeroMemory(&deviceInfoData, sizeof(SP_DEVINFO_DATA));
- deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
- if (SetupDiEnumDeviceInfo(deviceInfoSet, memberIndex, &deviceInfoData) == FALSE)
- {
- if (GetLastError() == ERROR_NO_MORE_ITEMS)
- {
- break;
- }
- }
- DWORD nSize=0 ;
- SetupDiGetDeviceInstanceId (deviceInfoSet, &deviceInfoData, buffer, sizeof(buffer), &nSize);
- buffer [nSize] ='\0';
- _tprintf (_T("%s\n"), buffer);
- memberIndex++;
- //Label1->Caption=String(buffer);
- if (String(buffer).SubString(1,8)=="USB\\VID_")
- ShowMessage(String(buffer)); // AnsiString dsa; dsa=dsa.SubString(dsa.Pos("USB\\"),)
- }
- if (deviceInfoSet)
- {
- SetupDiDestroyDeviceInfoList(deviceInfoSet);
- }
- }
- //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement