The software needs to be updated, and the DLL or EXE version must be modified. It is often dependent on IDE such as vs2008 and then compiled and generated.
The following describes how to modify the version number by modifying the binary file in the code area.
The main steps are as follows:
1. Get the file header information size
2. Get the file header information
3. Use the verqueryvalue function to obtain language information based on the obtained information.
4. Use the verqueryvalue function to obtain other information, such as file version information and product version information, based on the obtained information.
5. Modify the memory content based on the obtained version information.
6. Use beginupdateresource, updateresource, and endupdateresource to update resources.
------------------------------------------------------------------------------
The following is the main code:
The cversion class divides the input string information into four digits. The version. getversion (1) in the code is used to obtain the 2nd bits of the version.
# Include "stdafx. h "# include <Windows. h> # include "Version. h "typedef struct _ tagLanguage {WORD wLanguage; WORD wCodePage;} tagLanguage, * LPLanguage; int _ tmain (int argc, _ TCHAR * argv []) {if (argc! = 3) {return 0;} TCHAR * FileName = argv [1]; TCHAR * Version = argv [2]; // CVersion class, convert the version information of the string "1234,456,789,111 0" to a number. You can write the code CVersion Version (version); DWORD dwVerHnd = 0; // obtain the size of the entire file version information DWORD dwVerInfoSize = GetFileVersionInfoSize (FileName, & dwVerHnd); // apply for memory TCHAR * VerInfo = new TCHAR [dwVerInfoSize] based on the size; // obtain the file version information. The information is stored in the memory you just applied for. Modify the version information by directly modifying the memory, and then update the version information BOOL res = GetFileVersionInfo (FileName, 0, dwVerInfo Size, VerInfo); if (! Res) {delete [] VerInfo; return 0;} // read the language information in the obtained version information first, Because LPLanguage language = NULL is required to modify the version information; UINT size = 0; VerQueryValue (VerInfo, _ T ("\ VarFileInfo \ Translation"), (LPVOID *) & language, & size ); // read the file version information VS_FIXEDFILEINFO * FixedFileInfo = NULL; VerQueryValue (VerInfo, _ T ("\"), (LPVOID *) & FixedFileInfo, & size ); TCHAR TempBuf [MAX_PATH] = {0}; if (FixedFileInfo) {// modify the version number of the file version information. Here, the numbers "1234", "456" are obtained through the CVersion class, respectively ", "789", "111" 0 "// here you need to combine the high and low positions FixedFileInfo-> dwFileVersionMS = MAKELONG (version. getVersion (1), version. getVersion (0); FixedFileInfo-> dwFileVersionLS = MAKELONG (version. getVersion (3), version. getVersion (2); FixedFileInfo-> dwProductVersionMS = MAKELONG (version. getVersion (1), version. getVersion (0); FixedFileInfo-> dwProductVersionMS = MAKELONG (version. getVersion (3), version. getVersion (2);} // read information in StringFileInfo TCHAR * ProductVer = NULL; TCHAR * FileVer = NULL; _ stprintf_s (TempBuf, _ T ("\ StringFileInfo \ % 04x % 04x \ FileVersion"), language-> wLanguage, language-> wCodePage); VerQueryValue (VerInfo, TempBuf, (LPVOID *) & FileVer, & size); _ stprintf_s (TempBuf, _ T ("\ StringFileInfo \ % 04x % 04x \ ProductVersion"), language-> wLanguage, language-> wCodePage); VerQueryValue (VerInfo, TempBuf, (LPVOID *) & ProductVer, & size); size_t productlength = _ tcsl En (ProductVer); size_t fileLength = _ tcslen (FileVer); if (_ tcslen (Version)> productlength) {return 0;} if (_ tcslen (Version)> fileLength) {return 0;} // modify the memory _ tcscpy_s (ProductVer, productlength + 1, Version); _ tcscpy_s (FileVer, fileLength + 1, Version ); // read and modify the above information. Here, HANDLE hResource = BeginUpdateResource (FileName, FALSE) is updated; if (NULL! = HResource) {// here the parameter is correct, that is, the original read resource. By modifying the original resource memory, res = UpdateResource (hResource, RT_VERSION, MAKEINTRESOURCE (VS_VERSION_INFO), language-> wLanguage, VerInfo, dwVerInfoSize); if (! Res) {return 0;} EndUpdateResource (hResource, FALSE);} return 0 ;}