Hello, i'm tring to make an I/O driver in c++ (Builder wtv).
First i want to get the DevicePath ...
The code:
HDEVINFO hinfo = SetupDiGetClassDevs(NULL,
0, // Enumerator
0,
DIGCF_PRESENT | DIGCF_ALLCLASSES ); // to take all devices
//=============================== GET GUID FOR MY USB MOUSE ======/
if (hinfo == INVALID_HANDLE_VALUE)
{
Memo1->Lines->Add("gresit");
}
int i;
SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
_GUID x; //this is the GUID i want to use above
for (i=0;SetupDiEnumDeviceInfo(hinfo,i,&DeviceInfoData );i++)
{
DWORD DataT;
char buffer[10000];
DWORD buffersize = 0;
while (!SetupDiGetDeviceRegistryProperty(
hinfo,
&DeviceInfoData,
SPDRP_DEVICEDESC,
&DataT,
(PBYTE)buffer,
buffersize,
&buffersize))
{
}
if(!strcmp(buffer,"HID-compliant mouse")) //this will give me the _GUID for my usb mouse
{
x=DeviceInfoData.ClassGuid;
//break;
}
}
//================================================== =========//
//===========TRY TO GET THE PATH=============================//
//somewhere must be the problem...
HDEVINFO info = SetupDiGetClassDevs(&x, NULL,NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
if (info == INVALID_HANDLE_VALUE)
{
Memo1->Lines->Add("gresit");
}
else
Memo1->Lines->Add("ok");
for (DWORD i=0; ; ++i)
{
SP_INTERFACE_DEVICE_DATA ifdata;
ifdata.cbSize = sizeof(ifdata);
if (!SetupDiEnumInterfaceDevice(info, NULL,
&x, i,&ifdata))
{
if (GetLastError() == ERROR_NO_MORE_ITEMS) // it allways stuck here
{
break; // no more interfaces
}
}
DWORD needed;
SetupDiGetInterfaceDeviceDetail(info, &ifdata, NULL, 0,
&needed, NULL);
PSP_INTERFACE_DEVICE_DETAIL_DATA detail =
(PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc(needed);
detail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
SetupDiGetInterfaceDeviceDetail(info, &ifdata, detail,
needed, NULL, NULL);
char name[MAX_PATH];//this will get the DevicePath
strncpy(name, detail->DevicePath, sizeof(name));
free((PVOID) detail);
}
//=================================================//
Please help me...
Thank you very much.
|