Why does GetFileVersionInfo return incorrect File Versions for DLLs?

Nagy Balazs 0 Reputation points
2025-05-28T14:58:09.8833333+00:00

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:
ztrace_maps.dll 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.";
}
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,772 questions
{count} votes

1 answer

Sort by: Most helpful
  1. David Lowndes 2,630 Reputation points MVP
    2025-05-28T15:55:47.69+00:00

    Aha, if you add a manifest such as this:

    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
        <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
            <application>
                <!-- Windows 10, version 1903 -->
                <maxversiontested Id="10.0.18362.1"/>
                <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
            </application>
        </compatibility>
    </assembly>
    

    Then you get the expected 10.x values.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.