2

I made an application, and i have to create two separete builds for it. One for 32bit and one for 64bit. In the property of the file, i'd like to include some descriptions, like the original filename, where i'd like to set the architecture(x64 or x86). As it seems it is harder than i thought, or i am doing something wrong.

#ifdef _WIN64
   #define ARCHIT "1"
#else
   #define ARCHIT "2"
#endif

This macro always returns 2. Am i doing something wrong? If i insert some #pragma message before the define i see, that is evaluating correctly, but somehow the text written in the file property will always be 2.

Could someone help me?

Thanks!

Update:

This is how i use it:

#define VER_FILEVERSION             1,0,0,0
#define VER_FILEVERSION_STR         "1.0.0.0\0"

#define VER_PRODUCTVERSION          1,0,0,0
#define VER_PRODUCTVERSION_STR      "1.0.0.0\0"


1 VERSIONINFO
FILEVERSION     VER_FILEVERSION
PRODUCTVERSION  VER_PRODUCTVERSION
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
    BLOCK "040904b0"
    BEGIN
        VALUE "FileDescription", "My Description"
        VALUE "FileVersion", VER_FILEVERSION_STR
        VALUE "InternalName", BASENAME
        VALUE "LegalCopyright", "My company"
        VALUE "OriginalFilename", ARCHIT
        VALUE "ProductName", BASENAME
        VALUE "ProductVersion", VER_PRODUCTVERSION_STR
    END
END
BLOCK "VarFileInfo"
BEGIN
    VALUE "Translation", 0x409, 1200
END
END
Suma
  • 33,181
  • 16
  • 123
  • 191
kampi
  • 2,362
  • 12
  • 52
  • 91
  • 3
    Macros don't "return" anything. Show how you're *using* it, preferably a two-line `main()` that demonstrates your observation. – WhozCraig Jan 20 '15 at 11:00
  • @WhozCraig. I updated my question. This is how i use it. – kampi Jan 20 '15 at 11:05
  • 1
    BEGIN, BLOCK, END, VALUE? Why is this tagged C? – Jens Jan 20 '15 at 11:07
  • 2
    Thanks for the update. Unless I'm mistaken the C/C++ *compiler* macro `_WIN64` is **not** established by the *resource* compiler (RC), so that would likely be your problem. – WhozCraig Jan 20 '15 at 11:07
  • Ok, so how do i correct it? – kampi Jan 20 '15 at 11:09
  • 3
    You can fake it by editing your project settings, head to Resources/General/Preprocessor for each platform target and set your own macros. Be sure to do it for *both* debug and release for *both* target platforms. Check the RC docs to see if there is anything *they* define to dicern x64 vs x86 beforehand, however. May save you some time. – WhozCraig Jan 20 '15 at 11:11
  • @WhozCraig: That was my Idee, too. I tried it, but i don't why, that doesn't worked either :( – kampi Jan 20 '15 at 11:17

2 Answers2

1

From the comments and from MSDN it seems that the only predefined macro in RC scripts is RC_INVOKED. So, you can't automatize RC scripts. There are however T4 text templates, and their .tt scripts. With them you could create some kind of .rc2 scripts that would #define anything you need, and that you would then #include in .rc script.

Should work in theory, never tried it though.

There is a page that explains how to automatically generate code with T4 scripts, and according to that page you need to install a Modelling SDK for your Visual Studio (2010, 2012, 2013). Unfortunately, it's not available for older versions.

Dialecticus
  • 16,400
  • 7
  • 43
  • 103
  • If you use T4 at design time, you don't need to install anything. For updating during build, see also [this question](http://stackoverflow.com/q/2307567/33499) – wimh Jan 20 '15 at 11:55
0

Thanks for everyone, but for me, this was the Solution. I think that's the simplest.

Update:

Detailed description, in case the link isn't working:

1. Open your project in Visual Studio.
2. Right click on resource script file (e.g. app.rc) and select "Properties"
3. At the top of the property page, select one platform like "Win32" or 
"x64".
4. In the left menu bar, select [Configuration Properties] / [Resources] / 
[General].
5. In the "Preprocessor Definitions" field, add "WIN32" for "Win32" 
platform and "WIN64" for "x64" platform. The field value will become " 
WINXX;_UNICODE;UNICODE". (XX will be 32 or 64)
6. Click OK to close the window.
7. Right click on resource script file (e.g. app.rc) and select "View Code".
8. In the code editor, add #ifdef and #elif to conditionally include 
resources when compiling.
kampi
  • 2,362
  • 12
  • 52
  • 91
  • I didn't add thank you as an answer. I provided a link, where the solution can be found. What should i vote up? None of the answers were working for me, only the one i posted. Thanking people for their effort is bad? Or should i vote up everything? – kampi Jan 20 '15 at 21:10