Example #1
0
        public unsafe void ITypeInfo_GetFuncDesc_Invoke_Success()
        {
            using var image = new Bitmap(16, 32);
            IPictureDisp picture  = MockAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;
            ITypeInfo    typeInfo;
            HRESULT      hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo);

            using var typeInfoReleaser = new ComRefReleaser(typeInfo);
            Assert.Equal(HRESULT.S_OK, hr);

            FUNCDESC *pFuncDesc = null;

            try
            {
                hr = typeInfo.GetFuncDesc(0, &pFuncDesc);
                Assert.Equal(HRESULT.S_OK, hr);
                Assert.Equal((DispatchID)6, pFuncDesc->memid);
                Assert.Equal(IntPtr.Zero, pFuncDesc->lprgscode);
                Assert.NotEqual(IntPtr.Zero, (IntPtr)pFuncDesc->lprgelemdescParam);
                Assert.Equal(FUNCKIND.DISPATCH, pFuncDesc->funckind);
                Assert.Equal(INVOKEKIND.FUNC, pFuncDesc->invkind);
                Assert.Equal(CALLCONV.STDCALL, pFuncDesc->callconv);
                Assert.Equal(10, pFuncDesc->cParams);
                Assert.Equal(0, pFuncDesc->cParamsOpt);
                Assert.Equal(0, pFuncDesc->oVft);
                Assert.Equal(0, pFuncDesc->cScodes);
                Assert.Equal(VARENUM.VOID, pFuncDesc->elemdescFunc.tdesc.vt);
                Assert.Equal(IntPtr.Zero, pFuncDesc->elemdescFunc.tdesc.union.lpadesc);
                Assert.Equal(IntPtr.Zero, pFuncDesc->elemdescFunc.paramdesc.pparamdescex);
                Assert.Equal(IntPtr.Zero, pFuncDesc->elemdescFunc.paramdesc.pparamdescex);
            }
            finally
            {
                typeInfo.ReleaseFuncDesc(pFuncDesc);
            }
        }
Example #2
0
 public void ReleaseFuncDesc(FUNCDESC *pFuncDesc)
 {
     ((delegate * unmanaged <ITypeInfo *, FUNCDESC *, void>)(lpVtbl[20]))((ITypeInfo *)Unsafe.AsPointer(ref this), pFuncDesc);
 }
 public int AddFuncDesc([NativeTypeName("UINT")] uint index, [NativeTypeName("FUNCDESC *")] FUNCDESC *pFuncDesc)
 {
     return(((delegate * stdcall <ICreateTypeInfo2 *, uint, FUNCDESC *, int>)(lpVtbl[9]))((ICreateTypeInfo2 *)Unsafe.AsPointer(ref this), index, pFuncDesc));
 }
Example #4
0
 public HRESULT AddFuncDesc(uint index, FUNCDESC *pFuncDesc)
 {
     return(((delegate * unmanaged <ICreateTypeInfo *, uint, FUNCDESC *, int>)(lpVtbl[9]))((ICreateTypeInfo *)Unsafe.AsPointer(ref this), index, pFuncDesc));
 }
 public void ReleaseFuncDesc([NativeTypeName("FUNCDESC *")] FUNCDESC *pFuncDesc)
 {
     ((delegate * stdcall <ITypeInfo *, FUNCDESC *, void>)(lpVtbl[20]))((ITypeInfo *)Unsafe.AsPointer(ref this), pFuncDesc);
 }
Example #6
0
        private MethodDesc CreateMethodDesc(uint index)
        {
            if (typeInfo == null)
            {
                throw new ObjectDisposedException(Name);
            }

            FUNCDESC *funcDesc         = null;
            char *    dllPtr           = null;
            char *    entryPointPtr    = null;
            char **   stringArray      = stackalloc char *[1024];
            uint      numArgumentNames = 0;

            try
            {
                typeInfo.GetFuncDesc(index, out funcDesc);

                string dll        = null;
                string entryPoint = null;
                if (typeAttr.typekind == TYPEKIND.TKIND_MODULE)
                {
                    ushort ordinal;
                    typeInfo.GetDllEntry(funcDesc->memid, INVOKEKIND.INVOKE_FUNC, out dllPtr, out entryPointPtr, out ordinal);
                    dll = new string(dllPtr);
                    if (entryPointPtr != null)
                    {
                        entryPoint = new string(entryPointPtr);
                    }
                    else
                    {
                        entryPoint = "#" + ordinal.ToString(CultureInfo.InvariantCulture);
                    }
                }

                typeInfo.GetNames(funcDesc->memid, stringArray, 1024, out numArgumentNames);

                List <string> argumentNames = new List <string>();
                for (uint j = 1; j < numArgumentNames; j++)
                {
                    argumentNames.Add(new string(stringArray[j]));
                }

                return(new MethodDesc(new string(stringArray[0]), dll, entryPoint, *funcDesc, argumentNames.ToArray(), GetReferencedType));
            }
            finally
            {
                if (funcDesc != null)
                {
                    typeInfo.ReleaseFuncDesc(funcDesc);
                }
                if (dllPtr != null)
                {
                    NativeMethods.SysFreeString(dllPtr);
                }
                if (entryPointPtr != null)
                {
                    NativeMethods.SysFreeString(entryPointPtr);
                }
                for (int j = 0; j < numArgumentNames; j++)
                {
                    NativeMethods.SysFreeString(stringArray[j]);
                }
            }
        }