コード例 #1
0
 public static object Invoke(this IDispatchEx dispatchEx, object[] args, bool asConstructor)
 {
     using (var argVariantArrayBlock = new CoTaskMemVariantArgsByRefBlock(args))
     {
         using (var resultVariantBlock = new CoTaskMemVariantBlock())
         {
             EXCEPINFO excepInfo;
             var       dispArgs = new DISPPARAMS {
                 cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 0, rgdispidNamedArgs = IntPtr.Zero
             };
             Marshal.ThrowExceptionForHR(dispatchEx.InvokeEx(SpecialDispIDs.Default, 0, asConstructor ? DispatchFlags.Construct : DispatchFlags.Method, ref dispArgs, resultVariantBlock.Addr, out excepInfo));
             return(Marshal.GetObjectForNativeVariant(resultVariantBlock.Addr));
         }
     }
 }
コード例 #2
0
        public static object GetProperty(this IDispatchEx dispatchEx, string name, bool ignoreCase, object[] args)
        {
            int dispid;

            Marshal.ThrowExceptionForHR(dispatchEx.GetDispID(name, ignoreCase ? DispatchNameFlags.CaseInsensitive : DispatchNameFlags.CaseSensitive, out dispid));

            using (var argVariantArrayBlock = new CoTaskMemVariantArgsBlock(args))
            {
                using (var resultVariantBlock = new CoTaskMemVariantBlock())
                {
                    EXCEPINFO excepInfo;
                    var       dispArgs = new DISPPARAMS {
                        cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 0, rgdispidNamedArgs = IntPtr.Zero
                    };
                    Marshal.ThrowExceptionForHR(dispatchEx.InvokeEx(dispid, 0, DispatchFlags.PropertyGet, ref dispArgs, resultVariantBlock.Addr, out excepInfo));
                    return(Marshal.GetObjectForNativeVariant(resultVariantBlock.Addr));
                }
            }
        }