Ejemplo n.º 1
0
        public override ITypeInfoWrapper GetItemByIndex(int index)
        {
            _parent.GetRefTypeOfImplType(index, out var href);
            _parent.GetRefTypeInfo(href, out var ti);

            return(TypeApiFactory.GetTypeInfoWrapper(ti));
        }
Ejemplo n.º 2
0
 internal static ITypeLibWrapper FromVBProject(IVBProject vbProject)
 {
     using (var references = vbProject.References)
     {
         // Now we've got the references object, we can read the internal object structure to grab the ITypeLib
         var internalReferencesObj = StructHelper.ReadComObjectStructure <VBEReferencesObj>(references.Target);
         return(TypeApiFactory.GetTypeLibWrapper(internalReferencesObj._typeLib, addRef: true));
     }
 }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public override int GetTypeInfoOfGuid(ref Guid guid, IntPtr ppTInfo)
        {
            var hr = _target_ITypeLib.GetTypeInfoOfGuid(guid, ppTInfo);

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

            var pTInfo = RdMarshal.ReadIntPtr(ppTInfo);

            using (var outVal = TypeApiFactory.GetTypeInfoWrapper(pTInfo)) // takes ownership of the COM reference [pTInfo]
            {
                RdMarshal.WriteIntPtr(ppTInfo, outVal.GetCOMReferencePtr());

                _cachedTypeInfos = _cachedTypeInfos ?? new DisposableList <ITypeInfoWrapper>();
                _cachedTypeInfos.Add(outVal);
            }

            return(hr);
        }
Ejemplo n.º 6
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);
                        }
                    }
                }
        }