Пример #1
0
        public unsafe void ITypeInfo_GetVarDesc_Invoke_Success()
        {
            using var image = new Bitmap(16, 32);
            IPictureDisp picture  = SubAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;
            ITypeInfo    typeInfo;
            HRESULT      hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo);

            Assert.Equal(HRESULT.S_OK, hr);

            VARDESC *pVarDesc = null;

            try
            {
                hr = typeInfo.GetVarDesc(3, &pVarDesc);
                Assert.Equal(HRESULT.S_OK, hr);
                Assert.Equal((DispatchID)4, pVarDesc->memid);
                Assert.Equal(IntPtr.Zero, pVarDesc->lpstrSchema);
                Assert.Equal(IntPtr.Zero, pVarDesc->unionMember);
                Assert.Equal(VARENUM.USERDEFINED, pVarDesc->elemdescVar.tdesc.vt);
                Assert.NotEqual(IntPtr.Zero, pVarDesc->elemdescVar.tdesc.union.lpadesc);
                Assert.Equal(IntPtr.Zero, pVarDesc->elemdescVar.paramdesc.pparamdescex);
                Assert.Equal(PARAMFLAG.NONE, pVarDesc->elemdescVar.paramdesc.wParamFlags);
                Assert.Equal(VARFLAGS.FREADONLY, pVarDesc->wVarFlags);
                Assert.Equal(VARKIND.DISPATCH, pVarDesc->varkind);
            }
            finally
            {
                typeInfo.ReleaseVarDesc(pVarDesc);
            }
        }
Пример #2
0
        private ParameterDesc CreateFieldDesc(uint index)
        {
            if (typeInfo == null)
            {
                throw new ObjectDisposedException(Name);
            }

            VARDESC *vardesc          = null;
            char **  stringArray      = stackalloc char *[1024];
            uint     numArgumentNames = 0;

            try
            {
                typeInfo.GetVarDesc(index, out vardesc);

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

                object value    = null;
                bool   hasValue = false;
                switch (vardesc->varkind)
                {
                case VARKIND.VAR_CONST:
                    IntPtr valueAddress = new IntPtr(vardesc->__union1.lpvarValue);
                    if (valueAddress == null)
                    {
                        throw new Exception("Value address is null");
                    }
                    value    = Marshal.GetObjectForNativeVariant(valueAddress);
                    hasValue = true;
                    break;

                case VARKIND.VAR_PERINSTANCE:
                    //offset = (int)vardesc->__union1.oInst;
                    break;

                default:
                    throw new Exception("Variable kind " + vardesc->varkind + " is not supported");
                }

                return(new ParameterDesc(vardesc->elemdescVar, new string(stringArray[0]), GetReferencedType, (VARFLAGS)vardesc->wVarFlags, hasValue, value));
            }
            finally
            {
                if (vardesc != null)
                {
                    typeInfo.ReleaseVarDesc(vardesc);
                }
                for (int j = 0; j < numArgumentNames; j++)
                {
                    NativeMethods.SysFreeString(stringArray[j]);
                }
            }
        }
Пример #3
0
 public void ReleaseVarDesc(VARDESC *pVarDesc)
 {
     ((delegate * unmanaged <ITypeInfo *, VARDESC *, void>)(lpVtbl[21]))((ITypeInfo *)Unsafe.AsPointer(ref this), pVarDesc);
 }
 public int AddVarDesc([NativeTypeName("UINT")] uint index, [NativeTypeName("VARDESC *")] VARDESC *pVarDesc)
 {
     return(((delegate * stdcall <ICreateTypeInfo2 *, uint, VARDESC *, int>)(lpVtbl[14]))((ICreateTypeInfo2 *)Unsafe.AsPointer(ref this), index, pVarDesc));
 }
Пример #5
0
 public HRESULT AddVarDesc(uint index, VARDESC *pVarDesc)
 {
     return(((delegate * unmanaged <ICreateTypeInfo *, uint, VARDESC *, int>)(lpVtbl[14]))((ICreateTypeInfo *)Unsafe.AsPointer(ref this), index, pVarDesc));
 }
Пример #6
0
 public void ReleaseVarDesc([NativeTypeName("VARDESC *")] VARDESC *pVarDesc)
 {
     ((delegate * stdcall <ITypeInfo *, VARDESC *, void>)(lpVtbl[21]))((ITypeInfo *)Unsafe.AsPointer(ref this), pVarDesc);
 }