saumil patel saumil patel - 17 days ago 4
C# Question

Propvariant to variant C#

I am a newbie in this. I am trying to convert propvariant to variant in C#

I have a code like this.

public static object PropValueToVariant(PROPVARIANT Value)
{
object result;
DateTime stTime;
DateTime ftTime;
object __Null;
// Convert the prop variant to variant data type

switch(Value.vt)
{
//@ Undeclared identifier(3): 'VT_I1'
case VT_I1:
//@ Unsupported property or method(C): 'bVal'
result = Value.bVal;
break;
//@ Undeclared identifier(3): 'VT_UI1'
case VT_UI1:
//@ Unsupported property or method(C): 'bVal'
result = Value.bVal;
break;
//@ Undeclared identifier(3): 'VT_I2'
case VT_I2:
//@ Unsupported property or method(C): 'iVal'
result = Value.iVal;
break;
//@ Undeclared identifier(3): 'VT_UI2'
case VT_UI2:
//@ Unsupported property or method(C): 'uiVal'
result = Value.uiVal;
break;
//@ Undeclared identifier(3): 'VT_I4'
case VT_I4:
//@ Unsupported property or method(C): 'lVal'
result = Value.lVal;
break;
//@ Undeclared identifier(3): 'VT_UI4'
case VT_UI4:
//@ Unsupported property or method(C): 'ulVal'
result = ((int)Value.ulVal);
break;
//@ Undeclared identifier(3): 'VT_I8'
case VT_I8:
//@ Unsupported property or method(C): 'hVal'
//@ Unsupported property or method(D): 'LowPart'
result = ((int)Value.hVal.LowPart);
break;
//@ Undeclared identifier(3): 'VT_UI8'
case VT_UI8:
//@ Unsupported property or method(C): 'uhVal'
//@ Unsupported property or method(D): 'LowPart'
result = ((int)Value.uhVal.LowPart);
break;
//@ Undeclared identifier(3): 'VT_BOOL'
case VT_BOOL:
//@ Unsupported property or method(C): 'boolVal'
result = Value.boolVal;
break;
//@ Undeclared identifier(3): 'VT_R4'
case VT_R4:
//@ Unsupported property or method(C): 'fltVal'
result = Value.fltVal;
break;
//@ Undeclared identifier(3): 'VT_R8'
case VT_R8:
//@ Unsupported property or method(C): 'dblVal'
result = Value.dblVal;
break;
//@ Undeclared identifier(3): 'VT_CY'
case VT_CY:
//@ Unsupported property or method(C): 'cyVal'
result = Value.cyVal;
break;
//@ Undeclared identifier(3): 'VT_ERROR'
case VT_ERROR:
//@ Unsupported property or method(C): 'scode'
result = Value.scode;
break;
//@ Undeclared identifier(3): 'VT_DATE'
case VT_DATE:
//@ Unsupported property or method(C): 'date'
result = Value.date;
break;
//@ Undeclared identifier(3): 'VT_FILETIME'
case VT_FILETIME:
//@ Unsupported property or method(C): 'filetime'
//@ Unsupported function or procedure: 'FileTimeToLocalFileTime'
FileTimeToLocalFileTime(Value.filetime, ftTime);
//@ Undeclared identifier(3): 'FileTimeToSystemTime'
FileTimeToSystemTime(ftTime, stTime);
result = stTime;
break;
//@ Undeclared identifier(3): 'VT_CLSID'
case VT_CLSID:
//@ Unsupported property or method(C): 'puuid'
result = Value.puuid.ToString();
break;
//@ Undeclared identifier(3): 'VT_BSTR'
case VT_BSTR:
//@ Unsupported property or method(C): 'bstrVal'
result = Value.bstrVal;
break;
//@ Undeclared identifier(3): 'VT_LPSTR'
case VT_LPSTR:
//@ Unsupported property or method(C): 'pszVal'
result = (Value.pszVal as string);
break;
//@ Undeclared identifier(3): 'VT_LPWSTR'
case VT_LPWSTR:

result = WideCharToString(Value.pwszVal);
break;
default:
result = __Null;
break;
}
return result;
}


Why am I getting the Error for case names? also it doesnt understand ulval, lval, etc....

Thank you so much for help

Answer

you dont neet this function, here is the function already implemented in the .net framework: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getobjectfornativevariant.aspx

Comments