print file version
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "Version.lib")
void PrintFileVersion(LPCTSTR szVersionFile)
{
DWORD verHandle;
UINT size = 0;
LPBYTE lpBuffer = NULL;
DWORD verSize = GetFileVersionInfoSize(szVersionFile, &verHandle);
if (verSize != 0)
{
LPSTR verData = malloc(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)
{
// Doesn't matter if you are on 32 bit or 64 bit,
// DWORD is always 32 bits, so first two revision numbers
// come from dwFileVersionMS, last two come from dwFileVersionLS
char result[sizeof(DWORD) * 4 + 4] = "";
sprintf_s(result, sizeof(result), "%d.%d.%d.%d",
(verInfo->dwFileVersionMS >> 16) & 0xffff,
(verInfo->dwFileVersionMS >> 0) & 0xffff,
(verInfo->dwFileVersionLS >> 16) & 0xffff,
(verInfo->dwFileVersionLS >> 0) & 0xffff
);
printf(result);
}
}
}
}
free(verData);
}
}
int main()
{
TCHAR* szVersionFile = "C:/WINDOWS/system32/notepad.exe";
PrintFileVersion(szVersionFile);
system("PAUSE");
}