Human Readable Variant Type


Author: Dave
Date: 06.18.14 - 8:38am



This is a quick post on how to convert a COM variant's type bit field to a human readable form. Seems like this would have been built in somewhere, but I couldnt find it.

std::string TypeAsString(VARTYPE vt){
  switch (vt){
		case VT_EMPTY: return "VT_EMPTY";
		case VT_NULL: return "VT_NULL";
		case VT_I2: return "VT_I2";
		case VT_I4: return "VT_I4";
		case VT_R4: return "VT_R4";
		case VT_R8: return "VT_R8";
		case VT_CY: return "VT_CY";
		case VT_DATE: return "VT_DATE";
		case VT_BSTR: return "VT_BSTR";
		case VT_DISPATCH: return "VT_DISPATCH";
		case VT_ERROR: return "VT_ERROR";
		case VT_BOOL: return "VT_BOOL";
		case VT_VARIANT: return "VT_VARIANT";
		case VT_DECIMAL: return "VT_DECIMAL";
		case VT_RECORD: return "VT_RECORD";
		case VT_UNKNOWN: return "VT_UNKNOWN";
		case VT_I1: return "VT_I1";
		case VT_UI1: return "VT_UI1";
		case VT_UI2: return "VT_UI2";
		case VT_UI4: return "VT_UI4";
		case VT_INT: return "VT_INT";
		case VT_UINT: return "VT_UINT";
		case VT_VOID: return "VT_VOID";
		case VT_HRESULT: return "VT_HRESULT";
		case VT_PTR: return "VT_PTR";
		case VT_SAFEARRAY: return "VT_SAFEARRAY";
		case VT_CARRAY: return "VT_CARRAY";
		case VT_USERDEFINED: return "VT_USERDEFINED";
		case VT_LPSTR: return "VT_LPSTR";
		case VT_LPWSTR: return "VT_LPWSTR";
		case VT_BLOB: return "VT_BLOB";
		case VT_STREAM: return "VT_STREAM";
		case VT_STORAGE: return "VT_STORAGE";
		case VT_STREAMED_OBJECT: return "VT_STREAMED_OBJECT";
		case VT_STORED_OBJECT: return "VT_STORED_OBJECT";
		case VT_BLOB_OBJECT: return "VT_BLOB_OBJECT";
		case VT_CF: return "VT_CF"; 
		case VT_CLSID: return "VT_CLSID";
		case VT_VECTOR: return "VT_VECTOR";
		case VT_ARRAY: return "VT_ARRAY";
		default: return "???";
  }
}

void __stdcall ShowVariantType(VARIANT *pVal)
{
#pragma EXPORT
	
	std::string retVal;

	char buf[20];
	sprintf(buf, "0x%x = ", pVal->vt);
	retVal = buf;
        VARTYPE vt = pVal->vt;

	if( V_ISARRAY(pVal) ){
		retVal += "VT_ARRAY ";
		vt &= ~VT_ARRAY; //remove the flag
	}

	if( V_ISBYREF(pVal) ){
		retVal += "VT_BYREF ";
		vt &= ~VT_BYREF;  
	}

	retVal += TypeAsString(vt);
	MessageBoxA(0,retVal.c_str(),"",0);

}





Comments: (0)

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 31 + 33 = ? followed by the letter: Z 



About Me
More Blogs
Main Site
Posts: (All)
2024 ( 3 )
2023 ( 9 )
2022 ( 4 )
2021 ( 2 )
2020 ( 4 )
2019 ( 5 )
2018 ( 6 )
2017 ( 6 )
2016 ( 22 )
2015 ( 15 )
2014 (25)
     Query Last 12 Mos
     Progid from Interface ID
     VB6 to C Array Examples
     Human Readable Variant Type
     ScriptBasic COM Integration
     CodeView Addin
     ScriptBasic - Part 2
     Script Env
     MSCOMCTL Win7 Error
     printf override
     History Combo
     Disable IE
     API Hooking in VB6
     Addin Hook Events
     FastBuild Addin
     VB6 MemoryWindow
     Link C Obj Files into VB6
     Vb6 Standard Dlls
     CStr for Pascal
     Lazarus Review
     asprintf for VS
     VB6 GlobalMultiUse
     Scintilla in VB6
     Dynamic Highlight
     WinVerifyTrust, CryptMsgGetParam VB6
2013 ( 4 )
2012 ( 10 )
2011 ( 7 )
2010 ( 11 )
2009 ( 3 )