Why does my function return an incorrect file version number? [closed]

  api, c++, windows

I have a function to output the version number of a file using the GetFileVersionInfo windows API.

#include "Windows.h"
#include <tchar.h>
#include <stdio.h>

void getFileVersionNum()
{
LPTSTR lpszFilePath = "pathname";
DWORD dwDummy;
DWORD dwFVISize = GetFileVersionInfoSize(lpszFilePath, &dwDummy);
LPBYTE lpVersionInfo = new BYTE[dwFVISize];

GetFileVersionInfo(lpszFilePath, 0, dwFVISize, lpVersionInfo);

UINT uLen;
VS_FIXEDFILEINFO *lpFfi;

VerQueryValue(lpVersionInfo, _T(""), (LPVOID *)&lpFfi, &uLen);
DWORD dwFileVersionMS = lpFfi->dwFileVersionMS;
DWORD dwFileVersionLS = lpFfi->dwFileVersionLS;
delete[] lpVersionInfo;

DWORD dwLeftMost = HIWORD(dwFileVersionMS);
DWORD dwSecondLeft = LOWORD(dwFileVersionMS);
DWORD dwSecondRight = HIWORD(dwFileVersionLS);
DWORD dwRightMost = LOWORD(dwFileVersionLS);

printf("Version: %d.%d.%d.%dn", dwLeftMost, dwSecondLeft, dwSecondRight, dwRightMost);
}

For every file I test, I get the same version number every time: 52428.52428.21641.18636

What is the significance of these numbers?

I test a file with version number 1.4.0.0 and the output shows 52428.52428.21641.18636

I test a file with no version number, still 52428.52428.21641.18636

How can I fix this problem?

Source: StackOverflow

LEAVE A COMMENT