VARIANT vtProp;
hr = pclsObj->Get(L"VendorSpecific", 0, &vtProp, 0, 0);// Uint8
long lUpper = 0;
long lLower = 0;
hr = SafeArrayGetUBound(V_ARRAY(&vtProp),1,&lUpper);
hr = SafeArrayGetLBound(V_ARRAY(&vtProp),1,&lLower);
long lNumOfElems = lUpper-lLower+5;
BYTE HUGEP *plongArray;
BYTE b;
hr=SafeArrayAccessData(V_ARRAY(&vtProp), (void**)&plongArray);
b = plongArray[0];
Reading uint Array properties inside WMI in Visual C++
-
20-06-2023 - |
سؤال
I am having trouble reading uint ARRAYS properties from WMI objects. I can read and process STRING properties from WMI objects.
This is what I have tried:
VARIANT vtProp;
hr = pclsObj->Get(L"VendorSpecific", 0, &vtProp, 0, 0);// Uint8
المحلول 2
نصائح أخرى
This is how you get the first element of the safe array.
SAFEARRAY* safearray = vtProp.parray;
CComBSTR str;
LONG i = 0;
SafeArrayGetElement(safearray, &i, &str);
UPDATE: A more general solution:
SAFEARRAY* safearray = vtProp.parray;
VARTYPE vType;
SafeArrayGetVartype(safearray, &vType);
long bound = safearray ->rgsabound[0].cElements;
for(long i = 0; i < bound; ++i)
{
VARIANT value;
SafeArrayGetElement(safearray, &i, &value);
switch(vType)
{
case VT_BSTR:
// use value.bstrVal
break;
case VT_UI8:
// use value.ullVal
break;
}
}
لا تنتمي إلى StackOverflow