Пример #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;
                        }
        }
Пример #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);
            }
        }
Пример #3
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;
            }
        }
Пример #4
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;
            }
        }
Пример #5
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;
            }
        }
Пример #6
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);
         }
 }
Пример #7
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;
            }
        }
Пример #8
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;
                }
        }
Пример #9
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;
                    }
        }
Пример #10
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;
                }
        }
Пример #11
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);
            }
        }
Пример #12
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);
            }
        }
Пример #13
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);
                        }
                    }
                }
        }