Esempio n. 1
0
        void ComTypes.ITypeLib.GetDocumentation(int memid, out string strName, out string strDocString, out int dwHelpContext, out string strHelpFile)
        {
            // initialize out parameters
            strName       = default;
            strDocString  = default;
            dwHelpContext = default;
            strHelpFile   = default;

            using (var _name = AddressableVariables.CreateBSTR())
                using (var _docString = AddressableVariables.CreateBSTR())
                    using (var _helpContext = AddressableVariables.Create <int>())
                        using (var _Helpfile = AddressableVariables.CreateBSTR())
                        {
                            int hr = _this_Internal.GetDocumentation(memid, _name.Address, _docString.Address, _helpContext.Address, _Helpfile.Address);
                            if (ComHelper.HRESULT_FAILED(hr))
                            {
                                HandleBadHRESULT(hr);
                            }

                            strName       = _name.Value;
                            strDocString  = _docString.Value;
                            dwHelpContext = _helpContext.Value;
                            strHelpFile   = _Helpfile.Value;
                        }
        }
Esempio n. 2
0
        bool ComTypes.ITypeLib.IsName(string szNameBuf, int lHashVal)
        {
            using (var _pfName = AddressableVariables.Create <int>())
            {
                var hr = _this_Internal.IsName(szNameBuf, lHashVal, _pfName.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }

                return(_pfName.Value != 0);
            }
        }
Esempio n. 3
0
        void ComTypes.ITypeLib.GetLibAttr(out IntPtr ppTLibAttr)
        {
            // initialize out parameters
            ppTLibAttr = default;

            using (var typeLibAttrPtr = AddressableVariables.CreatePtrTo <ComTypes.TYPELIBATTR>())
            {
                var hr = _this_Internal.GetLibAttr(typeLibAttrPtr.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }
                ppTLibAttr = typeLibAttrPtr.Value.Address;
            }
        }
Esempio n. 4
0
        void ComTypes.ITypeLib.GetTypeComp(out ComTypes.ITypeComp ppTComp)
        {
            // initialize out parameters
            ppTComp = default;

            using (var typeCompPtr = AddressableVariables.CreateObjectPtr <ComTypes.ITypeComp>())
            {
                var hr = _this_Internal.GetTypeComp(typeCompPtr.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }
                ppTComp = typeCompPtr.Value;
            }
        }
Esempio n. 5
0
        void ComTypes.ITypeInfo.AddressOfMember(int memid, ComTypes.INVOKEKIND invKind, out IntPtr ppv)
        {
            // initialize out parameters
            ppv = default;

            using (var outPpv = AddressableVariables.Create <IntPtr>())
            {
                var hr = _this_Internal.AddressOfMember(memid, invKind, outPpv.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }
                ppv = outPpv.Value;
            }
        }
Esempio n. 6
0
        void ComTypes.ITypeInfo.GetRefTypeInfo(int hRef, out ComTypes.ITypeInfo ppTI)
        {
            // initialize out parameters
            ppTI = default;

            using (var typeInfoPtr = AddressableVariables.CreateObjectPtr <ComTypes.ITypeInfo>())
            {
                var hr = _this_Internal.GetRefTypeInfo(hRef, typeInfoPtr.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }
                ppTI = typeInfoPtr.Value;
            }
        }
Esempio n. 7
0
        void ComTypes.ITypeInfo.GetRefTypeOfImplType(int index, out int href)
        {
            // initialize out parameters
            href = default;

            using (var outHref = AddressableVariables.Create <int>())
            {
                var hr = _this_Internal.GetRefTypeOfImplType(index, outHref.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }
                href = outHref.Value;
            }
        }
Esempio n. 8
0
        void ComTypes.ITypeLib.GetTypeInfoType(int index, out ComTypes.TYPEKIND pTKind)
        {
            // initialize out parameters
            pTKind = default;

            using (var typeKindPtr = AddressableVariables.Create <ComTypes.TYPEKIND>())
            {
                var hr = _this_Internal.GetTypeInfoType(index, typeKindPtr.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }
                pTKind = typeKindPtr.Value;
            }
        }
