internal static Guid GetParentLibraryGuid(COMTypes.ITypeInfo typeInfo)
        {
            if (null == typeInfo)
            {
                return(Guid.Empty);
            }

            COMTypes.ITypeLib parentTypeLib = null;
            Guid parentGuid = Guid.Empty;

            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);

            return(parentGuid);
        }
Exemple #2
0
        /// <summary>
        /// get the guid from type lib there is the type defined
        /// </summary>
        /// <param name="comProxy"></param>
        /// <returns></returns>
        private static Guid GetParentLibraryGuid(object comProxy)
        {
            IDispatch dispatcher = comProxy as IDispatch;

            COMTypes.ITypeInfo typeInfo      = dispatcher.GetTypeInfo(0, 0);
            COMTypes.ITypeLib  parentTypeLib = null;

            Guid typeGuid   = GetTypeGuid(typeInfo);
            Guid parentGuid = Guid.Empty;

            if (!_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);

                _hostCache.Add(typeGuid, parentGuid);
            }

            Marshal.ReleaseComObject(typeInfo);

            return(parentGuid);
        }
Exemple #3
0
        private static Guid GetParentLibGuid(object comProxy)
        {
            Guid returnGuid = Guid.Empty;

            IDispatch dispatcher = (IDispatch)comProxy;

            COMTypes.ITypeInfo typeInfo      = dispatcher.GetTypeInfo(0, 0);
            COMTypes.ITypeLib  parentTypeLib = null;

            int i = 0;

            typeInfo.GetContainingTypeLib(out parentTypeLib, out i);

            IntPtr attributesPointer = IntPtr.Zero;

            parentTypeLib.GetLibAttr(out attributesPointer);

            COMTypes.TYPEATTR attributes = (COMTypes.TYPEATTR)Marshal.PtrToStructure(attributesPointer, typeof(COMTypes.TYPEATTR));
            returnGuid = attributes.guid;

            parentTypeLib.ReleaseTLibAttr(attributesPointer);
            Marshal.ReleaseComObject(parentTypeLib);
            Marshal.ReleaseComObject(typeInfo);

            return(returnGuid);
        }
