Reputation: 588
Referencing to this answer I'm trying to get ProductVersion with windows Api using GetFileVersionInfo method. The problem is that through the propreties of .exe ProductVersion is visible, but programmatically I get only "0.0.0.0".
.exe propreties:
output:
Code:
printf( "File Version 1: %d.%d.%d.%d\n",
( verInfo->dwFileVersionMS >> 16 ) & 0xffff,
( verInfo->dwFileVersionMS >> 0 ) & 0xffff,
( verInfo->dwFileVersionLS >> 16 ) & 0xffff,
( verInfo->dwFileVersionLS >> 0 ) & 0xffff
);
printf( "File Version 2: %d.%d.%d.%d\n",
( verInfo->dwFileVersionLS >> 24 ) & 0xff,
( verInfo->dwFileVersionLS >> 16 ) & 0xff,
( verInfo->dwFileVersionLS >> 8 ) & 0xff,
( verInfo->dwFileVersionLS >> 0 ) & 0xff
);
printf( "Product Version 1: %d.%d.%d.%d\n",
( verInfo->dwProductVersionLS >> 24 ) & 0xff,
( verInfo->dwProductVersionLS >> 16 ) & 0xff,
( verInfo->dwProductVersionLS >> 8 ) & 0xff,
( verInfo->dwProductVersionLS >> 0 ) & 0xff
);
printf( "Product Version 2: %d.%d.%d.%d\n",
(verInfo->dwProductVersionMS >> 16) & 0xffff,
(verInfo->dwProductVersionMS >> 0) & 0xffff,
(verInfo->dwProductVersionLS >> 16) & 0xffff,
(verInfo->dwProductVersionLS >> 0) & 0xffff
);
printf( "Product Version 3: %d.%d.%d.%d\n",
(verInfo->dwProductVersionMS >> 16) & 0xffff,
(verInfo->dwProductVersionMS >> 8) & 0xffff,
(verInfo->dwProductVersionLS >> 16) & 0xffff,
(verInfo->dwProductVersionLS >> 8) & 0xffff
);
The question is - WTF? How to get ProductVersion, and how do the guys from Microsoft did that?
Upvotes: 2
Views: 4442
Reputation: 1515
this worked on my end
fwprintf(f_output, L"// File Version:\t\t\t%d.%d.%d.%d\n",
(verInfo->dwFileVersionMS >> 16) & 0xffff,
(verInfo->dwFileVersionMS >> 0) & 0xffff,
(verInfo->dwFileVersionLS >> 16) & 0xffff,
(verInfo->dwFileVersionLS >> 0) & 0xffff
);
fwprintf(f_output, L"// Product Version:\t\t\t%d.%d.%d.%d\n",
(verInfo->dwProductVersionMS >> 16) & 0xffff,
(verInfo->dwProductVersionMS >> 0) & 0xffff,
(verInfo->dwProductVersionLS >> 16) & 0xffff,
(verInfo->dwProductVersionLS >> 0) & 0xffff
);
Upvotes: 2
Reputation: 588
Here is the code snippet for those who also trying to get the ProductVersion:
if (!VerQueryValue (lpData, TEXT("\\StringFileInfo\\040904E4\\ProductVersion"),
(LPVOID) &lpBuffer, (PUINT) &BufLen)) {
/* language ID 040904E4: U.S. English, char set = Windows, Multilingual */
printf ("ProductVersion: not found\n");
}
else
printf ("ProductVersion: %s\n", lpBuffer);
Here is Full Code.
Upvotes: 0
Reputation: 101569
The version info resource contains a small fixed portion (VS_FIXEDFILEINFO
) and optionally some strings.
Some applications display the numbers from the fixed portion and some use the FileVersion/ProductVersion strings.
You should probably use the string if it is present because it allows the developer to add extra pieces of information like Alpha/Beta etc. and because some people forget to properly set the correct version in the fixed part.
Use the VerQueryValue
function to get a list of languages and the strings...
Upvotes: 1