Ejemplo n.º 1
0
        /// <summary>
        /// Release any unmanaged memory associated with the Variant
        /// </summary>
        /// <returns></returns>
        public void Clear()
        {
            // We do not need to call OLE32's VariantClear for primitive types or ByRefs
            // to safe ourselves the cost of interop transition.
            // ByRef indicates the memory is not owned by the VARIANT itself while
            // primitive types do not have any resources to free up.
            // Hence, only safearrays, BSTRs, interfaces and user types are
            // handled differently.
            VarEnum vt = VariantType;

            if ((vt & VarEnum.VT_BYREF) != 0)
            {
                VariantType = VarEnum.VT_EMPTY;
            }
            else if (
                ((vt & VarEnum.VT_ARRAY) != 0) ||
                ((vt) == VarEnum.VT_BSTR) ||
                ((vt) == VarEnum.VT_UNKNOWN) ||
                ((vt) == VarEnum.VT_DISPATCH) ||
                ((vt) == VarEnum.VT_RECORD)
                )
            {
                IntPtr variantPtr = UnsafeMethods.ConvertVariantByrefToPtr(ref this);
                UnsafeNativeMethods.VariantClear(variantPtr);
                Debug.Assert(IsEmpty);
            }
            else
            {
                VariantType = VarEnum.VT_EMPTY;
            }
        }
Ejemplo n.º 2
0
        public static Variant GetVariantForObject(object obj)
        {
            Variant variant = default(Variant);

            System.Runtime.InteropServices.Marshal.GetNativeVariantForObject(obj, UnsafeMethods.ConvertVariantByrefToPtr(ref variant));
            return(variant);
        }
Ejemplo n.º 3
0
 public void SetAsByrefVariant(ref Variant value)
 {
     Debug.Assert(IsEmpty); // The setter can only be called once as VariantClear might be needed otherwise
     VariantType = (VarEnum.VT_VARIANT | VarEnum.VT_BYREF);
     _typeUnion._unionTypes._byref = UnsafeMethods.ConvertVariantByrefToPtr(ref value);
 }
Ejemplo n.º 4
0
        public static object GetObjectForVariant(Variant variant)
        {
            IntPtr ptr = UnsafeMethods.ConvertVariantByrefToPtr(ref variant);

            return(System.Runtime.InteropServices.Marshal.GetObjectForNativeVariant(ptr));
        }