Home > Article > Backend Development > How to Retrieve Version Information from DLLs and EXEs using Win32 APIs?
Retrieving Version Information from DLLs and EXEs using Win32 APIs
When dealing with DLLs and EXEs, there often arises a need to obtain their version numbers. In contrast to the Windows version, this four-part dotted version (e.g., x.x.x.x) is accessible via the file's "Details" tab in its properties.
Solution: GetFileVersionInfo API
The key to retrieving version information programmatically lies in the GetFileVersionInfo API. Detailed documentation is available on Microsoft's MSDN website under the aptly titled "Using Version Information."
Sample Implementation
In C or C , a typical implementation might resemble the following code:
<code class="c++">DWORD verHandle = 0; UINT size = 0; LPBYTE lpBuffer = NULL; DWORD verSize = GetFileVersionInfoSize(szVersionFile, &verHandle); if (verSize != NULL) { 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 ); } } } } delete[] verData; }</code>
Remember to adjust 'szVersionFile' with the actual path and filename of the DLL or EXE you want to inspect.
The above is the detailed content of How to Retrieve Version Information from DLLs and EXEs using Win32 APIs?. For more information, please follow other related articles on the PHP Chinese website!