I try to determine in which IRQNumber a specific device is associated. Then, when I have the IRQNumber, I want to list all the devices which are on this IRQ to see if the specific device is the only one on this IRQ or if it shares it.
Thanks to the peripheral manager I know the name of the specific device and the IRQNumber associated, but I want to do the operation above in a C++ code.
I found the Win32_PnPAllocatedResource class, but I can't select the device in the query.
The query:
sprintf(szTemp, "SELECT * FROM Win32_PnPAllocatedResource Where Dependent LIKE '\\\\%ws\\root\\cimv2:Win32_PnPEntity.DeviceID=\"%s\"'", ComputerName, DriverIDm);
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t(szTemp),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator2);
if (FAILED(hres))
{
cout << "Query for Win32_PnPAllocatedResource name failed."
<< " Error code = 0x"
<< hex << hres << endl;
pSvc2->Release();
pLoc2->Release();
CoUninitialize();
//return 1; // Program has failed.
}
For the computer name and the deviceID picked up before:
IEnumWbemClassObject* pEnumerator = NULL;
IEnumWbemClassObject* pEnumerator2 = NULL;
char szTemp[1024];
char szTemp2[1024];
LPCTSTR DriverID;
//////////////////////////////////////////////////////////////////
//
// DeviceID
//
//////////////////////////////////////////////////////////////////
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_PnPEntity Where Name LIKE 'Name'"), //Name of the device find in the peripheral manager
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
cout << "Query for PnPEntity name failed."
<< " Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
//return 1; // Program has failed.
}
IWbemClassObject *pclsObj = NULL;
ULONG uReturn = 0;
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if (0 == uReturn)
{
sprintf_s(szTemp, "Device not found !");
MessageBoxA(NULL, szTemp, "Error", MB_ICONERROR);
}
VARIANT vtProp;
hr = pclsObj->Get(L"DeviceID", 0, &vtProp, 0, 0);
wcout << " DeviceID : " << vtProp.bstrVal << endl;
DriverID = vtProp.bstrVal;
int size = 0, cpt = 0, cpt2 = 0;
sprintf(szTemp2, "%ws", DriverID);
size = strlen(szTemp2);
char DriverIDm[1024];
for (cpt = 0; cpt < size + 1; cpt++)
{
if (cpt == size )
{
DriverIDm[cpt2] = '\0';
break;
}
if (szTemp2[cpt] == '\\')
{
DriverIDm[cpt2] = szTemp2[cpt];
cpt2++;
DriverIDm[cpt2] = szTemp2[cpt];
cpt2++;
}
else
{
DriverIDm[cpt2] = szTemp2[cpt];
cpt2++;
}
}
//////////////////////////////////////////////////////////////////
//
// Computer Name
//
//////////////////////////////////////////////////////////////////
LPCTSTR ComputerName;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_IRQResource"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
cout << "Query for IRQResource failed."
<< " Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
//return 1; // Program has failed.
}
hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if (0 == uReturn)
{
sprintf_s(szTemp, "Error query !");
MessageBoxA(NULL, szTemp, "Error", MB_ICONERROR);
}
hr = pclsObj->Get(L"CSName", 0, &vtProp, 0, 0);
wcout << " CSName : " << vtProp.bstrVal << endl;
ComputerName = vtProp.bstrVal;
The computer name and the DeviceID are picked up without any error.
Now the code where the error occurs:
IWbemClassObject *pclsObj2 = NULL;
ULONG uReturn2 = 0;
while (pEnumerator2)
{
HRESULT hr2 = pEnumerator2->Next(WBEM_INFINITE, 1,
&pclsObj2, &uReturn2);
DWORD nError2 = GetLastError();
if (0 == uReturn2)
{
sprintf_s(szTemp, "Device not found !");
MessageBoxA(NULL, szTemp, "Error", MB_ICONERROR);
break;
}
The value of hr2 is 0x80041017 (WBEM_E_INVALID_QUERY : Query was not syntactically valid.). The value returned by GetLastError() is 1008 (ERROR_NO_TOKEN : An attempt was made to reference a token that does not exist.). And Return2 = 0.
Where is the problem?
Is Win32_PnPAllocatedResource the right class to know on which IRQ is a specific device?
Thanks
User contributions licensed under CC BY-SA 3.0