retrieving windows VS_VERSIONINFO struct from a binary

Reading the version information from a windows binary is a non trivial task.  The version information is stored in the resource file in a bit-wise fashion.  this means that all the information as you read it in the resource file is laid out the same way in binary form when it is compiled into the application resources.  I wrote this sample because I didn’t find any sample code that correctly handles the windows Multi-byte and Unicode character sets without significant modifications.

Below is a typical version block as you see it in the resource file.  The version block is divided into two parts.  the fixed version info, the information in the resource version structure that is language independent, and the string block information that we are interested in retrieving.

The fixed version info is this part of the version information.  In this section we have numerical representations of the file and product version along with a bit mask that identifies the properties of the binary.  the file mask values tell you what kind of binary you have (DLL, EXE, lib, etc…) and which operating system is supported, and other information that can be view off of MSDN here: Resource VERSION block

The string block section is defined below. Each string block will have a unique entry for each language supported.  The string block is a variable length block whos length is determined by the length of the strings in the block, and by how many languages are supported for the binary.

The string block itself is divided into block sections  identified by each langauge supported.  The languages are identified by the language identifier string



This information is compiled into the resources or in a resource DLL during compilation in the order in which it was entered.  In early versions of windows you had to manually set a pointer to the resource block your wanted and manually parse the version structure to retrieve the information you wanted.  Beginning with windows 2000, a version API was introduced to make it easier to access the version information stored in the resources.  For this sample, we are only interested in 3 functions GetFileVersionInfoSize, GetFileVersionInfo, and VerQueryValue.  The rest of the version API relates to install and upgrade mechanisms to assist the installer during install or an upgrade of the binary files.  The steps to retrieve the version info structure is very straight forward.

  • determine the size of the version info structure
  • allocate a pointer to hold the version info
  • retrieve the version info structure and all it’s data
  • search it for the values you want.

First we get the file name of the component we want to access the version information.

Now we allocate a memory block large enough to hold the version information.

Once we have the memory allocated, we retrieve the version information.

Once we have the version info structure, we need to parse the version information to see if our desired language is defined, if not, we default to english using your default language identifier.

Here is the complete function.  This function has been tested in Multi-byte and Unicode build environments.  If you search the internet hard enough (and it’s not that hard) you can find many samples that demonstrate this technique.  I borrowed from several different samples to build this function.  This sample however, is the only sample that I have found that deals with Unicode and Multi-byte characters with no code changes.  The string that you have queried is returned in a CString class object that is defined for ATL and MFC.

Feel free to use this code at your discretion, use this code at your own risk.

links and other references:



VS_VERSIONINFO structure
VerQueryValue function
GetFileVersionInfoSize function
GetFileVersionInfo function

3 thoughts on “retrieving windows VS_VERSIONINFO struct from a binary

  1. I cannot get this to work in Visual Studio 2015 after upgrading project from 2010. It works in VS2010

Comments are closed.