how to use the GetFileVersionInfo function?

18,598

The file version information is of variable length. It contains a number of different pieces of information. The total length of all these different pieces is given by the return value of GetFileVersionInfoSize.

When you call VerQueryValue you are asking for a specific individual piece of information within the overall version information. And the length of that specific part can never be larger that the overall size.

The documentation for VerQueryFile contains sample code that extracts the file description.

Share:
18,598
user1386966
Author by

user1386966

Updated on June 04, 2022

Comments

  • user1386966
    user1386966 almost 2 years

    I have this code - that is returning the file version (into a struct) I'm using as example the shell32.dll but there are some values that I don't understand their meanings , and would love to get an explanation.

    here is the code :

    void GetFileVersion( PCHAR pFilePath  ,PVERSION pRetVersion)
    {
    DWORD               dwSize              = 0;
    BYTE                *pVersionInfo       = NULL;
    VS_FIXEDFILEINFO    *pFileInfo          = NULL;
    UINT                pLenFileInfo        = 0;
    
    
    /*getting the file version info size */
    dwSize = GetFileVersionInfoSize( pFilePath, NULL );
    if ( dwSize == 0 )
    {
        printf( "Error in GetFileVersionInfoSize: %d\n", GetLastError() );
        return;
    }
    
    pVersionInfo = new BYTE[ dwSize ]; /*allocation of space for the verison size */
    
    if ( !GetFileVersionInfo( pFilePath, 0, dwSize, pVersionInfo ) ) /*entering all info     data to pbVersionInfo*/
    {
        printf( "Error in GetFileVersionInfo: %d\n", GetLastError() );
        delete[] pVersionInfo;
        return;
    }
    
    if ( !VerQueryValue( pVersionInfo, TEXT("\\"), (LPVOID*) &pFileInfo, &pLenFileInfo ) )
    {
        printf( "Error in VerQueryValue: %d\n", GetLastError() );
        delete[] pVersionInfo;
        return;
    }
    
    
    /*checking if the allocation succeeded */
    if (NULL == pRetVersion)
    {
        printf("Allocation failed! \n" , GetLastError());
        return;
    }
    
    
    pRetVersion->major  =  ( pFileInfo->dwFileVersionMS >> 16 ) & 0xffff ;
    pRetVersion->minor  =  ( pFileInfo->dwFileVersionMS) & 0xffff;
    pRetVersion->hotfix =  ( pFileInfo->dwFileVersionLS >>  16 ) & 0xffff;
    pRetVersion->other  =  ( pFileInfo->dwFileVersionLS) & 0xffff;      
    
    }
    
    1. what is the the meaning of dwSize ? is this only the file version size? where can I see it while clicking on the shell32.dll?

    2. pLenFileinfo - what is this size ?

    3. when I look at the struct of VS_FIXEDFILEINFO there is only the version info information , Is there a wae to get for example : File description , Date modified , Original filename etc ? (all the other properties that are inside the "Details" )?

    thanks !!!!!

  • user1386966
    user1386966 over 11 years
    Maybe I'm missing something - I get that dwSize is 1860 , and pLenFileInfo is 52. my version number is 6.1.7601.17869 . what is the connection between these numbers? when I look at the shell32.dll->details and see the version number - it's the only thing I know about the version , so I can't understand what are the meaning of the other numbers. Or the version is everything??? (file description , type , product name etc ??)
  • David Heffernan
    David Heffernan over 11 years
    pLenFileInfo is 52 because it's a VS_FIXEDFILEINFO which is 13 DWORDs. The return value of GetFileVersionInfoSize is larger, as I explained in my answer. Because it has more information in it. For example, the file description.