Esempio n. 1
0
        public IEnumerator GetEnumerator()
        {
            Variant result;

            unsafe
            {
                void *     resultLocal = &result;
                DISPPARAMS dispParams  = new DISPPARAMS();
                Guid       guid        = Guid.Empty;
                Dispatch.Invoke(
                    DISPID_NEWENUM,
                    ref guid,
                    LCID_DEFAULT,
                    InvokeFlags.DISPATCH_METHOD | InvokeFlags.DISPATCH_PROPERTYGET,
                    ref dispParams,
                    new IntPtr(resultLocal),
                    IntPtr.Zero,
                    IntPtr.Zero);
            }

            object resultAsObject = result.ToObject();

            if (!(resultAsObject is IEnumVARIANT enumVariant))
            {
                throw new InvalidOperationException(SR.InvalidOp_InvalidNewEnumVariant);
            }

            return((IEnumerator)EnumeratorToEnumVariantMarshaler.GetInstance(null).MarshalNativeToManaged(Marshal.GetIUnknownForObject(enumVariant)));
        }
Esempio n. 2
0
 public static ICustomMarshaler GetInstance(string pstrCookie)
 {
     if (instance == null)
     {
         instance = new EnumeratorToEnumVariantMarshaler();
     }
     return(instance);
 }
Esempio n. 3
0
        public System.Collections.IEnumerator GetEnumerator()
        {
            Variant result;

            unsafe
            {
                void *     resultLocal = &result;
                DISPPARAMS dispParams  = default;
                Guid       guid        = Guid.Empty;
                Dispatch.Invoke(
                    DISPID_NEWENUM,
                    ref guid,
                    LCID_DEFAULT,
                    InvokeFlags.DISPATCH_METHOD | InvokeFlags.DISPATCH_PROPERTYGET,
                    ref dispParams,
                    new IntPtr(resultLocal),
                    IntPtr.Zero,
                    IntPtr.Zero
                    );
            }

            Debug.Assert(OperatingSystem.IsWindows());
            IntPtr enumVariantPtr = IntPtr.Zero;

            try
            {
                object?resultAsObject = result.ToObject();
                if (!(resultAsObject is IEnumVARIANT enumVariant))
                {
                    throw new InvalidOperationException(SR.InvalidOp_InvalidNewEnumVariant);
                }

                enumVariantPtr = Marshal.GetIUnknownForObject(enumVariant);
                return((System.Collections.IEnumerator)EnumeratorToEnumVariantMarshaler
                       .GetInstance(null)
                       .MarshalNativeToManaged(enumVariantPtr));
            }
            finally
            {
                result.Clear();

                if (enumVariantPtr != IntPtr.Zero)
                {
                    Marshal.Release(enumVariantPtr);
                }
            }
        }
		public static ICustomMarshaler GetInstance (string pstrCookie) {
			if (instance == null)
				instance = new EnumeratorToEnumVariantMarshaler ();
			return instance;
		}