1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| #include <windows.h>
#include <stdio.h>
// Linker la librairie "version.lib" / "version.dll"
#pragma comment(lib,"version")
int main ( int argc, char* argv[] ) {
DWORD handle, len ;
UINT blen ;
LPTSTR data ;
VS_FIXEDFILEINFO* fileinfo ;
if (argc!=2) {
printf("Usage : %s <ExecutableFile>\n",argv[0]);
printf("Print the internal version of the file.\n");
printf("\n");
printf("Return values :\n");
printf("0\tNo error, version found.\n");
printf("1\tBad parameters.\n");
printf("2\tNo version info.\n");
printf("3\tNot enough memory.\n");
printf("4\tCould not read version block.\n");
printf("5\tNo version info in version block.\n");
printf("If error code >1, NOTHING is printed on console.\n");
return 1 ;
}
len = GetFileVersionInfoSize((LPCSTR)argv[1],&handle) ;
if (!len)
return 2 ;
data = (LPTSTR)malloc(len) ;
if (!data)
return 3 ;
if (!GetFileVersionInfo(argv[1],handle,len,data)) {
free(data) ;
return 4 ;
}
if (VerQueryValue(data,"\\",(LPVOID*)&fileinfo,(PUINT)&blen)) {
printf("%d.%d.%d.%d\n", HIWORD(fileinfo->dwFileVersionMS), LOWORD(fileinfo->dwFileVersionMS),
HIWORD(fileinfo->dwFileVersionLS), LOWORD(fileinfo->dwFileVersionLS)) ;
free(data) ;
return 0 ;
}
free(data) ;
return 5 ;
} |
Partager