/// <summary> /// Determines the document class type of a VBA class. See <see cref="DocClassHelper" /> /// </summary> /// <returns>the identified document class type, or <see cref="DocClassType.Unrecognized" /></returns> public static DocClassType DetermineDocumentClassType(ITypeInfoWrapper rootInterface) { return(rootInterface.ImplementedInterfaces .DoesImplement(DocClassHelper.KnownDocumentInterfaceProgIds, out var matchId) ? DocClassHelper.KnownDocumentInterfaces[matchId].DocType : DocClassType.Unrecognized); }
int ITypeLibWrapper.GetSafeTypeInfoByIndex(int index, out ITypeInfoWrapper outTI) { var result = GetSafeTypeInfoByIndex(index, out var outTIW); outTI = outTIW; return(result); }
int ITypeInfoWrapper.GetSafeRefTypeInfo(int hRef, out ITypeInfoWrapper outTI) { var result = GetSafeRefTypeInfo(hRef, out var outTIW); outTI = outTIW; return(result); }
/// <summary> /// Gets the control <see cref="ComTypes.ITypeInfo"/> by looking for the /// corresponding getter on the form interface and returning its retval type /// </summary> /// <param name="controlName">the name of the control</param> /// <returns> /// <see cref="ITypeInfoWrapper"/> representing the type of control, /// typically the coclass, but this is host dependent /// </returns> public static ITypeInfoWrapper GetControlTypeFromInterface(ITypeInfoWrapper rootInterface, string controlName) { // TODO should encapsulate handling of raw datatypes foreach (var func in rootInterface.Funcs) { using (func) { // Controls are exposed as getters on the interface. // can either be ControlType* get_ControlName() // or HRESULT get_ControlName(ControlType** Out) if ((func.Name == controlName) && (func.ProcKind == PROCKIND.PROCKIND_GET) && (func.ParamCount == 0) && (func.FuncDesc.elemdescFunc.tdesc.vt == (short)VarEnum.VT_PTR)) { var retValElement = StructHelper.ReadStructureUnsafe <ComTypes.ELEMDESC>(func.FuncDesc.elemdescFunc.tdesc.lpValue); if (retValElement.tdesc.vt == (short)VarEnum.VT_USERDEFINED) { var hr = rootInterface.GetSafeRefTypeInfo((int)retValElement.tdesc.lpValue, out var retVal); if (ComHelper.HRESULT_FAILED(hr)) { throw RdMarshal.GetExceptionForHR(hr); } return(retVal); } } else if ((func.Name == controlName) && (func.ProcKind == PROCKIND.PROCKIND_GET) && (func.ParamCount == 1) && (func.FuncDesc.elemdescFunc.tdesc.vt == (short)VarEnum.VT_HRESULT)) { // Get details of the first argument var retValElementOuterPtr = StructHelper.ReadStructureUnsafe <ComTypes.ELEMDESC>(func.FuncDesc.lprgelemdescParam); if (retValElementOuterPtr.tdesc.vt == (short)VarEnum.VT_PTR) { var retValElementInnerPtr = StructHelper.ReadStructureUnsafe <ComTypes.ELEMDESC>(retValElementOuterPtr.tdesc.lpValue); if (retValElementInnerPtr.tdesc.vt == (short)VarEnum.VT_PTR) { var retValElement = StructHelper.ReadStructureUnsafe <ComTypes.ELEMDESC>(retValElementInnerPtr.tdesc.lpValue); if (retValElement.tdesc.vt == (short)VarEnum.VT_USERDEFINED) { var hr = rootInterface.GetSafeRefTypeInfo((int)retValElement.tdesc.lpValue, out var retVal); if (ComHelper.HRESULT_FAILED(hr)) { throw RdMarshal.GetExceptionForHR(hr); } return(retVal); } } } } } } throw new ArgumentException($"TypeInfoWrapper::GetControlType failed. '{controlName}' control not found."); }
int ITypeInfoWrapper.GetSafeRefTypeInfo(int hRef, out ITypeInfoWrapper outTI) { Before($"{nameof(hRef)}: {hRef}"); var result = _wrapper.GetSafeRefTypeInfo(hRef, out var t); After($"{nameof(result)}: {result}, {nameof(outTI)}: {t?.GetHashCode()}"); outTI = t; return(result); }
int ITypeLibWrapper.GetSafeTypeInfoByIndex(int index, out ITypeInfoWrapper outTI) { Before($"{nameof(index)}: {index}"); var result = _wrapper.GetSafeTypeInfoByIndex(index, out var t); After($"{nameof(result)}: {result}, {nameof(outTI)}: {t?.GetHashCode()}"); outTI = t; return(result); }
public static void Document(this ITypeInfoWrapper _this, StringLineBuilder output, string qualifiedName, int implementsLevel) { output.AppendLine(); if (implementsLevel == 0) { output.AppendLine("-------------------------------------------------------------------------------"); output.AppendLine(); } implementsLevel++; qualifiedName += "::" + (_this.Name ?? "[unnamed]"); output.AppendLineNoNullChars(qualifiedName); output.AppendLineNoNullChars("- FullName: " + _this.ContainerName + "." + _this.Name); output.AppendLineNoNullChars("- Documentation: " + _this.DocString); output.AppendLineNoNullChars("- HelpContext: " + _this.HelpContext); output.AppendLineNoNullChars("- HelpFile: " + _this.HelpFile); output.AppendLine("- HasVBEExtensions: " + _this.HasVBEExtensions); if (_this.HasVBEExtensions) { output.AppendLine("- HasModuleScopeCompilationErrors: " + _this.HasModuleScopeCompilationErrors); } output.AppendLine("- Type: " + _this.TypeKind); output.AppendLine("- Guid: {" + _this.GUID + "}"); output.AppendLine("- cImplTypes (implemented interfaces count): " + _this.ImplementedInterfaces.Count); output.AppendLine("- cFuncs (function count): " + _this.Funcs.Count); output.AppendLine("- cVars (fields count): " + _this.Vars.Count); foreach (var func in _this.Funcs) { using (func) { func.Document(output); } } foreach (var variable in _this.Vars) { using (variable) { variable.Document(output); } } foreach (var typeInfoImpl in _this.ImplementedInterfaces) { using (typeInfoImpl) { output.AppendLine("implements..."); typeInfoImpl.Document(output, qualifiedName, implementsLevel); } } }
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); } }
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); } }
internal TypeInfoWrapperTracer(ITypeInfoWrapper wrapper, ITypeInfoInternal inner) { _wrapper = wrapper; _inner = inner; }
private static void TraceWrapper(ref ITypeInfoWrapper wrapper) { wrapper = new TypeInfoWrapperTracer(wrapper, (ITypeInfoInternal)wrapper); }
public TypeInfoVBEExtensions(ITypeInfoWrapper parent, IntPtr tiPtr) { _parent = parent; //_target_IVBEComponent = ComHelper.ComCastViaAggregation<IVBEComponent>(tiPtr); _vbeComponentPointer = ComPointer <IVBEComponent> .GetObjectViaAggregation(tiPtr, false, true); }