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

前端 未结 7 431
情歌与酒
情歌与酒 2020-11-28 09:17

I have a version resource in my resources in a C++ project which contains version number, copyright and build details. Is there an easy way to access this at run-time to po

7条回答
  •  情歌与酒
    2020-11-28 09:45

    To get a language independent result to Mark's answer change :

       // replace "040904e4" with the language ID of your resources
        !VerQueryValue(&data[0], _T("\\StringFileInfo\\040904e4\\ProductVersion"), &pvProductVersion, &iProductVersionLen))
    {
        TRACE("Can't obtain ProductName and ProductVersion from resources\n");
        return false;
    }
    

    To

    UINT                uiVerLen = 0;
    VS_FIXEDFILEINFO*   pFixedInfo = 0;     // pointer to fixed file info structure
    // get the fixed file info (language-independent) 
    if(VerQueryValue(&data[0], TEXT("\\"), (void**)&pFixedInfo, (UINT *)&uiVerLen) == 0)
    {
        return false;
    }
    
     strProductVersion.Format("%u.%u.%u.%u", 
        HIWORD (pFixedInfo->dwProductVersionMS),
        LOWORD (pFixedInfo->dwProductVersionMS),
        HIWORD (pFixedInfo->dwProductVersionLS),
        LOWORD (pFixedInfo->dwProductVersionLS));
    

提交回复
热议问题