Esempio n. 9
0
        void ComTypes.ITypeInfo.GetVarDesc(int index, out IntPtr ppVarDesc)
        {
            // initialize out parameters
            ppVarDesc = default;

            using (var varDescPtr = AddressableVariables.CreatePtrTo <ComTypes.VARDESC>())
            {
                var hr = _this_Internal.GetVarDesc(index, varDescPtr.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }
                ppVarDesc = varDescPtr.Value.Address;          // dereference the ptr, and take the contents address
            }
        }
Esempio n. 10
0
        void ComTypes.ITypeLib.GetTypeInfoOfGuid(ref Guid guid, out ComTypes.ITypeInfo ppTInfo)
        {
            // initialize out parameters
            ppTInfo = default;

            using (var typeInfoPtr = AddressableVariables.CreateObjectPtr <ComTypes.ITypeInfo>())
            {
                var hr = _this_Internal.GetTypeInfoOfGuid(guid, typeInfoPtr.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }
                ppTInfo = typeInfoPtr.Value;
            }
        }
Esempio n. 11
0
        void ComTypes.ITypeInfo.GetTypeAttr(out IntPtr ppTypeAttr)
        {
            // initialize out parameters
            ppTypeAttr = default;

            using (var typeAttrPtr = AddressableVariables.CreatePtrTo <ComTypes.TYPEATTR>())
            {
                var hr = _this_Internal.GetTypeAttr(typeAttrPtr.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }

                ppTypeAttr = typeAttrPtr.Value.Address;        // dereference the ptr, and take the contents address
            }
        }
Esempio n. 12
0
 void ComTypes.ITypeInfo.GetIDsOfNames(string[] rgszNames, int cNames, int[] pMemId)
 {
     // We can't use the managed arrays as passed in.  We create our own unmanaged arrays,
     // and copy them into the managed ones on completion
     using (var names = AddressableVariables.CreateBSTR(cNames))
         using (var memberIds = AddressableVariables.Create <int>(cNames))
         {
             var hr = _this_Internal.GetIDsOfNames(names.Address, cNames, memberIds.Address);
             if (ComHelper.HRESULT_FAILED(hr))
             {
                 HandleBadHRESULT(hr);
             }
             names.CopyArrayTo(rgszNames);
             memberIds.CopyArrayTo(pMemId);
         }
 }
Esempio n. 13
0
        void ComTypes.ITypeInfo.GetImplTypeFlags(int index, out ComTypes.IMPLTYPEFLAGS pImplTypeFlags)
        {
            // initialize out parameters
            pImplTypeFlags = default;

            using (var implTypeFlags = AddressableVariables.Create <ComTypes.IMPLTYPEFLAGS>())
            {
                var hr = _this_Internal.GetImplTypeFlags(index, implTypeFlags.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }

                pImplTypeFlags = implTypeFlags.Value;
            }
        }
Esempio n. 14
0
        void ComTypes.ITypeInfo.GetMops(int memid, out string pBstrMops)
        {
            // initialize out parameters
            pBstrMops = default;

            using (var strMops = AddressableVariables.CreateBSTR())
            {
                var hr = _this_Internal.GetMops(memid, strMops.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }

                pBstrMops = strMops.Value;
            }
        }
Esempio n. 15
0
        void ComTypes.ITypeInfo.GetNames(int memid, string[] rgBstrNames, int cMaxNames, out int pcNames)
        {
            // initialize out parameters
            pcNames = default;

            using (var names = AddressableVariables.CreateBSTR(cMaxNames))
                using (var namesCount = AddressableVariables.Create <int>())
                {
                    var hr = _this_Internal.GetNames(memid, names.Address, cMaxNames, namesCount.Address);
                    if (ComHelper.HRESULT_FAILED(hr))
                    {
                        HandleBadHRESULT(hr);
                    }
                    names.CopyArrayTo(rgBstrNames);
                    pcNames = namesCount.Value;
                }
        }
Esempio n. 16
0
        void ComTypes.ITypeInfo.CreateInstance(object pUnkOuter, ref Guid riid, out object ppvObj)
        {
            // initialize out parameters
            ppvObj = default;

            using (var outPpvObj = AddressableVariables.CreateObjectPtr <object>())
            {
                var unkOuter = RdMarshal.GetIUnknownForObject(pUnkOuter);
                var hr       = _this_Internal.CreateInstance(unkOuter, riid, outPpvObj.Address);
                RdMarshal.Release(unkOuter);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }

                ppvObj = outPpvObj.Value;
            }
        }
