MC++ FAQ
Sunday 09 | 08 | 2002
_variant_t to System::Object
If you've got an instance of the _variant_t COM helper class, and want to create a reference to System::Object from it, a fairly simple way is to use the helper methods of the Marshal class.

Here's a short example function that does the conversion:

System::Object* VariantToObject(const VARIANT & v)
{
   using namespace System;
   using namespace System::Runtime::InteropServices;

   return Marshal::GetObjectForNativeVariant(IntPtr((void*)&v));
}

Notice that the function takes a reference to a VARIANT as an argument. This is just fine, as _variant_t defines an implicit conversion operator to VARIANT.

Posted by tomasr at September 08, 2002 11:27 PM
Comments
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?

Copyright(C) 2002, Tomas Restrepo, All rights reserved. Powered by Movable Type 2.63