1

Possible Duplicate:
How do I read from a version resource in Visual C++

in my c++ project i've added a .rc file where I can store the file version, the executable description, copyright, etc..

and is ok, I compile, i go to the explorer -> file property and I see all the fields in the form.

My question is: if I need to read from the project the own file version ( to show into a form for example), how can I do this?

thanks

Community
  • 1
  • 1
ghiboz
  • 7,863
  • 21
  • 85
  • 131

2 Answers2

6

Windows provides a set of API calls for retrieving the version information from executable files. The following snippet of code should help you get started.

bool GetVersionInfo(
    LPCTSTR filename,
    int &major,
    int &minor,
    int &build,
    int &revision)
{
    DWORD   verBufferSize;
    char    verBuffer[2048];

    //  Get the size of the version info block in the file
    verBufferSize = GetFileVersionInfoSize(filename, NULL);
    if(verBufferSize > 0 && verBufferSize <= sizeof(verBuffer))
    {
        //  get the version block from the file
        if(TRUE == GetFileVersionInfo(filename, NULL, verBufferSize, verBuffer))
        {
            UINT length;
            VS_FIXEDFILEINFO *verInfo = NULL;

            //  Query the version information for neutral language
            if(TRUE == VerQueryValue(
                verBuffer,
                _T("\\"),
                reinterpret_cast<LPVOID*>(&verInfo),
                &length))
            {
                //  Pull the version values.
                major = HIWORD(verInfo->dwProductVersionMS);
                minor = LOWORD(verInfo->dwProductVersionMS);
                build = HIWORD(verInfo->dwProductVersionLS);
                revision = LOWORD(verInfo->dwProductVersionLS);
                return true;
            }
        }
    }

    return false;
}
Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74
2

Use these functions on the executable:

http://msdn.microsoft.com/en-us/library/ms646981%28v=VS.85%29.aspx