Esempio n. 17
0
        void ComTypes.ITypeLib.FindName(string szNameBuf, int lHashVal, ComTypes.ITypeInfo[] ppTInfo, int[] rgMemId, ref short pcFound)
        {
            // We can't use the managed arrays as passed in.  We create our own unmanaged arrays,
            // and copy them into the managed ones on completion
            using (var _ppTInfo = AddressableVariables.CreateObjectPtr <ComTypes.ITypeInfo>(pcFound))
                using (var _MemIds = AddressableVariables.Create <int>(pcFound))
                    using (var _pcFound = AddressableVariables.Create <short>())
                    {
                        var hr = _this_Internal.FindName(szNameBuf, lHashVal, _ppTInfo.Address, _MemIds.Address, _pcFound.Address);
                        if (ComHelper.HRESULT_FAILED(hr))
                        {
                            HandleBadHRESULT(hr);
                        }

                        _ppTInfo.CopyArrayTo(ppTInfo);
                        _MemIds.CopyArrayTo(rgMemId);
                        pcFound = _pcFound.Value;
                    }
        }
Esempio n. 18
0
        void ComTypes.ITypeInfo.GetContainingTypeLib(out ComTypes.ITypeLib ppTLB, out int pIndex)
        {
            // initialize out parameters
            ppTLB  = default;
            pIndex = default;

            using (var typeLibPtr = AddressableVariables.CreateObjectPtr <ComTypes.ITypeLib>())
                using (var indexPtr = AddressableVariables.Create <int>())
                {
                    var hr = _this_Internal.GetContainingTypeLib(typeLibPtr.Address, indexPtr.Address);
                    if (ComHelper.HRESULT_FAILED(hr))
                    {
                        HandleBadHRESULT(hr);
                    }

                    ppTLB  = typeLibPtr.Value;
                    pIndex = indexPtr.Value;
                }
        }
Esempio n. 19
0
        public override int GetFuncDesc(int index, IntPtr ppFuncDesc)
        {
            var hr = _target_ITypeInfo.GetFuncDesc(index, ppFuncDesc);

            if (ComHelper.HRESULT_FAILED(hr))
            {
                return(HandleBadHRESULT(hr));
            }

            if (_target_ITypeInfoAlternate != null)
            {
                var pFuncDesc = StructHelper.ReadStructureUnsafe <IntPtr>(ppFuncDesc);
                var funcDesc  = StructHelper.ReadStructureUnsafe <ComTypes.FUNCDESC>(pFuncDesc);

                // Populate wFuncFlags from the alternative typeinfo provided by VBA
                // The alternative typeinfo is not as useful as the main typeinfo for most things, but does expose wFuncFlags
                // The list of functions appears to be in the same order as the main typeinfo.
                using (var funcDescAlternatePtr = AddressableVariables.CreatePtrTo <ComTypes.FUNCDESC>())
                {
                    var hr2 = _target_ITypeInfoAlternate.GetFuncDesc(index, funcDescAlternatePtr.Address);
                    if (!ComHelper.HRESULT_FAILED(hr2))
                    {
                        var funcDescAlternate = funcDescAlternatePtr.Value.Value;    // dereference the ptr, then the content

                        //sanity check
                        if (funcDescAlternate.memid == funcDesc.memid)
                        {
                            funcDesc.wFuncFlags = funcDescAlternate.wFuncFlags;
                        }
                        else
                        {
                            Debug.Assert(false, $"The sanity check failed; {nameof(funcDesc.memid)}: {funcDesc.memid} and {nameof(funcDescAlternate.memid)}: {funcDescAlternate.memid}");
                        }
                        _target_ITypeInfoAlternate.ReleaseFuncDesc(funcDescAlternatePtr.Value.Address);

                        RdMarshal.StructureToPtr(funcDesc, pFuncDesc, true);
                    }
                }
            }

            return(hr);
        }
