您好,我正在使用 Visual Studio C++ 2010,但我仍然不擅长它。我正在使用 wmi 查询,我想在计算结果之前使用 if 语句这里是代码
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_ComputerSystem"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
cout << "Query for CS failed."
<< " Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
// Get the data from the query
IWbemClassObject *pclsObj;
ULONG uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
break;
}
VARIANT vtProp;
// Get the value of the Name property
hr = pclsObj->Get(L"Manufacturer", 0, &vtProp, 0, 0);
if (vtProp.bstrVal == "test") //// HERE IS THE PROB HOW TO FIX HERE?I WANT TO SAY IF THE RESULT ="WHATEVER" THEN
wcout << "\Manufacturer : " << vtProp.bstrVal << endl; // or do stuff
VariantClear(&vtProp);
pclsObj->Release();
错误是:错误C2446:'==':没有从'const char *'到'BSTR'的转换我仍然是初学者,我不知道如何解决这个问题,请帮助!