Ejemplo n.º 1
0
 private void ParseInterface(TreeNode node, out ComInterfaceExternalProxyStubRegInfo externalProxyStub, out ComInterfaceProxyStubRegInfo proxyStub)
 {
     externalProxyStub                  = new ComInterfaceExternalProxyStubRegInfo();
     externalProxyStub.iid              = node.Text;
     proxyStub                          = new ComInterfaceProxyStubRegInfo();
     proxyStub.iid                      = node.Text;
     externalProxyStub.name             = node.GetNodeValue();
     proxyStub.name                     = externalProxyStub.name;
     externalProxyStub.proxyStubClsid32 = node.GetNodeValue("ProxyStubClsid32");
     proxyStub.proxyStubClsid32         = externalProxyStub.proxyStubClsid32;
     externalProxyStub.tlbid            = node.GetNodeValue("TypeLib");
     proxyStub.tlbid                    = externalProxyStub.tlbid;
 }
Ejemplo n.º 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);
                    }
                }
            }
        }