nobs
nobs

Reputation: 730

Visual Studio Resource compiler string merging

In my project I have an include file "buildversion.h" which contains the definition for the versionnumber. To make it more managable I'v done some Preprocessor "magic"

The problem is, the Visual studio resourcefile editor don't behave like the normal compiler so I get "wrong" entrys

My header file:

#define MAJOR_VER_NUM 2
#define MINOR_VER_NUM  3
#define REV_NUM     9999
#define STR(x)   #x        // helper defines
#define XSTR(x)  STR(x)  // helper defines
#define XXX_FILE_VERSION           MAJOR_VER_NUM,MINOR_VER_NUM,REV_NUM,0
#define XXX_PRODUCT_VERSION        MAJOR_VER_NUM,MINOR_VER_NUM,REV_NUM,0
#define XX_FILE_VERSION_STRING    XSTR(MAJOR_VER_NUM)", "XSTR(MINOR_VER_NUM)", "XSTR(REV_NUM)", 0"
#define ICOS_PRODUCT_VERSION_STRING XSTR(MAJOR_VER_NUM)", "XSTR(MINOR_VER_NUM)", "XSTR(REV_NUM)", 0"
int const MajorVersionNumber = MAJOR_VER_NUM;
int const MinorVersionNumber = MINOR_VER_NUM;
int const RevisionNumber     = REV_NUM;

In my "main.rc" file I include the above header and In the version block I write

VALUE "FileVersion", XXX_FILE_VERSION_STRING

The result for this entry is:

2", "3", "9999", 0

If I use the above header file in normal c++ code the substition works fine, I get

2, 3, 9999, 0

as expected.

Is there some way to do make this work in a resourcefile?

Upvotes: 3

Views: 481

Answers (1)

azhrei
azhrei

Reputation: 2323

This is code that works for me, replaced to use the same macro names as yours.

Keep your version numbers and str helpers as is, then:

  #define XXX_FILE_VERSION_DOT MAJOR_VER_NUM.MINOR_VER_NUM.REV_NUM.0
  #define XXX_FILE_VERSION_COMMA MAJOR_VER_NUM,MINOR_VER_NUM,REV_NUM,0

  #define XXX_FILE_VERSION_DOT_STR XSTR(XXX_FILE_VERSION_DOT)
  #define XXX_FILE_VERSION_COMMA_STR XSTR(XXX_FILE_VERSION_COMMA)

Then in the .rc, I find you need to use the comma form only in the FILEVERSION section, like so:

 FILEVERSION XXX_FILE_VERSION_COMMA

And later in the StringFileInfo block you use the dotted string form version, like so:

 VALUE "FileVersion", XXX_FILE_VERSION_DOT_STR

Upvotes: 2

Related Questions