• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            S.l.e!ep.¢%

            像打了激速一樣,以四倍的速度運轉,開心的工作
            簡單、開放、平等的公司文化;尊重個性、自由與個人價值;
            posts - 1098, comments - 335, trackbacks - 0, articles - 1
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            Introduction

            There are several good articles here about reading module version information (by shaman74 and Armen Hakobyan), also there are some about modifying RC files during the build process (by Srinivas Vaithianathan and gugulea).

            But sometimes, one needs to modify the version information in a compiled executable(s) or DLL:

            • Change product name, company name, comments, etc. when deploying multiple products under different names (different skins, branding, resources) but same code;
            • Update DLL version numbers without having to modify dozens of RC files;
            • Modify a self-extractable archive's (simple installers) resources to reflect the product name and the version information of the contained application.

            Description

            This library provides an easy way to read, modify, and save version information resource(s) (RT_VERSION) in compiled executable modules (EXE, DLL, OCX, SCR, etc.).

            Collapse Copy Code
            CVersionInfo vi(strModulePath);
            //Initialize version information object, //load first RT_VERSION resource// Set file version in both VS_FIXEDFILEINFO// and in all string tables// FileVersion string will be set// to "4, 5, 0, 3" just like VS does
            vi.SetFileVersion(4, 5, 0, 3, 
                   TRUE /*Update StringTables*/);
            
            // Alternatively, if you need to set// non-numeric version number// like 4.5.0.3452Rus.RelB.MFC7 use// vi["FileVersion"] = "4.5.0.3452Rus.RelB.MFC7"// Set Comments string
            vi["Comments"] = "We will stick to C++";
            
            // Save modified version information to module,// resource id, and language// that we CVersionInfo from
            vi.Save();

            Classes exported from VerLibInfo

            • CVersionInfo - The main class; reads and writes complete version information resources to/from modules. Contains CStringFileInfo and VS_FIXEDFILEINFO. The VarFileInfo structure is not a part of this object, because it is basically computed data. When saving modified version information, proper VarFileInfo is calculated from the number of string tables and their language-codepage keys.
            • CStringFileInfo - The wrapper for the StringFileInfo structure (contains string tables for different translations of the version information).
            • CStringTable- The wrapper for the string-table structure (contains the actual name-value pairs).
            • CVersionInfoString - The wrapper for the string structure.

            CVersionInfo reference

            Collapse Copy Code
            				//
            				 Construction/Destruction
            				//
            				 Construct uninitialized empty
            				//
            				 version information object
            CVersionInfo(); 
            
            // Construct object, populate structures// from RT_VERSION resource of a given module
            CVersionInfo(const CString& strModulePath, 
                         LPCTSTR lpszResourceId = NULL /*Auto*/, 
                         WORD wLangId = 0xFFFF /*Auto*/);
            virtual ~CVersionInfo();
            
            //Read version information from module
            BOOL FromFile(const CString& strModulePath, 
                 LPCTSTR lpszResourceId = NULL /*Auto*/, 
                 WORD wLangId = 0xFFFF /*Auto*/);
            
            //Save version information to module resource //(specify strModulePath, lpszResourceId & wLangId //to copy resource to different module, resource, language)
            BOOL ToFile(const CString& strModulePath = "", 
                 LPCTSTR lpszResourceId = NULL /*Auto*/, 
                 WORD wLangId = 0xFFFF /*Auto*/);
            
            //Quick save (saves to the same module, resource, //and language that it was loaded from)
            BOOL Save();
            
            //Resets (removes all string tables //and cleans fixed version info)void Reset();
            
            // Validates object (mostly used to verify //that version information was //successfully loaded from module)
            BOOL IsValid() const;
            
            // Get/Set the order of blocks //(Regular (TRUE) = StringFileInfo first, VarFileInfo 2nd)
            BOOL GetInfoBlockOrder() const;
            void SetInfoBlockOrder(BOOL bRegularStringsFirst);
            
            // Get reference to CStringFileInfo const CStringFileInfo& GetStringFileInfo() const;
            CStringFileInfo& GetStringFileInfo();
            
            // Overloaded bracket operators allow //quick access to first string table in StringFileInfo r/wconst CString operator [] (const CString &strName) const;
            CString &operator [] (const CString &strName);
            
            // Get reference to VS_FIXEDFILEINFOconst VS_FIXEDFILEINFO& GetFixedFileInfo() const;
            VS_FIXEDFILEINFO& GetFixedFileInfo();
            
            // SetFileVersion - Updates file version //in VS_FIXEDFILEINFO and in string tables //when bUpdateStringTables == TRUEvoid SetFileVersion(WORD dwFileVersionMSHi, 
                                WORD dwFileVersionMSLo, 
                                WORD dwFileVersionLSHi, 
                                WORD dwFileVersionLSLo, 
                                BOOL bUpdateStringTables = TRUE);
            void SetFileVersion(DWORD dwFileVersionMS, 
                                DWORD dwFileVersionLS, 
                                BOOL bUpdateStringTables = TRUE);
            
            // SetProductVersion - Updates product version// in VS_FIXEDFILEINFO and ALL string tables// when bUpdateStringTables == TRUEvoid SetProductVersion(WORD dwProductVersionMSHi, 
                                   WORD dwProductVersionMSLo, 
                                   WORD dwProductVersionLSHi, 
                                   WORD dwProductVersionLSLo, 
                                   BOOL bUpdateStringTables = TRUE);
            void SetProductVersion(DWORD dwProductVersionMS, 
                                   DWORD dwProductVersionLS, 
                                   BOOL bUpdateStringTables = TRUE);

            Sample usage

            The attached file contains a sample project that utilizes the library (VerInfoLibTest). The test tool understands several command line parameters:

            Collapse Copy Code
            Test Application for Version Info Library
            USAGE:
            VerInfoLibTest.exe -system
            Prints out version numbers of all DLLs in Windows system folder
            
            VerInfoLibTest.exe -f <FileName>
            Prints out version info string tables of a specified module
            
            VerInfoLibTest.exe -u <FileName> <StringName> "<Value>"
            Modifies the StringName value in the first String Table 
                     in module version information
            
            EXAMPLES:
            VerInfoLibTest.exe -u mydll.dll CompanyName "New company name"
            VerInfoLibTest.exe -u mydll.dll Comments "Updated comment"
            VerInfoLibTest.exe -f mydll.dll

            The code for "-system":

            Collapse Copy Code
            WIN32_FIND_DATA FindFileData;
            HANDLE hFind;
                
            TCHAR szBuf[MAX_PATH];
            ::GetSystemDirectory(szBuf, MAX_PATH);
            CString strSystemFolder = szBuf;
            
            hFind = FindFirstFile(strSystemFolder + "\\*.dll", &FindFileData);
            
            if (hFind == INVALID_HANDLE_VALUE) 
            {
                printf ("Invalid File Handle. ""Get Last Error reports %d\n", 
                        GetLastError ());
            } 
            else 
            {
                do
                {
                    CString strModulePath = strSystemFolder + 
                               "\\" + FindFileData.cFileName;
            
                    const CVersionInfo vi(strModulePath);
                    
                    if (vi.IsValid())
                    {
                        _tprintf(_T("%s\t%s\n"), 
                                 FindFileData.cFileName, 
                                 vi["FileVersion"]);
                    }
                    
                }
                while (FindNextFile(hFind, &FindFileData));
                
                FindClose(hFind);
            }

            The code for "-f <FileName>":

            Collapse Copy Code
            				const CVersionInfo vi(strFilePath);
            if (vi.IsValid())
            {
                POSITION posTable = 
                  vi.GetStringFileInfo().GetFirstStringTablePosition();
                while (posTable)
                {
                    const CStringTable &st = 
                          *vi.GetStringFileInfo().GetNextStringTable(posTable);
                    
                    _tprintf(_T("String table %s\n-----") 
                             _T("-------------------------\n"), 
                             st.GetKey());
                    
                    POSITION posString = st.GetFirstStringPosition();
                    
                    while (posString)
                    {
                        const CVersionInfoString &vistr = 
                                 *st.GetNextString(posString);
                        _tprintf(_T("%s=%s\n"), vistr.GetKey(), 
                                             vistr.GetValue());
                    }
                    _tprintf(_T("------------------------------\n"));
                }
            }
            else
            {
                _tprintf(_T("Failed to get module version") 
                         _T(" information for %s\n"), strFilePath);
            }

            This will produce an output similar to:

            Collapse Copy Code
            C:\...eProject\Article1\Output\Release>
                       VerInfoLibTest.exe -f VerInfoLib.dll
            String table 040904b0
            ------------------------------
            Comments=
            CompanyName=Denis Zabavchik
            FileDescription=VerInfoLib DLL
            FileVersion=1, 0, 0, 1
            InternalName=VerInfoLib
            LegalCopyright=Copyright (C) 2006
            LegalTrademarks=
            OriginalFilename=VerInfoLib.DLL
            PrivateBuild=
            ProductName=VerInfoLib Dynamic Link Library
            ProductVersion=1, 0, 0, 1
            SpecialBuild=
            ------------------------------

            The code for updating a given string is very neat (-u <FileName> <StringName> "<Value>"):

            Collapse Copy Code
            				if (!_tcscmp(argv[1], _T("-u")))
            {
                // 2nd argument is the file path
                CString strFilePath(argv[2]);
                CVersionInfo vi(strFilePath);
                vi[argv[3]] = argv[4];
                
                vi.Save();
            }

            Notes

            The code compiles and works in VC6 and 2005 (both MBCS and UNICODE are supported). MFC is used for the container classes, maps etc. The code can be easily ported to be used without MFC.

            License

            This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

            About the Author

            Denis Zabavchik


            Member

            Occupation: Software Developer (Senior)
            Location: Russian Federation Russian Federation
            MM131亚洲国产美女久久| 香蕉久久一区二区不卡无毒影院 | 精品久久777| 国产成人精品久久| 欧美日韩精品久久免费| 婷婷伊人久久大香线蕉AV| 青青草国产精品久久久久| 色婷婷综合久久久久中文字幕 | 国产精品久久自在自线观看| 久久精品成人影院| 久久国产精品一国产精品金尊 | 亚洲国产美女精品久久久久∴ | 久久国产高潮流白浆免费观看| 2021国产成人精品久久| 久久亚洲日韩看片无码| 免费观看久久精彩视频| 久久婷婷五月综合97色一本一本 | 狠狠综合久久综合中文88| A级毛片无码久久精品免费| 久久国产精品成人免费| 97精品国产97久久久久久免费| 久久播电影网| 99久久精品免费| 久久99精品国产一区二区三区| 日日狠狠久久偷偷色综合免费| 日韩一区二区久久久久久 | 久久国产午夜精品一区二区三区| 午夜人妻久久久久久久久| 久久99精品久久久久久秒播| 久久精品国产99国产精偷| 亚洲国产精品无码久久久不卡| 亚洲国产天堂久久综合| 久久久99精品一区二区| 精品多毛少妇人妻AV免费久久| 久久中文字幕一区二区| 国产产无码乱码精品久久鸭| 久久无码人妻一区二区三区 | 国内精品久久久久久久涩爱| 久久久久久午夜成人影院| 久久精品无码专区免费青青| 欧美黑人又粗又大久久久|