Question

I have C/C++ code issue wherein there's WMI query which retrieves instances of Win32_DiskDrive and gets its Size property. This property is retrieved as Variant type and then I have to convert it to UINT64 type which is failing.

If I print variant wchar value AS IS, it prints OK. But if I print any of UINT forms, it gives me some garbled value. This is in WinPE environment, not sure if it will affect anything.

Code snippet is:

VariantClear(&varPropVal);
hr = pInst->Get(L"Size", // property name
                0L,            // Reserved, must be zero.
                &varPropVal,   // property value returned.
                NULL,          // CIM type not needed.
                NULL);         // Flavor not needed.
if(hr == WBEM_S_NO_ERROR) 
{
    printf("Disk size: %S %llu %llu %u\n", V_BSTR(&varPropVal),
                                           V_UI4(&varPropVal),
                                           V_UI8(&varPropVal),
                                           V_UINT(&varPropVal));
    diskInfo->size = V_UI8(&varPropVal);
}

Output of the log statement: Disk size: 13440107520 4631112 4631112 4631112

Here first size printed as wchar* is correct one.

Anything I'm missing out here?

Was it helpful?

Solution

Setting locale (std::locale("")) at start of program solve the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top