Home > Article > Backend Development > How can I retrieve version information from DLLs and EXEs using Win32 API in C or C ?
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 .
The above is the detailed content of How can I retrieve version information from DLLs and EXEs using Win32 API in C or C ?. For more information, please follow other related articles on the PHP Chinese website!