COM Variants?

  • Thread starter Thread starter glenn
  • Start date Start date
G

glenn

I have a COM object that passes back a varient which actually contains a
string that I need to cast in my C# app back as a string. I have read that
C# does not support varient types and that I should use an object instead
but I don't know how to convert my object to a string either and I'm getting
errors in my COM call trying to set the result to an object as well.

How do you do this in C#?

Thanks,

glenn
 
glenn said:
I have a COM object that passes back a varient which actually contains a
string that I need to cast in my C# app back as a string. I have read
that
C# does not support varient types and that I should use an object instead
but I don't know how to convert my object to a string either and I'm
getting
errors in my COM call trying to set the result to an object as well.

How do you do this in C#?

Thanks,

glenn

VARIANTs are marshaled as Object, A VARIANT that contains a BSTR is
marshaled as an Object of type string.

string s = (string) CallComMethodThatReturnsAStringVariant();

Willy.
 
Back
Top