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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
//-----------------------------------------------------------------------------
// Copyright (C) 2001 Radical Entertainment Ltd. All rights reserved.
//
// winutil.h
//
// Description: A set of utilities which are specific to the windows development
// environment.
//
// Modification History:
// + Created Aug 03, 2001 -- bkusy
//-----------------------------------------------------------------------------
//----------------------------------------
// System Includes
//----------------------------------------
#include <windows.h>
#include <stdio.h>
#include <assert.h>
//----------------------------------------
// Project Includes
//----------------------------------------
#include "winutil.h"
//----------------------------------------
// Constants
//----------------------------------------
#define BUFFER_SIZE 256
//-----------------------------------------------------------------------------
// w i n u t i l _ V e r s i o n I n f o
//
// Synopsis: Retrieve a version info string for the specified module.
//
// Parameters: name - the module to retrieve the information for.
// info - a reference parameter to receive the info string.
// info_size - the size of the buffer pointed to by info.
//
// Returns: the length of the string returned in info.
//
// Constraints: NONE
//
//-----------------------------------------------------------------------------
int winutil_VersionInfo( const char* name, char* info, int info_size )
{
char buffer[ BUFFER_SIZE + 1 ];
char* data = 0;
DWORD data_length, unused;
VS_FIXEDFILEINFO* fixed_file_info;
UINT fixed_file_info_length;
int major, minor;
int result;
GetModuleFileName( GetModuleHandle( name ), buffer, BUFFER_SIZE );
data_length = GetFileVersionInfoSize( buffer, &unused );
data = calloc( data_length, sizeof( char ) );
assert( data );
GetFileVersionInfo( buffer, unused, data_length, data );
VerQueryValue( data, "\\", (void**)(&fixed_file_info), &fixed_file_info_length );
major = fixed_file_info->dwFileVersionMS >> 16;
minor = fixed_file_info->dwFileVersionMS & 0x0ffff;
result = _snprintf( info, info_size, "%d.%d", major, minor );
return result;
}
|