Esempio n. 20
0
        public int GetSafeRefTypeInfo(int hRef, out ITypeInfoWrapper outTI)
        {
            outTI = null;

            using (var typeInfoPtr = AddressableVariables.Create <IntPtr>())
            {
                var hr = _target_ITypeInfo.GetRefTypeInfo(hRef, typeInfoPtr.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    return(HandleBadHRESULT(hr));
                }

                var outVal = TypeApiFactory.GetTypeInfoWrapper(typeInfoPtr.Value, IsUserFormBaseClass ? (int?)hRef : null); // takes ownership of the COM reference
                _cachedReferencedTypeInfos = _cachedReferencedTypeInfos ?? new DisposableList <ITypeInfoWrapper>();
                _cachedReferencedTypeInfos.Add(outVal);
                outTI = outVal;

                return(hr);
            }
        }
Esempio n. 21
0
        public int GetSafeTypeInfoByIndex(int index, out ITypeInfoWrapper outTI)
        {
            outTI = null;

            using (var typeInfoPtr = AddressableVariables.Create <IntPtr>())
            {
                var hr = _target_ITypeLib.GetTypeInfo(index, typeInfoPtr.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    return(HandleBadHRESULT(hr));
                }

                var outVal = TypeApiFactory.GetTypeInfoWrapper(typeInfoPtr.Value);
                _cachedTypeInfos = _cachedTypeInfos ?? new DisposableList <ITypeInfoWrapper>();
                _cachedTypeInfos.Add(outVal);
                outTI = outVal;

                return(hr);
            }
        }
Esempio n. 22
0
        private void InitCommon()
        {
            using (var typeAttrPtr = AddressableVariables.CreatePtrTo <ComTypes.TYPEATTR>())
            {
                var hr = _target_ITypeInfo.GetTypeAttr(typeAttrPtr.Address);

                if (!ComHelper.HRESULT_FAILED(hr))
                {
                    CachedAttributes = typeAttrPtr.Value.Value;    // dereference the ptr, then the content
                    var pTypeAttr = typeAttrPtr.Value.Address;     // dereference the ptr, and take the contents address
                    _target_ITypeInfo.ReleaseTypeAttr(pTypeAttr);  // can release immediately as CachedAttributes is a copy
                }
                else
                {
                    if (hr == (int)KnownComHResults.E_VBA_COMPILEERROR)
                    {
                        // If there is a compilation error outside of a procedure code block, the type information is not available for that component.
                        // We detect this, via the E_VBA_COMPILEERROR error
                        HasModuleScopeCompilationErrors = true;
                    }

                    // just mute the error and expose an empty type
                    CachedAttributes = new ComTypes.TYPEATTR();
                }
            }

            Funcs = new TypeInfoFunctionCollection(this, CachedAttributes);

            // Refer to AllVars XML docs for details
            AllVars = new TypeInfoVariablesCollection(this, CachedAttributes);
            if (CachedAttributes.typekind == ComTypes.TYPEKIND.TKIND_MODULE && HasVBEExtensions)
            {
                _consts = new TypeInfoConstantsCollection(this, CachedAttributes);
            }

            ImplementedInterfaces = new TypeInfoImplementedInterfacesCollection(this, CachedAttributes);

            // cache the container type library if it is available, else create a simulated one
            using (var typeLibPtr = AddressableVariables.Create <IntPtr>())
                using (var containerTypeLibIndex = AddressableVariables.Create <int>())
                {
                    var hr = _target_ITypeInfo.GetContainingTypeLib(typeLibPtr.Address, containerTypeLibIndex.Address);

                    if (!ComHelper.HRESULT_FAILED(hr))
                    {
                        // We have to wrap the ITypeLib returned by GetContainingTypeLib
                        _container     = TypeApiFactory.GetTypeLibWrapper(typeLibPtr.Value, addRef: false);
                        ContainerIndex = containerTypeLibIndex.Value;
                    }
                    else
                    {
                        if (hr == (int)KnownComHResults.E_NOTIMPL)
                        {
                            // it is acceptable for a type to not have a container, as types can be runtime generated (e.g. UserForm base classes)
                            // When that is the case, the ITypeInfo responds with E_NOTIMPL
                            // However, we create fake container to avoid errors from CLR when using those "uncontained" TypeInfo
                            HasSimulatedContainer = true;
                            var newContainer = new SimpleCustomTypeLibrary();
                            _container     = newContainer;
                            ContainerIndex = newContainer.Add(this);
                        }
                        else
                        {
                            throw new ArgumentException("Unrecognised error when getting ITypeInfo container: \n" + hr);
                        }
                    }
                }
        }