コード例 #1
0
ファイル: ComRegInfo.cs プロジェクト: bofhbug/privateprj
        private void ParseTypeLib(TreeNode node, out Dictionary <string, ComTypeLibRegInfo> comClassRegInfoList)
        {
            comClassRegInfoList = new Dictionary <string, ComTypeLibRegInfo>(StringComparer.InvariantCultureIgnoreCase);
            foreach (TreeNode subItem in node.Nodes)
            {
                if (subItem.Tag == null)
                {
                    var comClassRegInfo = new ComTypeLibRegInfo();
                    comClassRegInfo.tlbid   = node.Text;
                    comClassRegInfo.version = subItem.Text;
                    string typeLibFile = string.Empty;
                    foreach (TreeNode subSubItem in subItem.Nodes)
                    {
                        if (subSubItem.Text == "FLAGS")
                        {
                            comClassRegInfo.flags = subSubItem.GetNodeValue();
                        }
                        else if (subSubItem.Text == "HELPDIR")
                        {
                            comClassRegInfo.helpdir = subSubItem.GetNodeValue();
                        }
                        else
                        {
                            string tempFile = subSubItem.GetNodeValue("win32");
                            if (string.IsNullOrWhiteSpace(tempFile))
                            {
                                tempFile = subSubItem.GetNodeValue("win64");
                            }
                            int startPos = tempFile.LastIndexOf('\\');
                            if (startPos != -1)
                            {
                                typeLibFile = tempFile.Substring(startPos + 1);
                            }
                            else
                            {
                                typeLibFile = tempFile;
                            }
                        }
                    }

                    if (!comClassRegInfoList.ContainsKey(typeLibFile))
                    {
                        comClassRegInfoList.Add(typeLibFile, comClassRegInfo);
                    }
                }
            }
        }
コード例 #2
0
ファイル: ComRegInfo.cs プロジェクト: bofhbug/privateprj
        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);
                    }
                }
            }
        }