Many applications require the ability to retrieve version information from files. This information is used for display purposes, such as showing the version number on the properties dialog box.
The Win32 API provides several functions that can be used to obtain version information. One common approach is to use the GetFileVersionInfo API.
The GetFileVersionInfo function retrieves information about a file's version resources. The steps involved in using this function are:
Once the version information is retrieved, you can use the VerQueryValue function to extract specific information. The following sample code demonstrates how to extract the product version and file version numbers:
LPSTR verData = new char[verSize]; if (GetFileVersionInfo(szVersionFile, verHandle, verSize, verData)) { if (VerQueryValue(verData, "\\", (VOID FAR* FAR*)&lpBuffer, &size)) { if (size) { VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer; if (verInfo->dwSignature == 0xfeef04bd) { TRACE("File Version: %d.%d.%d.%d\n", (verInfo->dwFileVersionMS >> 16) & 0xffff, (verInfo->dwFileVersionMS >> 0) & 0xffff, (verInfo->dwFileVersionLS >> 16) & 0xffff, (verInfo->dwFileVersionLS >> 0) & 0xffff ); } } } }
By following these steps, you can programmatically obtain the product version and file version numbers for DLLs or EXE files using Win32 native APIs in C or C .
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3