开发者

c++ get version from .rc into code [duplicate]

开发者 https://www.devze.com 2023-03-21 22:26 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How do I rea开发者_JAVA百科d from a version resource in Visual C++
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How do I rea开发者_JAVA百科d 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


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;
}


Use these functions on the executable:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消