Beispiel #1
0
        private void ParseComClass(TreeNode node, out ComClassRegInfo comClassRegInfo, out string comFile)
        {
            comClassRegInfo       = new ComClassRegInfo();
            comClassRegInfo.clsid = node.Text;
            comFile = "";
            comClassRegInfo.description = node.GetNodeValue();
            var progId = node.GetNodeValue("ProgId");

            if (!string.IsNullOrWhiteSpace(progId))
            {
                comClassRegInfo.AddProgId(progId);
            }
            var inprocNode = node.GetNode("InprocServer32");

            if (inprocNode == null)
            {
                inprocNode = node.GetNode("InprocHandler32");
            }
            if (inprocNode != null)
            {
                foreach (TreeNode inprocItem in inprocNode.Nodes)
                {
                    Model.RegInfo regInfo = inprocItem.Tag as Model.RegInfo;
                    if (regInfo != null && regInfo.ValueName == "@")
                    {
                        string comFilePath = regInfo.Value.Replace(@"\\", @"\");
                        int    startPos    = comFilePath.LastIndexOf("\\");
                        if (startPos != -1)
                        {
                            comFilePath = comFilePath.Substring(startPos + 1);
                        }
                        comFile = comFilePath;
                    }
                    else if (regInfo != null && string.Compare(regInfo.ValueName, "ThreadingModel", true) == 0)
                    {
                        comClassRegInfo.threadingModel = regInfo.Value;
                    }
                }
            }
            else
            {
                comClassRegInfo.tlbid = node.GetNodeValue("TypeLib");
            }
        }
Beispiel #2
0
        public void UpdateTypeInfo(List <string> listOfComFile, List <string> allFiles)
        {
            foreach (var item in listOfComFile)
            {
                string filePath = allFiles.GetFilePath(item);
                if (File.Exists(filePath))
                {
                    string      tlbFilePath = string.Format("{0}\\{1}.tlb", Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath));
                    ComFileInfo fileInfo;
                    string      fileName = Path.GetFileName(filePath);
                    ITypeLib    typeLib;
                    if (File.Exists(tlbFilePath))
                    {
                        typeLib = TypeLib.GetTypeLib(tlbFilePath);
                    }
                    else
                    {
                        typeLib = TypeLib.GetTypeLib(filePath);
                    }

                    if (typeLib == null)
                    {
                        if (_allRegComFiles.TryGetValue(fileName, out fileInfo))
                        {
                            fileInfo.name = fileName;
                            _allFileComFiles.Add(fileName, fileInfo);
                        }
                        continue;
                    }

                    fileInfo      = new ComFileInfo();
                    fileInfo.name = fileName;
                    ComTypeLibRegInfo typeLibInfo = new ComTypeLibRegInfo();
                    _allFileComFiles.Add(fileInfo.name, fileInfo);

                    IntPtr typeLibAttribPtr;
                    typeLib.GetLibAttr(out typeLibAttribPtr);

                    if (typeLibAttribPtr != IntPtr.Zero)
                    {
                        var typeLibAttrib = Marshal.PtrToStructure <System.Runtime.InteropServices.ComTypes.TYPELIBATTR>(typeLibAttribPtr);

                        typeLibInfo.tlbid   = typeLibAttrib.guid.ToString("B");
                        typeLibInfo.version = typeLibAttrib.wMajorVerNum.ToString();
                        typeLibInfo.flags   = typeLibAttrib.wLibFlags.ToString();
                        typeLibInfo.helpdir = "";
                        string typelibname;
                        string description;
                        int    dwHelpContext;
                        string helpStr;
                        typeLib.GetDocumentation(-1, out typelibname, out description, out dwHelpContext, out helpStr);
                        typeLibInfo.name = typelibname;
                        fileInfo.TypeLibInfo.Add(typeLibInfo.tlbid, typeLibInfo);
                    }

                    typeLib.ReleaseTLibAttr(typeLibAttribPtr);

                    int totalNoDefined = typeLib.GetTypeInfoCount();

                    for (int typeIndex = 0; typeIndex < totalNoDefined; typeIndex++)
                    {
                        ITypeInfo typeInfo;
                        typeLib.GetTypeInfo(typeIndex, out typeInfo);

                        IntPtr typeAttrPtr;
                        typeInfo.GetTypeAttr(out typeAttrPtr);

                        if (typeAttrPtr != IntPtr.Zero)
                        {
                            var typeAttr = Marshal.PtrToStructure <System.Runtime.InteropServices.ComTypes.TYPEATTR>(typeAttrPtr);
                            if (typeAttr.typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_COCLASS)
                            {
                                ComClassRegInfo coClassInfo;
                                string          clsid = typeAttr.guid.ToString("B");
                                if (!_allRegComClasses.TryGetValue(clsid, out coClassInfo))
                                {
                                    coClassInfo       = new ComClassRegInfo();
                                    coClassInfo.clsid = clsid;
                                }
                                string className;
                                string description;
                                int    dwHelpContext;
                                string helpStr;
                                typeInfo.GetDocumentation(-1, out className, out description, out dwHelpContext, out helpStr);
                                coClassInfo.tlbid       = typeLibInfo.tlbid;
                                coClassInfo.description = description;
                                coClassInfo.name        = className;
                                if (string.IsNullOrWhiteSpace(coClassInfo.progid))
                                {
                                    coClassInfo.AddProgId(string.Format("{0}.{1}", typeLibInfo.name, className));
                                }
                                fileInfo.ComClassInfo.Add(clsid, coClassInfo);
                            }
                            else if (typeAttr.typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_INTERFACE ||
                                     typeAttr.typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH)
                            {
                                ComInterfaceExternalProxyStubRegInfo proxyStub;
                                string clsid = typeAttr.guid.ToString("B");
                                if (!_allRegComInterfaceExternalProxyStub.TryGetValue(clsid, out proxyStub))
                                {
                                    proxyStub     = new ComInterfaceExternalProxyStubRegInfo();
                                    proxyStub.iid = clsid;
                                    if (typeAttr.wTypeFlags == System.Runtime.InteropServices.ComTypes.TYPEFLAGS.TYPEFLAG_FDUAL ||
                                        typeAttr.wTypeFlags == System.Runtime.InteropServices.ComTypes.TYPEFLAGS.TYPEFLAG_FOLEAUTOMATION)
                                    {
                                        //Just add std automation proxy
                                        proxyStub.proxyStubClsid32 = "{00020424-0000-0000-C000-000000000046}";
                                    }
                                }
                                string interfaceName;
                                string description;
                                int    dwHelpContext;
                                string helpStr;
                                typeInfo.GetDocumentation(-1, out interfaceName, out description, out dwHelpContext, out helpStr);
                                proxyStub.tlbid = typeLibInfo.tlbid;
                                proxyStub.name  = interfaceName;
                                fileInfo.InterfaceInfo.Add(clsid, proxyStub);
                            }
                        }

                        typeInfo.ReleaseTypeAttr(typeAttrPtr);
                    }
                }
            }
        }