I'm trying to use ExecQuery() from http://msdn.microsoft.com/en-us/library/aa392107%28v=vs.85%29.aspx in a program, but I'm having problems with errors. Specifically, if the WQL query is good, then everything works. The results are good, I can work with them. If, however, the query is bad like
"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPENab8f"
the HRESULT returned from ExecQuery is still a success. However accessing the enumerator will crash the program. The documentation indicates that there are return values that indicate different errors. The following do not catch it:
IEnumWbemClassObject * wmienumerator = NULL;
//
HRESULT hres;
hres = pWMI->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_Networkiguration WHERE IntderfaceIndex=4"),
WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
NULL,
&wmienumerator);
if(hres != WBEM_S_NO_ERROR)
{
cerr << "error";
exit(1);
}
else if(hres != 0)
{
cerr << "error";
exit(1);
}
else if(hres == WBEM_E_FAILED)
{
cerr << "error";
exit(1);
}
else if(FAILED(hres))
{
cerr << "error";
exit(1);
}
I've tried many other If statements, checking for different values, as well as checking if the enumerator pointer is still NULL (it's not).
At this point, I'm wondering if that is a valid query, and the results that are being returned are just empty. I don't know how to check if that is the case...
I feel like I'm missing something that is obvious to an experienced programmer, I'm fresh out of my freshman C++ class...