delphiexplorerfileversioninfo

Compiled VS_VERSION_INFO resource displays in Explorer unexpected texts


I'm using an external file (verinfo.rc) to generated the details of the compiled EXE file. Here is an example of how my file looks like:

VS_VERSION_INFO VERSIONINFO
FILEVERSION             1,0,0,0
PRODUCTVERSION          1,0,0,0
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
        VALUE "Comments",         "Company Soft"
        VALUE "CompanyName",      "Company2"
        VALUE "FileDescription",  "Company Soft"
        VALUE "FileVersion",      "x.x.x.x"
        VALUE "InternalName",     "Company Soft"
        VALUE "LegalCopyright",   "Company2"
        VALUE "OriginalFilename", "abrev.exe"
        VALUE "ProductName",      "Company Soft"
        VALUE "ProductVersion",   "x.x.x.x"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x0409,1200
    END
END

Looking into the compiled EXE's details using the Explorer, I note that some data get wrecked and crazy symbols appears. What is happening?

Explorer file version details


Solution

  • As per the documentation's example, all the data parts of a VALUE must have a terminating NULL byte:

    #define VER_FILEVERSION_STR "3.10.349.0\0"
    ...
    VALUE "FileVersion", VER_FILEVERSION_STR
    

    Also, I'm used to using curly brackets for decades when working in Delphi instead of using keywords for blocks:

    FILETYPE 0x1 {
      BLOCK "StringFileInfo" {
        BLOCK "00000000" {
          VALUE "FileDescription", "Great product, much value!\000" 
          VALUE "FileVersion", "1.0.39\000" 
        }
      }
      BLOCK "VarFileInfo" {
        VALUE "Translation", 0x0000 0x0000
      }
    }
    

    In doubt, always add a terminating NULL byte to a string - it's expected more often than not. If you look into the compiled RES file and see how your text turned into UTF-16, you'll also notice that none of the texts are prefixed with anything that looks like a length - that's also a reason why a terminating \0 must be used, because otherwise nobody knows where the text ends:

    binary of FILEVERSION ressource