/// <summary> /// Returns parent library id /// </summary> /// <param name="value">core to use</param> /// <param name="comProxy">new created proxy</param> /// <returns>parent library/component id</returns> internal static Guid GetParentLibraryGuid(this Core value, object comProxy) { if (null == comProxy) { throw new ArgumentNullException(); } IDispatch dispatcher = comProxy as IDispatch; if (null == dispatcher) { return(Guid.Empty); } COMTypes.ITypeInfo typeInfo = dispatcher.GetTypeInfo(0, 0); COMTypes.ITypeLib parentTypeLib = null; Guid typeGuid = typeInfo.GetTypeGuid(); Guid parentGuid = Guid.Empty; if (!value.HostCache.TryGetValue(typeGuid, out parentGuid)) { int i = 0; typeInfo.GetContainingTypeLib(out parentTypeLib, out i); IntPtr attributesPointer = IntPtr.Zero; parentTypeLib.GetLibAttr(out attributesPointer); COMTypes.TYPELIBATTR attributes = (COMTypes.TYPELIBATTR)Marshal.PtrToStructure(attributesPointer, typeof(COMTypes.TYPELIBATTR)); parentGuid = attributes.guid; parentTypeLib.ReleaseTLibAttr(attributesPointer); Marshal.ReleaseComObject(parentTypeLib); value.HostCache.Add(typeGuid, parentGuid); } Marshal.ReleaseComObject(typeInfo); return(parentGuid); }
/// <summary> /// Get type id from IDispatch GetTypeInfo /// </summary> /// <param name="comProxy">target proxy</param> /// <returns>type id</returns> internal static Guid TypeGuid(this object comProxy) { Guid typeGuid = Guid.Empty; if (null == comProxy) { throw new ArgumentNullException(); } IDispatch dispatcher = comProxy as IDispatch; if (null == dispatcher) { throw new IDispatchNotImplementedException(); } COMTypes.ITypeInfo typeInfo = dispatcher.GetTypeInfo(); typeGuid = typeInfo.GetTypeGuid(); Marshal.ReleaseComObject(typeInfo); return(typeGuid); }