1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| #include "GUID_main.h"
#include "hid.hpp"
#include "winbase.h"
#include "dbt.h"
void __fastcall DevicessHID();
void __fastcall Capabilites();
//---------------------------------------------------------------
void __fastcall DevicessHID()
{
Form1->Mem1->Clear(); // effacer le memo
// Obtenir les information des dispositifs installé
hDevInfo = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
// Taille de la structur SetupDiEnumDeviceInterfaces
devInfoData.cbSize = sizeof(devInfoData);
// Obtenir le handle de la structur SP_DEVICE_INTERFACE_DATA du matériel installé
Result = SetupDiEnumDeviceInterfaces(hDevInfo, 0, &guid, MemberIndex, &devInfoData);
if (Result != 0)
{
// Active les bouton Capabilitées et donnée
BtnT->Enabled = true;
BtnCap->Enabled = true;
// Recherche des information détail de hDevInfo
Result = SetupDiGetDeviceInterfaceDetail(hDevInfo, &devInfoData, NULL, 0, &Length, NULL);
//Répartir la mémoire pour la structure hDevInfo
detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA) malloc(Length);
//Taile de la strucutre
detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
//Appeler la fonction SetupDiGetDeviceInterfaceDetail
Result = SetupDiGetDeviceInterfaceDetail(hDevInfo, &devInfoData, detailData, Length, &Required, NULL);
DeviceHandle = CreateFile(detailData->DevicePath,
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
(LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, 0, NULL);
// Fonction pour récupérer les Attributes
HidD_GetAttributes((unsigned)DeviceHandle, Attributes);
//Affichage des attributes (VID,PID et Version)
Mem1->Lines->Add(("Vendor ID : ")+("0x"+IntToHex(Attributes.VendorID,4))+
(" Porduit ID : ")+("0x"+IntToHex(Attributes.ProductID,4))+
(" Version : ")+((int)Attributes.VersionNumber));
// Récupération des strings fabricant, nom du produit ez numero de série
ManufacturerName = HidD_GetManufacturerString((unsigned)DeviceHandle, ManufacturerBuffer, 256);
ProductName = HidD_GetProductString((unsigned)DeviceHandle, ProductBuffer, 256);
SerieNum = HidD_GetSerialNumberString((unsigned)DeviceHandle, SerieBuffer, 256);
// Affichage du string fabricant
for (int i = 0; i<256 ; i++)
{
SendMessage(Mem1->Handle,WM_CHAR,(char)ManufacturerBuffer[i],0);
}
SendMessage(Mem1->Handle,WM_CHAR,'\n',0);
i=0;
// Affichage du string nom du produit
for (int i = 0; i<256 ; i++)
{
SendMessage(Mem1->Handle,WM_CHAR,(char)ProductBuffer[i],0);
}
SendMessage(Mem1->Handle,WM_CHAR,'\n',0);
// Affichage du string dumero de série
Mem1->Lines->Add(SerieBuffer[0]);
free(detailData); // libéré la mémoire detailData
}
else
{
ShowMessage("Pas de récupération des devices!");
CloseHandle(DeviceHandle);
}
} |