Witam,
Mam problem z pobraniem adresów ip z bazy "wmi". Z tego co wyczytałem z dokumentacji w MSDN należy do pobraniu użyć SAFEARRAY, tylko że w internecie nie ma przykładów jak użyć tej funkcji. Typ danych zwracanych z bazy to VT_BSTR + VT_ARRAY.
Kod pobierający adresy ip z bazy powinien być w tym miejscu :
if ((vtProp.vt & VT_ARRAY))
wcout << "IPAddress : " << "Array types not supported (yet)" << endl;
Kawałek kodu :
...
if (!localconn)
{
hres = CoSetProxyBlanket(
pEnumerator, // Indicates the proxy to set
RPC_C_AUTHN_DEFAULT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_DEFAULT, // RPC_C_AUTHZ_xxx
COLE_DEFAULT_PRINCIPAL, // Server principal name
RPC_C_AUTHN_LEVEL_PKT_PRIVACY, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
userAcct, // client identity
EOAC_NONE // proxy capabilities
);
if (FAILED(hres))
{
cout << "Could not set proxy blanket on enumerator. Error code = 0x" << hex << hres << endl;
cout << _com_error(hres).ErrorMessage() << endl;
pEnumerator->Release();
pSvc->Release();
pLoc->Release();
CoUninitialize();
cout << "press enter to exit" << endl;
cin.get();
return 1; // Program has failed.
}
}
// Get the data from the WQL sentence
IWbemClassObject *pclsObj = NULL;
ULONG uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if(0 == uReturn || FAILED(hr))
break;
VARIANT vtProp;
hr = pclsObj->Get(L"IPAddress", 0, &vtProp, 0, 0);// String
if (!FAILED(hr))
{
if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
wcout << "IPAddress : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
else{
if ((vtProp.vt & VT_ARRAY))
wcout << "IPAddress : " << "Array types not supported (yet)" << endl;
else
wcout << "IPAddress : " << vtProp.bstrVal << endl;
}
}
VariantClear(&vtProp);
pclsObj->Release();
pclsObj=NULL;
}
// Cleanup
pSvc->Release();
pLoc->Release();
pEnumerator->Release();
if (pclsObj!=NULL)
pclsObj->Release();
CoUninitialize();
return 0; // Program successfully completed.
...