简体   繁体   中英

How to convert concatenated defines into a string in an RC file?

I have an RC file with these defines inside:

#define V_MAJOR 0
#define V_MINOR 0
#define V_PATCH 0
#define V_BUILD 2
#define DOT .

#define V_STRING V_MAJOR##DOT##V_MINOR##DOT##V_PATCH##DOT##V_BUILD

How do I turn V_STRING into a literal string?

I tried the following code (which I found on the internet and supposedly works)

#define STRINGIZE_(x) #x
#define STRINGIZE(x) STRINGIZE_(x)

and then I called STRINGIZE on V_STRING, but instead of turning the values into strings, it turned the identifiers into strings. (AKA it displays "V_MAJORDOTV_MINORDOTV_PATCHDOTV_BUILD" in the properties tab in explorer for the Product Version.)

I basically want V_STRING to return "0.0.0.2", using V_MAJOR, V_MINOR, V_PATCH and V_BUILD. How do I do that?

Firstly, redefine your version numbers as given below.

#define V_MAJOR "0"
#define V_MINOR "0"
#define V_PATCH "0"
#define V_BUILD "2"
#define DOT "."

Please note that the version numbers are inside double quotes.

Then redefine VS_STRING as given below.

    #define V_STRING V_MAJOR DOT V_MINOR DOT V_PATCH DOT V_BUILD

Note that NO token paste operator is used.

Now you can use the VS_STRING macro inside an RC file as given below.

// Other stuffs
VALUE "FileVersion", V_STRING
// Other stuffs

Also, you can use the VS_STRING macro in code as given below.

    char* ptszVersion = V_STRING;
    printf( "Version number is %s", ptszVersion );

See below output.

Version number is 0.0.0.2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM