Click here to Skip to main content
15,888,057 members
Please Sign up or sign in to vote.
4.67/5 (2 votes)
See more:
I have a WMI class and im reading fine, I have a couple of small functins that read properties. Obviously each will have a different property type.

My question is what would you use to read the uint64?

For Strings:
C++
void WMIReader::ReadPropertyString( WCHAR* PropertyName, char* ReturnBuffer )
{
	VARIANT pProperty;
	ClassObject->Get( PropertyName, 0, &pProperty, 0, 0 );
	sprintf( ReturnBuffer, "%S", pProperty.bstrVal ); //bstrVal for strings
	VariantClear( &pProperty );
}


For Integers:
C++
void WMIReader::ReadPropertyInt( WCHAR* PropertyName, char* ReturnBuffer )
{
	VARIANT pProperty;
	ClassObject->Get( PropertyName, 0, &pProperty, 0, 0 );
	sprintf( ReturnBuffer, "%i", pProperty.intVal ); //intVal for integers
	VariantClear( &pProperty );
}


For UINT64:
C++
void WMIReader::ReadPropertyInt( WCHAR* PropertyName, char* ReturnBuffer )
{
    VARIANT pProperty;
    ClassObject->Get( PropertyName, 0, &pProperty, 0, 0 );
    sprintf( ReturnBuffer, "%i", pProperty.???? ); //What for uint64?
    VariantClear( &pProperty );
}


Thanks
Posted

Ok turns out you would use the string to read a uint64 value. I ran wbemtest, queried my hard disk found the size value if you then edit the property it tells you the qualifier is "CIMTYPE CIM_STRING uint64".

I put this to the test and queried the size using the string reader and got:

Hard Disk: [C:\] - Size: [1000202039296]

Which matches what windows shows me as 1,000,202,039,296 bytes. Divide that by 1024 to get 976759804 KB. Divide that by 1024 to get 953866 MB. Divide that by 1024 to get 931 GB.

So for others wanting to read a uint64 use the bStrVal (String).
 
Share this answer
 
Aah, you need a reference to the documentation.

Here you go http://msdn.microsoft.com/en-us/library/ms221627(v=vs.85)[^]

Alan.
 
Share this answer
 
Hi there, looking at VARIANT structure[^] my guess would be ullVal

I.e sizeof(unsigned long long) = 8 (win7 32bit app)
 
Share this answer
 
Maybe i've done something wrong but i've done the following:

Read UINT64:
C++
void WMIReader::ReadPropertyUINT64( WCHAR* PropertyName, char* ReturnBuffer )
{
	VARIANT pProperty;
	ClassObject->Get( PropertyName, 0, &pProperty, 0, 0 );
	sprintf( ReturnBuffer, "%ld", pProperty.ulVal );
	VariantClear( &pProperty );
}


Query Logical Disk Class
C++
if( Reader->GetFirstDevice( L"Win32_LogicalDisk" ) )
{
	Reader->ReadPropertyUINT64( L"Size", pBuffer );
	strcpy( FoundDrive->FreeSpace, pBuffer );
}


Print out the Result
C++
Tools.AppendWindowText( pThis->m_StatusWindow, "Hard Disk: [%s\\] - Size: [%s]", CurrentDrive->DriveLetter, CurrentDrive->FreeSpace );


What i get is the following:
Hard Disk: [C:\] - Size: [4157124]

My Drive is:
Used: 138,660,515,840 bytes - 129gb
Free: 861,541,523,456 bytes - 802gb
Total: 1,000,202,039,296 bytes - 931gb
 
Share this answer
 
Comments
enhzflep 14-May-12 9:36am    
You've just asked for a (4 byte) unsigned long. Notice, you've only used 1 l - pProperty.ulVal (unsigned long)

you need 2 l's: pProperty.ullVal (unsigned long long)
My answer for UINT64 is: uVal

UINT64 means unsigned int** secPoint (i.e. point to *point)
that is (2 ^ 2)(4, unsigned int) * (2 ^ 6) 64KB = 2 ^ 8
So it is uVal.

void WMIReader::ReadPropertyInt( WCHAR* PropertyName, char* ReturnBuffer )
{
... ...
sprintf( ReturnBuffer, "%i", pProperty.???? ); //What for uint64?
VariantClear( &pProperty );
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900