Tried out the answers from MSDN forum & the answer mentioned in thread - How do I programmatically get the version of a DLL or EXE file? - but I always get version number as "0.0.0.0"
Right Click my DLL -> Properties -> Details -> File Version has correct value. The EXE that loads my DLL does not version info - but not sure if that would matter.
My code is below (as part of the dll)->
std::string moduleName = "<full absolute path to DLL that this code is part of>";
DWORD zero = 0;
uint32 verInfoLen = 0;
BYTE *verInfo = NULL;
VS_FIXEDFILEINFO *fileInfo = NULL;
uint32 len = 0;
/* Get the size of FileVersionInfo structure */
verInfoLen = GetFileVersionInfoSize(moduleName.c_str(), &zero);
if (verInfoLen == 0) {
printf("GetFileVersionInfoSize() Failed!");
return;
}
/* Get FileVersionInfo structure */
verInfo = new BYTE[verInfoLen];
if (!GetFileVersionInfo(moduleName.c_str(), zero, verInfoLen, verInfo)) {
printf("GetFileVersionInfo Failed!");
return;
}
/* Query for File version details. */
if (!VerQueryValue(verInfo, "\\", (LPVOID *)&fileInfo, &len)) {
printf("VerQueryValue Failed!");
return;
}
/* None of the above func calls fail - but both printf below print all zeros */
printf("Version is %d.%d.%d.%d",
(fileInfo->dwProductVersionMS >> 16) & 0xff,
(fileInfo->dwProductVersionMS >> 0) & 0xff,
(fileInfo->dwProductVersionLS >> 16) & 0xff,
(fileInfo->dwProductVersionLS >> 0) & 0xff);
printf("Version is %d.%d.%d.%d",
HIWORD(fileInfo->dwProductVersionMS),
LOWORD(fileInfo->dwProductVersionMS),
HIWORD(fileInfo->dwProductVersionLS),
LOWORD(fileInfo->dwProductVersionLS));
Any help appreciated !