How do I access a uint64 in a VARIANT structure?
Eg:
VARIANT vtProp{};
hres = pclsObj->Get(L"FreeSpaceInPagingFiles", 0, &vtProp, 0, 0);
strSystemInfo.AppendFormat(L" Free Space In Paging Files: %d\r\n", vtProp.iVal);
These are properties from the Win32_ComputerSystem class.
I don't understand why I get:
Total Virtual Memory Size: 1860884006920
Total Visible Memory Size: 1860884006920
with this code:
hres = pclsObj->Get(L"TotalVirtualMemorySize", 0, &vtProp, 0, 0);
strSystemInfo.AppendFormat(L" Total Virtual Memory Size: %lld\r\n", vtProp.ullVal);
VariantClear(&vtProp);
hres = pclsObj->Get(L"TotalVisibleMemorySize", 0, &vtProp, 0, 0);
strSystemInfo.AppendFormat(L" Total Visible Memory Size: %lld\r\n", vtProp.ullVal);
VariantClear(&vtProp);
But PowerShell:
Get-WmiObject -Class "Win32_operatingsystem" | Format-List *
Reports:
TotalVirtualMemorySize : 35567932
TotalVisibleMemorySize : 33470780
What am I doing wrong?
For example, for Win32_ComputerSystem.TotalPhysicalMemory the docs say:
TotalPhysicalMemoryData type:
uint64Access type: Read-only
Qualifiers: MappingStrings ("Win32API|Memory Management Structures|MEMORYSTATUS|dwTotalPhys"), Units ("bytes")
Total size of physical memory. Be aware that, under some circumstances, this property may not return an accurate value for the physical memory. For example, it is not accurate if the BIOS is using some of the physical memory. For an accurate value, use the Capacity property in
Win32_PhysicalMemoryinstead.Example: 67108864
For more information about using
uint64values in scripts, see Scripting in WMI.
To be honest, it doesn't matter which memory value properties I use as I struggle to interpret the VARIANT object data correctly.
I have part of the answer:
The value is correct in
bstrVal.So ,taking the
Capacity, I get:The values match PowerShell:
I have 2 banks, so the total is
34359738368. And this is similar toWin32_ComputerSystem.TotalPhysicalMemory->Installed RAM: 34274078720.The short answer is that I can use
bstrValto get the actual value that PowerShell displays. But how I turn thatbstrValinto a suitable GB value is another story.For the latter query: