Ejemplo n.º 1
0
        static void    ExtractNames(string typelib)
        {
            UCOMITypeLib tl = null;

            OleAut.LoadTypeLibEx(typelib, OleAut.REGKIND_NONE, out tl);

            // Get the names from ITypeLib
            string name;
            string docstring;
            Int32  ctxt;
            string helpfile;

            tl.GetDocumentation(-1, out name, out docstring, out ctxt, out helpfile);
            IntPtr pa;

            tl.GetLibAttr(out pa);
            TYPELIBATTR ta = (TYPELIBATTR)Marshal.PtrToStructure(pa, typeof(TYPELIBATTR));

            DealWithName(name, ta.guid);

            // Enumerate TypeInfos
            int nTypeInfos = tl.GetTypeInfoCount();

            for (int i = 0; i < nTypeInfos; i++)
            {
                UCOMITypeInfo it = null;
                tl.GetTypeInfo(i, out it);
                DealWithTypeInfo(it);
            }
        }
Ejemplo n.º 2
0
        /// <include file='doc\AxImporter.uex' path='docs/doc[@for="AxImporter.GenerateFromTypeLibrary"]/*' />
        /// <devdoc>
        ///    <para>Generates a wrapper for an ActiveX control for use in the design-time
        ///       environment.</para>
        /// </devdoc>
        public string GenerateFromTypeLibrary(UCOMITypeLib typeLib)
        {
            bool foundAxCtl = false;

            int ctypes = typeLib.GetTypeInfoCount();

            Debug.WriteLineIf(AxWrapperGen.AxWrapper.Enabled, "Number of TypeInfos found in typelib: " + ctypes);

            for (int i = 0; i < ctypes; ++i)
            {
                IntPtr        pAttr;
                TYPEATTR      typeAttr;
                UCOMITypeInfo pTI;

                typeLib.GetTypeInfo(i, out pTI);
                pTI.GetTypeAttr(out pAttr);
                typeAttr = (TYPEATTR)Marshal.PtrToStructure(pAttr, typeof(TYPEATTR));

                if ((int)typeAttr.typekind == (int)TYPEKIND.TKIND_COCLASS)
                {
                    Guid        g          = typeAttr.guid;
                    string      controlKey = "CLSID\\{" + g.ToString() + "}\\Control";
                    RegistryKey key        = Registry.ClassesRoot.OpenSubKey(controlKey);
                    if (key != null)
                    {
                        Debug.WriteLineIf(AxWrapperGen.AxWrapper.Enabled, "Found ActiveX control with the following GUID: " + g.ToString());
                        foundAxCtl = true;
                    }
                }

                pTI.ReleaseTypeAttr(pAttr);
                pAttr = IntPtr.Zero;
                Marshal.ReleaseComObject(pTI);
                pTI = null;
            }

            if (foundAxCtl)
            {
                Debug.WriteLineIf(AxWrapperGen.AxWrapper.Enabled, "Generating Windows Forms wrappers for: " + typeLibName);
                return(GenerateFromTypeLibrary(typeLib, Guid.Empty));
            }
            else
            {
                throw new Exception(SR.GetString(SR.AXNoActiveXControls, (typeLibName != null) ? typeLibName : Marshal.GetTypeLibName(typeLib)));
            }
        }
Ejemplo n.º 3
0
        public ComImporter(string path, OutputMessageCollection outputMessages, string outputDisplayName)
        {
            _outputMessages    = outputMessages;
            _outputDisplayName = outputDisplayName;

            if (NativeMethods.SfcIsFileProtected(IntPtr.Zero, path) != 0)
            {
                outputMessages.AddWarningMessage("GenerateManifest.ComImport", outputDisplayName, _resources.GetString("ComImporter.ProtectedFile"));
            }

            object obj = null;

            try { NativeMethods.LoadTypeLibEx(path, NativeMethods.RegKind.RegKind_None, out obj); }
            catch (COMException) { }

#pragma warning disable 618
            UCOMITypeLib tlib = (UCOMITypeLib)obj;
            if (tlib != null)
            {
                IntPtr typeLibAttrPtr = IntPtr.Zero;
                tlib.GetLibAttr(out typeLibAttrPtr);
                TYPELIBATTR typeLibAttr = (TYPELIBATTR)Marshal.PtrToStructure(typeLibAttrPtr, typeof(TYPELIBATTR));
                tlib.ReleaseTLibAttr(typeLibAttrPtr);
                Guid tlbid = typeLibAttr.guid;

                string name, docString, helpFile;
                int    helpContext;
                tlib.GetDocumentation(-1, out name, out docString, out helpContext, out helpFile);
                string helpdir = Util.FilterNonprintableChars(helpFile); //Path.GetDirectoryName(helpFile);

                _typeLib = new TypeLib(tlbid, new Version(typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum), helpdir, typeLibAttr.lcid, Convert.ToInt32(typeLibAttr.wLibFlags, CultureInfo.InvariantCulture));

                List <ComClass> comClassList = new List <ComClass>();
                int             count        = tlib.GetTypeInfoCount();
                for (int i = 0; i < count; ++i)
                {
                    TYPEKIND tkind;
                    tlib.GetTypeInfoType(i, out tkind);
                    if (tkind == TYPEKIND.TKIND_COCLASS)
                    {
                        UCOMITypeInfo tinfo;
                        tlib.GetTypeInfo(i, out tinfo);

                        IntPtr tinfoAttrPtr = IntPtr.Zero;
                        tinfo.GetTypeAttr(out tinfoAttrPtr);
                        TYPEATTR tinfoAttr = (TYPEATTR)Marshal.PtrToStructure(tinfoAttrPtr, typeof(TYPEATTR));
                        tinfo.ReleaseTypeAttr(tinfoAttrPtr);
                        Guid   clsid  = tinfoAttr.guid;
                        string sclsid = clsid.ToString("B");

                        tlib.GetDocumentation(i, out name, out docString, out helpContext, out helpFile);
                        string description = Util.FilterNonprintableChars(docString);

                        ClassInfo info = GetRegisteredClassInfo(clsid);
                        if (info == null)
                        {
                            continue;
                        }

                        comClassList.Add(new ComClass(tlbid, clsid, info.Progid, info.ThreadingModel, description));
                    }
                }
                if (comClassList.Count > 0)
                {
                    _comClasses = comClassList.ToArray();
                    _success    = true;
                }
                else
                {
                    outputMessages.AddErrorMessage("GenerateManifest.ComImport", outputDisplayName, _resources.GetString("ComImporter.NoRegisteredClasses"));
                    _success = false;
                }
            }
            else
            {
                outputMessages.AddErrorMessage("GenerateManifest.ComImport", outputDisplayName, _resources.GetString("ComImporter.TypeLibraryLoadFailure"));
                _success = false;
            }
#pragma warning restore 618
        }
Ejemplo n.º 4
0
Archivo: Form1.cs Proyecto: rojac07/COM
        private void FillListBoxes(UCOMITypeLib itfTypeLib)
        {
            // Clear out current contents.
            lstBoxCoclasses.Items.Clear();
            lstBoxInterfaces.Items.Clear();
            lstBoxEnums.Items.Clear();

            // Get # of COM types in the library.
            int typeCount = itfTypeLib.GetTypeInfoCount();
            lblNumbOfTypes.Text = "Number of COM Types in file: " + typeCount.ToString();

            // Switch between COM type.
            // Dump out the types.
            for(int typeIndex = 0; typeIndex < typeCount; typeIndex++)
            {
                string typeInfoString;
                UCOMITypeInfo pInfo;

                // Get TYPEATTR structure set up.
                TYPEATTR typeAtt = new TYPEATTR();
                Type TYPEATTRType = typeAtt.GetType();
                int structSize = Marshal.SizeOf(TYPEATTRType);
                IntPtr ptr = IntPtr.Zero;
                ptr = Marshal.AllocHGlobal(structSize);

                // Get next type info.
                itfTypeLib.GetTypeInfo(typeIndex, out pInfo);
                pInfo.GetTypeAttr(out ptr);
                typeAtt = (TYPEATTR) Marshal.PtrToStructure(ptr, TYPEATTRType);

                // Based on the kind of COM type, print out some information.
                string typeName, helpFile, docString;
                int helpID;

                switch(typeAtt.typekind)
                {
                    case TYPEKIND.TKIND_COCLASS:  // type is a coclass.
                        pInfo.GetDocumentation(-1, out typeName, out docString,
                                               out helpID, out helpFile);
                        typeInfoString = "Name: " + typeName + "\tCLSID: {" + typeAtt.guid.ToString() + "}";
                        lstBoxCoclasses.Items.Add(typeInfoString);
                    break;

                    case TYPEKIND.TKIND_INTERFACE:  // type is a interface.
                    case TYPEKIND.TKIND_DISPATCH:
                        pInfo.GetDocumentation(-1, out typeName, out docString,
                            out helpID, out helpFile);
                        typeInfoString = "Name: " + typeName + "\tIID: {" + typeAtt.guid.ToString() + "}";
                        lstBoxInterfaces.Items.Add(typeInfoString);
                    break;

                    case TYPEKIND.TKIND_ENUM:  // type is a enum.
                        pInfo.GetDocumentation(-1, out typeName, out docString,
                            out helpID, out helpFile);
                        typeInfoString = "Name: " + typeName;
                        lstBoxEnums.Items.Add(typeInfoString);
                    break;
                }
                Marshal.DestroyStructure(ptr, typeAtt.GetType());
            }
        }
Ejemplo n.º 5
0
Archivo: Form1.cs Proyecto: summy00/COM
        private void FillListBoxes(UCOMITypeLib itfTypeLib)
        {
            // Clear out current contents.
            lstBoxCoclasses.Items.Clear();
            lstBoxInterfaces.Items.Clear();
            lstBoxEnums.Items.Clear();

            // Get # of COM types in the library.
            int typeCount = itfTypeLib.GetTypeInfoCount();

            lblNumbOfTypes.Text = "Number of COM Types in file: " + typeCount.ToString();

            // Switch between COM type.
            // Dump out the types.
            for (int typeIndex = 0; typeIndex < typeCount; typeIndex++)
            {
                string        typeInfoString;
                UCOMITypeInfo pInfo;

                // Get TYPEATTR structure set up.
                TYPEATTR typeAtt      = new TYPEATTR();
                Type     TYPEATTRType = typeAtt.GetType();
                int      structSize   = Marshal.SizeOf(TYPEATTRType);
                IntPtr   ptr          = IntPtr.Zero;
                ptr = Marshal.AllocHGlobal(structSize);

                // Get next type info.
                itfTypeLib.GetTypeInfo(typeIndex, out pInfo);
                pInfo.GetTypeAttr(out ptr);
                typeAtt = (TYPEATTR)Marshal.PtrToStructure(ptr, TYPEATTRType);

                // Based on the kind of COM type, print out some information.
                string typeName, helpFile, docString;
                int    helpID;

                switch (typeAtt.typekind)
                {
                case TYPEKIND.TKIND_COCLASS:                          // type is a coclass.
                    pInfo.GetDocumentation(-1, out typeName, out docString,
                                           out helpID, out helpFile);
                    typeInfoString = "Name: " + typeName + "\tCLSID: {" + typeAtt.guid.ToString() + "}";
                    lstBoxCoclasses.Items.Add(typeInfoString);
                    break;

                case TYPEKIND.TKIND_INTERFACE:                          // type is a interface.
                case TYPEKIND.TKIND_DISPATCH:
                    pInfo.GetDocumentation(-1, out typeName, out docString,
                                           out helpID, out helpFile);
                    typeInfoString = "Name: " + typeName + "\tIID: {" + typeAtt.guid.ToString() + "}";
                    lstBoxInterfaces.Items.Add(typeInfoString);
                    break;

                case TYPEKIND.TKIND_ENUM:                          // type is a enum.
                    pInfo.GetDocumentation(-1, out typeName, out docString,
                                           out helpID, out helpFile);
                    typeInfoString = "Name: " + typeName;
                    lstBoxEnums.Items.Add(typeInfoString);
                    break;
                }
                Marshal.DestroyStructure(ptr, typeAtt.GetType());
            }
        }
Ejemplo n.º 6
0
        public ComImporter(string path, OutputMessageCollection outputMessages, string outputDisplayName)
        {
            this.outputMessages    = outputMessages;
            this.outputDisplayName = outputDisplayName;
            if (Microsoft.Build.Tasks.Deployment.ManifestUtilities.NativeMethods.SfcIsFileProtected(IntPtr.Zero, path) != 0)
            {
                outputMessages.AddWarningMessage("GenerateManifest.ComImport", new string[] { outputDisplayName, this.resources.GetString("ComImporter.ProtectedFile") });
            }
            object typeLib = null;

            try
            {
                Microsoft.Build.Tasks.Deployment.ManifestUtilities.NativeMethods.LoadTypeLibEx(path, Microsoft.Build.Tasks.Deployment.ManifestUtilities.NativeMethods.RegKind.RegKind_None, out typeLib);
            }
            catch (COMException)
            {
            }
            UCOMITypeLib lib = (UCOMITypeLib)typeLib;

            if (lib != null)
            {
                string str;
                string str2;
                string str3;
                int    num;
                IntPtr zero = IntPtr.Zero;
                lib.GetLibAttr(out zero);
                TYPELIBATTR typelibattr = (TYPELIBATTR)Marshal.PtrToStructure(zero, typeof(TYPELIBATTR));
                lib.ReleaseTLibAttr(zero);
                Guid tlbId = typelibattr.guid;
                lib.GetDocumentation(-1, out str, out str2, out num, out str3);
                string helpDirectory = Microsoft.Build.Tasks.Deployment.ManifestUtilities.Util.FilterNonprintableChars(str3);
                this.typeLib = new Microsoft.Build.Tasks.Deployment.ManifestUtilities.TypeLib(tlbId, new Version(typelibattr.wMajorVerNum, typelibattr.wMinorVerNum), helpDirectory, typelibattr.lcid, Convert.ToInt32(typelibattr.wLibFlags, CultureInfo.InvariantCulture));
                List <ComClass> list          = new List <ComClass>();
                int             typeInfoCount = lib.GetTypeInfoCount();
                for (int i = 0; i < typeInfoCount; i++)
                {
                    TYPEKIND typekind;
                    lib.GetTypeInfoType(i, out typekind);
                    if (typekind == TYPEKIND.TKIND_COCLASS)
                    {
                        UCOMITypeInfo info;
                        lib.GetTypeInfo(i, out info);
                        IntPtr ppTypeAttr = IntPtr.Zero;
                        info.GetTypeAttr(out ppTypeAttr);
                        TYPEATTR typeattr = (TYPEATTR)Marshal.PtrToStructure(ppTypeAttr, typeof(TYPEATTR));
                        info.ReleaseTypeAttr(ppTypeAttr);
                        Guid guid = typeattr.guid;
                        guid.ToString("B");
                        lib.GetDocumentation(i, out str, out str2, out num, out str3);
                        string    description         = Microsoft.Build.Tasks.Deployment.ManifestUtilities.Util.FilterNonprintableChars(str2);
                        ClassInfo registeredClassInfo = this.GetRegisteredClassInfo(guid);
                        if (registeredClassInfo != null)
                        {
                            list.Add(new ComClass(tlbId, guid, registeredClassInfo.Progid, registeredClassInfo.ThreadingModel, description));
                        }
                    }
                }
                if (list.Count > 0)
                {
                    this.comClasses = list.ToArray();
                    this.success    = true;
                }
                else
                {
                    outputMessages.AddErrorMessage("GenerateManifest.ComImport", new string[] { outputDisplayName, this.resources.GetString("ComImporter.NoRegisteredClasses") });
                    this.success = false;
                }
            }
            else
            {
                outputMessages.AddErrorMessage("GenerateManifest.ComImport", new string[] { outputDisplayName, this.resources.GetString("ComImporter.TypeLibraryLoadFailure") });
                this.success = false;
            }
        }