Exemple #4
0
        internal static ComTypes.TYPELIBATTR GetTypeLibAttr(ComTypes.ITypeLib typeLib)
        {
            IntPtr ptr;

            typeLib.GetLibAttr(out ptr);
            var typeLibAttr = (ComTypes.TYPELIBATTR)Marshal.PtrToStructure(ptr, typeof(ComTypes.TYPELIBATTR));

            typeLib.ReleaseTLibAttr(ptr);
            return(typeLibAttr);
        }
        private void AddTypeLibAttr(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib)
        {
            if (this.tlbAttrs == null)
            {
                this.tlbAttrs = new ArrayList();
            }
            IntPtr invalidIntPtr = System.Design.NativeMethods.InvalidIntPtr;

            typeLib.GetLibAttr(out invalidIntPtr);
            if (invalidIntPtr != System.Design.NativeMethods.InvalidIntPtr)
            {
                System.Runtime.InteropServices.TYPELIBATTR typelibattr = (System.Runtime.InteropServices.TYPELIBATTR)Marshal.PtrToStructure(invalidIntPtr, typeof(System.Runtime.InteropServices.TYPELIBATTR));
                this.tlbAttrs.Add(typelibattr);
                typeLib.ReleaseTLibAttr(invalidIntPtr);
            }
        }
        internal Assembly GetPrimaryInteropAssembly(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib, TypeLibConverter tlbConverter)
        {
            Assembly assem = this.FindRCW(typeLib);

            if (assem == null)
            {
                IntPtr invalidIntPtr = System.Design.NativeMethods.InvalidIntPtr;
                typeLib.GetLibAttr(out invalidIntPtr);
                if (!(invalidIntPtr != System.Design.NativeMethods.InvalidIntPtr))
                {
                    return(assem);
                }
                System.Runtime.InteropServices.TYPELIBATTR typelibattr = (System.Runtime.InteropServices.TYPELIBATTR)Marshal.PtrToStructure(invalidIntPtr, typeof(System.Runtime.InteropServices.TYPELIBATTR));
                string asmName     = null;
                string asmCodeBase = null;
                try
                {
                    tlbConverter.GetPrimaryInteropAssembly(typelibattr.guid, typelibattr.wMajorVerNum, typelibattr.wMinorVerNum, typelibattr.lcid, out asmName, out asmCodeBase);
                    if ((asmName != null) && (asmCodeBase == null))
                    {
                        try
                        {
                            assem       = Assembly.ReflectionOnlyLoad(asmName);
                            asmCodeBase = this.GetLocalPath(assem.EscapedCodeBase);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else if (asmCodeBase != null)
                    {
                        asmCodeBase = this.GetLocalPath(asmCodeBase);
                        assem       = Assembly.ReflectionOnlyLoadFrom(asmCodeBase);
                    }
                    if (assem != null)
                    {
                        this.AddRCW(typeLib, assem);
                        this.AddReferencedAssembly(asmCodeBase);
                    }
                }
                finally
                {
                    typeLib.ReleaseTLibAttr(invalidIntPtr);
                }
            }
            return(assem);
        }
Exemple #7
0
        internal static ComTypes.TYPELIBATTR GetTypeAttrForTypeLib(ComTypes.ITypeLib typeLib)
        {
            IntPtr pAttrs = IntPtr.Zero;

            typeLib.GetLibAttr(out pAttrs);

            // GetTypeAttr should never return null, this is just to be safe
            if (pAttrs == IntPtr.Zero)
            {
                throw Error.CannotRetrieveTypeInformation();
            }

            try {
                return((ComTypes.TYPELIBATTR)Marshal.PtrToStructure(pAttrs, typeof(ComTypes.TYPELIBATTR)));
            } finally {
                typeLib.ReleaseTLibAttr(pAttrs);
            }
        }
Exemple #8
0
        // Create a ComReferenceNode via a string to a TLB
        internal ComReferenceNode(ProjectNode root, string filePath)
            : base(root)
        {
            object otypeLib = null;

            ComTypes.ITypeLib typeLib      = null;
            IntPtr            ptrToLibAttr = IntPtr.Zero;

            try
            {
                LoadTypeLibEx(filePath, RegKind.RegKind_None, out otypeLib);
                typeLib = (ComTypes.ITypeLib)otypeLib;
                if (typeLib == null)
                {
                    throw new ArgumentException();
                }
                ComTypes.TYPELIBATTR typeAttr = new ComTypes.TYPELIBATTR();
                typeLib.GetLibAttr(out ptrToLibAttr);
                typeAttr = (ComTypes.TYPELIBATTR)Marshal.PtrToStructure(ptrToLibAttr, typeAttr.GetType());

                // Initialize state
                this.typeGuid           = typeAttr.guid;
                this.majorVersionNumber = typeAttr.wMajorVerNum.ToString(CultureInfo.InvariantCulture);
                this.minorVersionNumber = typeAttr.wMinorVerNum.ToString(CultureInfo.InvariantCulture);
                this.lcid = typeAttr.lcid;

                // Check to see if the COM object actually exists.
                this.SetInstalledFilePath();
                // If the value cannot be set throw.
                if (String.IsNullOrEmpty(this.installedFilePath))
                {
                    var message = string.Format(SR.GetString(SR.ReferenceCouldNotBeAdded, CultureInfo.CurrentUICulture), filePath);
                    throw new InvalidOperationException(message);
                }
            }
            finally
            {
                if (typeLib != null)
                {
                    typeLib.ReleaseTLibAttr(ptrToLibAttr);
                }
            }
        }
        private static string GetFileOfTypeLib(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib)
        {
            IntPtr invalidIntPtr = System.Design.NativeMethods.InvalidIntPtr;

            typeLib.GetLibAttr(out invalidIntPtr);
            if (invalidIntPtr != System.Design.NativeMethods.InvalidIntPtr)
            {
                System.Runtime.InteropServices.TYPELIBATTR tlibattr = (System.Runtime.InteropServices.TYPELIBATTR)Marshal.PtrToStructure(invalidIntPtr, typeof(System.Runtime.InteropServices.TYPELIBATTR));
                try
                {
                    return(GetFileOfTypeLib(ref tlibattr));
                }
                finally
                {
                    typeLib.ReleaseTLibAttr(invalidIntPtr);
                }
            }
            return(null);
        }
        /// <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);
        }
 internal Assembly FindRCW(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib)
 {
     if (this.rcwCache != null)
     {
         IntPtr invalidIntPtr = System.Design.NativeMethods.InvalidIntPtr;
         typeLib.GetLibAttr(out invalidIntPtr);
         try
         {
             if (invalidIntPtr != System.Design.NativeMethods.InvalidIntPtr)
             {
                 System.Runtime.InteropServices.TYPELIBATTR typelibattr = (System.Runtime.InteropServices.TYPELIBATTR)Marshal.PtrToStructure(invalidIntPtr, typeof(System.Runtime.InteropServices.TYPELIBATTR));
                 return((Assembly)this.rcwCache[typelibattr.guid]);
             }
         }
         finally
         {
             typeLib.ReleaseTLibAttr(invalidIntPtr);
         }
     }
     return(null);
 }
        internal void AddRCW(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib, Assembly assem)
        {
            if (this.rcwCache == null)
            {
                this.rcwCache = new Hashtable();
            }
            IntPtr invalidIntPtr = System.Design.NativeMethods.InvalidIntPtr;

            typeLib.GetLibAttr(out invalidIntPtr);
            try
            {
                if (invalidIntPtr != System.Design.NativeMethods.InvalidIntPtr)
                {
                    System.Runtime.InteropServices.TYPELIBATTR typelibattr = (System.Runtime.InteropServices.TYPELIBATTR)Marshal.PtrToStructure(invalidIntPtr, typeof(System.Runtime.InteropServices.TYPELIBATTR));
                    this.rcwCache.Add(typelibattr.guid, assem);
                }
            }
            finally
            {
                typeLib.ReleaseTLibAttr(invalidIntPtr);
            }
        }
Exemple #13
0
 public ComTypeLibrary(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib)
 {
     _typeLib = typeLib;
     _typeLib.GetLibAttr(out _pTypeLibAttr);
     _typeLib.GetDocumentation(-1, out _Name, out _Description, out _HelpContext, out _HelpFile);
 }
Exemple #14
0
 public ComTypeLibrary(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib)
 {
     _typeLib = typeLib;
     _typeLib.GetLibAttr(out _pTypeLibAttr);
     _typeLib.GetDocumentation(-1, out _Name, out _Description, out _HelpContext, out _HelpFile);
 }