The goal is to retrieve the File Versions of DLLs from the file's "Properties" -> "Details" tab using the Version Information functions listed here. However, when accessing DLLs in the Windows system directories (SysWOW64 and System32), incorrect file versions are sometimes returned.
For instance, while querying "C:\Windows\SysWOW64\ztrace_maps.dll", the expected version is "10.0.22621.2506", but instead, "6.2.22621.2506" is received.
What could be causing this discrepancy, and what solutions are available? Further details are provided below.
The example dll's properties:
The function in my code that I'm using:
std::wstring GetFileInfo(const std::wstring& filePath, bool getFileVersion) {
DWORD handle = 0;
DWORD size = GetFileVersionInfoSize(filePath.c_str(), &handle);
if (size == 0) {
return L"Error: Unable to get version info size.";
}
std::vector<char> buffer(size);
if (!GetFileVersionInfo(filePath.c_str(), handle, size, buffer.data())) {
return L"Error: Unable to get version info.";
}
VS_FIXEDFILEINFO* fileInfo = nullptr;
UINT len = 0;
if (!VerQueryValue(buffer.data(), L"\\", reinterpret_cast<LPVOID*>(&fileInfo), &len)) {
return L"Error: Unable to query version info.";
}
if (fileInfo) {
DWORD versionMS = getFileVersion ? fileInfo->dwFileVersionMS : fileInfo->dwProductVersionMS;
DWORD versionLS = getFileVersion ? fileInfo->dwFileVersionLS : fileInfo->dwProductVersionLS;
return ToWString((versionMS >> 16) & 0xffff) + L"." +
ToWString((versionMS >> 0) & 0xffff) + L"." +
ToWString((versionLS >> 16) & 0xffff) + L"." +
ToWString((versionLS >> 0) & 0xffff);
}
return L"Error: Version info not found.";
}