06-25-2002 07:22 PM
06-26-2002 02:48 AM
06-26-2002 06:38 AM
08-21-2008 04:03 PM
I was recently trying to do this, and the example in the Windows SDK is less than clear - so here's what I ended up with that gets the version information from the FileInfo Structure.
DWORD size;
LPTSTR *version;
UINT versionLen = 0;
BOOL status = FALSE;
UINT ver1 = 0;
UINT ver2 = 0;
UINT ver3 = 0;
UINT ver4 = 0;
size = GetFileVersionInfoSize (argv[0], 0);
if (!size)
{
error.flag = TRUE;
error.code = GetLastError ();
goto Error;
}
version = calloc (size + 1, sizeof (char));
status = GetFileVersionInfo (argv[0], 0, size, version);
status = VerQueryValue (version, "\\", (LPVOID*)&fileInfo, &versionLen);
if (status)
{
ver1 = HIWORD(fileInfo->dwFileVersionMS);
ver2 = LOWORD(fileInfo->dwFileVersionMS);
ver3 = HIWORD(fileInfo->dwFileVersionLS);
ver4 = LOWORD(fileInfo->dwFileVersionLS);
}
Hope this help those who don't use the SDK often...
-Jack
08-22-2008 02:55 AM
beware of the current path when using argv[0]. sometimes the filename specified in argv[0] does not include the full path (executable launched from console, ...). in this case, GetFileVersionInfo will search the file on the current path, which may no more be the path where the file resides (expecially if you used the CVI open file dialog).
to get the fully qualified path to the current executable, you should use GetModuleFileName( NULL ).
08-22-2008 10:36 AM
Thanks for the clarification - Just for completness I also forgot to add the definition of the variable "fileInfo"; it's:
VS_FIXEDFILEINFO *fileInfo;
Sorry about that.
-Jack