Example #1
0
 public void AddressOfMember(int memid, ComTypes.INVOKEKIND invKind, out IntPtr ppv)
 {
     throw new NotImplementedException();
 }
Example #2
0
        unsafe void NativeMethods.IDispatch.Invoke(
            int dispid,
            ref Guid riid,
            int lcid,
            ComTypes.INVOKEKIND wFlags,
            ref ComTypes.DISPPARAMS pDispParams,
            IntPtr pvarResult,
            IntPtr pExcepInfo,
            IntPtr puArgErr)
        {
            ComEventsMethod method = FindMethod(dispid);

            if (method == null)
            {
                return;
            }

            // notice the unsafe pointers we are using. This is to avoid unnecessary
            // arguments marshalling. see code:ComEventsHelper#ComEventsArgsMarshalling

            object [] args      = new object[pDispParams.cArgs];
            int []    byrefsMap = new int[pDispParams.cArgs];
            bool []   usedArgs  = new bool[pDispParams.cArgs];

            Variant *pvars      = (Variant *)pDispParams.rgvarg;
            int *    pNamedArgs = (int *)pDispParams.rgdispidNamedArgs;

            // copy the named args (positional) as specified
            int i;
            int pos;

            for (i = 0; i < pDispParams.cNamedArgs; i++)
            {
                pos = pNamedArgs[i];

                Variant *pvar = GetVariant(&pvars[i]);
                args[pos]     = pvar->ToObject();
                usedArgs[pos] = true;

                if (pvar->IsByRef)
                {
                    byrefsMap[pos] = i;
                }
                else
                {
                    byrefsMap[pos] = -1;
                }
            }

            // copy the rest of the arguments in the reverse order
            pos = 0;
            for (; i < pDispParams.cArgs; i++)
            {
                // find the next unassigned argument
                while (usedArgs[pos])
                {
                    ++pos;
                }

                Variant *pvar = GetVariant(&pvars[pDispParams.cArgs - 1 - i]);
                args[pos] = pvar->ToObject();

                if (pvar->IsByRef)
                {
                    byrefsMap[pos] = pDispParams.cArgs - 1 - i;
                }
                else
                {
                    byrefsMap[pos] = -1;
                }

                pos++;
            }

            // Do the actual delegate invocation
            object result;

            result = method.Invoke(args);

            // convert result to VARIANT
            if (pvarResult != IntPtr.Zero)
            {
                Marshal.GetNativeVariantForObject(result, pvarResult);
            }

            // Now we need to marshal all the byrefs back
            for (i = 0; i < pDispParams.cArgs; i++)
            {
                int idxToPos = byrefsMap[i];
                if (idxToPos == -1)
                {
                    continue;
                }

                GetVariant(&pvars[idxToPos])->CopyFromIndirect(args[i]);
            }
        }
Example #3
0
 public void GetDllEntry(int memid, ComTypes.INVOKEKIND invKind, IntPtr pBstrDllName, IntPtr pBstrName, IntPtr pwOrdinal)
 {
     throw new NotImplementedException();
 }