02-13-2014 03:35 AM
I Need to control every compilation releasement to manage the updates and use the Version information. How can I extract the Automatic Version number into a Report or a variable.
02-13-2014 03:48 AM
Hello Arturo,
You can do something like that:
//Recupération des informations du fichier
char *GetInfo(char *InfoItem)
{
static char szResult[256] = {0};
char szFullPath[256];
char szGetName[256];
LPSTR lpVersion; // String pointer to Item text
DWORD dwVerInfoSize; // Size of version information block
DWORD dwVerHnd=0; // An 'ignored' parameter, always '0'
UINT uVersionLen;
BOOL bRetCode;
GetModuleFileName (NULL, szFullPath, sizeof(szFullPath));
dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
if (dwVerInfoSize) {
LPSTR lpstrVffInfo;
HANDLE hMem;
hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
lpstrVffInfo = (LPSTR)GlobalLock(hMem);
GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpstrVffInfo);
// Get a codepage from base_file_info_sctructure
lstrcpy(szGetName, "\\VarFileInfo\\Translation");
uVersionLen = 0;
lpVersion = NULL;
bRetCode = VerQueryValue((LPVOID)lpstrVffInfo,
(LPSTR)szGetName,
(void **)&lpVersion,
(UINT *)&uVersionLen);
if ( bRetCode && uVersionLen && lpVersion) {
sprintf(szResult, "%04x%04x", (WORD)(*((DWORD *)lpVersion)),
(WORD)(*((DWORD *)lpVersion)>>16));
// lstrcpy(szResult, lpVersion);
}
else {
// 041904b0 is a very common one, because it means:
// US English/Russia, Windows MultiLingual characterset
// Or to pull it all apart:
// 04------ = SUBLANG_ENGLISH_USA
// --09---- = LANG_ENGLISH
// --19---- = LANG_RUSSIA
// ----04b0 = 1200 = Codepage for Windows:Multilingual
lstrcpy(szResult, "041904b0");
}
// Add a codepage to base_file_info_sctructure
sprintf (szGetName, "\\StringFileInfo\\%s\\", szResult);
// Get a specific item
lstrcat (szGetName, InfoItem);
uVersionLen = 0;
lpVersion = NULL;
bRetCode = VerQueryValue((LPVOID)lpstrVffInfo,
(LPSTR)szGetName,
(void **)&lpVersion,
(UINT *)&uVersionLen);
if ( bRetCode && uVersionLen && lpVersion) {
lstrcpy(szResult, lpVersion);
}
else {
lstrcpy(szResult, "");
}
}
return szResult;
}
and then use it as here under:
//Recupération de la version de l'exe
sprintf(titre,"%s", GetInfo("ProductName"));
SetSystemAttribute (ATTR_TASKBAR_BUTTON_TEXT, GetInfo("ProductName"));
sprintf(titre,"%s %s", titre, GetInfo("ProductVersion"));
sprintf(titre,"%s %s", titre, GetInfo("Comments"));
SetPanelAttribute (g_iMainPanel, ATTR_TITLE, titre);
see ms link : http://msdn.microsoft.com/en-us/library/windows/desktop/ms647464(v=vs.85).aspx
02-13-2014 06:24 AM
the problem is that you gave the path of the element that you want to get info from, but, I want to get the application itself to say hey this is my version. or compilation date. or something like that. to make it automatically then this value is set into a result file and the this result file is compared with a @golden@ or known result value and we can check if the application was compiled from another person or modified without changing the limit file or compared file.
02-13-2014 07:42 AM
There are some predefine Macros that you can use. Once you have them in a buffer you can write them to a file or compare them to you golden data.
sprintf(caMessage, "%d", _CVI_);
SetCtrlVal(ghAboutPanel, ABOUT_CVI_VERSION, caMessage);
sprintf(caMessage, "%s", COMPILE_DATE);
SetCtrlVal(ghAboutPanel, ABOUT_COMPILEDATE, caMessage);
sprintf(caMessage, "%s", _TARGET_FILE_VERSION_);
SetCtrlVal(ghAboutPanel, ABOUT_FILEVERSION, caMessage);
There is also the GetCVIVersion(); function.
Paul