/// <summary> /// returns id of an interface /// </summary> /// <param name="typeInfo"></param> /// <returns></returns> private static Guid GetTypeGuid(COMTypes.ITypeInfo typeInfo) { IntPtr attribPtr = IntPtr.Zero; typeInfo.GetTypeAttr(out attribPtr); COMTypes.TYPEATTR Attributes = (COMTypes.TYPEATTR)Marshal.PtrToStructure(attribPtr, typeof(COMTypes.TYPEATTR)); Guid typeGuid = Attributes.guid; typeInfo.ReleaseTypeAttr(attribPtr); return(typeGuid); }
internal static Guid GetTypeGuid(COMTypes.ITypeInfo typeInfo) { if (null == typeInfo) { return(Guid.Empty); } IntPtr attribPtr = IntPtr.Zero; typeInfo.GetTypeAttr(out attribPtr); COMTypes.TYPEATTR Attributes = (COMTypes.TYPEATTR)Marshal.PtrToStructure(attribPtr, typeof(COMTypes.TYPEATTR)); Guid typeGuid = Attributes.guid; typeInfo.ReleaseTypeAttr(attribPtr); return(typeGuid); }
internal static ComTypes.TYPEATTR GetTypeAttrForTypeInfo(ComTypes.ITypeInfo typeInfo) { IntPtr pAttrs = IntPtr.Zero; typeInfo.GetTypeAttr(out pAttrs); // GetTypeAttr should never return null, this is just to be safe if (pAttrs == IntPtr.Zero) { throw Error.CannotRetrieveTypeInformation(); } try { return((ComTypes.TYPEATTR)Marshal.PtrToStructure(pAttrs, typeof(ComTypes.TYPEATTR))); } finally { typeInfo.ReleaseTypeAttr(pAttrs); } }
/// <summary> /// Creates an entity support list for a proxy /// </summary> /// <param name="factory">core to perform searching</param> /// <param name="comProxy">proxy to analyze</param> /// <returns>supported methods and properties as name/kind dictionary</returns> /// <exception cref="COMException">Throws generaly if any exception occurs. See inner exception(s) for details</exception> internal Dictionary <string, string> GetSupportedEntities(Core factory, object comProxy) { try { Guid parentLibraryGuid = CoreFactoryExtensions.GetParentLibraryGuid(factory, comProxy); if (Guid.Empty == parentLibraryGuid) { return(null); } string className = TypeDescriptor.GetClassName(comProxy); string key = (parentLibraryGuid.ToString() + className).ToLower(); Dictionary <string, string> supportList = null; if (factory.EntitiesListCache.TryGetValue(key, out supportList)) { return(supportList); } supportList = new Dictionary <string, string>(); IDispatch dispatch = comProxy as IDispatch; if (null == dispatch) { throw new COMException("Unable to cast underlying proxy to IDispatch."); } COMTypes.ITypeInfo typeInfo = dispatch.GetTypeInfo(0, 0); if (null == typeInfo) { throw new COMException("GetTypeInfo returns null."); } IntPtr typeAttrPointer = IntPtr.Zero; typeInfo.GetTypeAttr(out typeAttrPointer); COMTypes.TYPEATTR typeAttr = (COMTypes.TYPEATTR)Marshal.PtrToStructure(typeAttrPointer, typeof(COMTypes.TYPEATTR)); for (int i = 0; i < typeAttr.cFuncs; i++) { string strName, strDocString, strHelpFile; int dwHelpContext; IntPtr funcDescPointer = IntPtr.Zero; COMTypes.FUNCDESC funcDesc; typeInfo.GetFuncDesc(i, out funcDescPointer); funcDesc = (COMTypes.FUNCDESC)Marshal.PtrToStructure(funcDescPointer, typeof(COMTypes.FUNCDESC)); switch (funcDesc.invkind) { case COMTypes.INVOKEKIND.INVOKE_PROPERTYGET: case COMTypes.INVOKEKIND.INVOKE_PROPERTYPUT: case COMTypes.INVOKEKIND.INVOKE_PROPERTYPUTREF: { typeInfo.GetDocumentation(funcDesc.memid, out strName, out strDocString, out dwHelpContext, out strHelpFile); string outValue = ""; bool exists = supportList.TryGetValue("Property-" + strName, out outValue); if (!exists) { supportList.Add("Property-" + strName, strDocString); } break; } case COMTypes.INVOKEKIND.INVOKE_FUNC: { typeInfo.GetDocumentation(funcDesc.memid, out strName, out strDocString, out dwHelpContext, out strHelpFile); string outValue = ""; bool exists = supportList.TryGetValue("Method-" + strName, out outValue); if (!exists) { supportList.Add("Method-" + strName, strDocString); } break; } } typeInfo.ReleaseFuncDesc(funcDescPointer); } typeInfo.ReleaseTypeAttr(typeAttrPointer); Marshal.ReleaseComObject(typeInfo); factory.EntitiesListCache.Add(key, supportList); return(supportList); } catch (Exception exception) { throw new COMException("An unexpected error occurs.", exception); } }