为什么这个宏评估错误?

Why does this macro evaluating wrong?

我做了一个应用程序,我必须为它创建两个单独的版本。一个用于 32 位,一个用于 64 位。在文件的 属性 中,我想包含一些描述,例如原始文件名,我想在其中设置架构(x64 或 x86)。看起来它比我想象的要难,或者我做错了什么。

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

这个宏总是returns 2.我做错了什么吗?如果我在我看到的 define 之前插入一些 #pragma message,那是正确的评估,但不知何故,文件 属性 中写入的文本将始终为 2.

有人可以帮助我吗?

谢谢!

更新:

我是这样使用它的:

#define VER_FILEVERSION             1,0,0,0
#define VER_FILEVERSION_STR         "1.0.0.0[=11=]"

#define VER_PRODUCTVERSION          1,0,0,0
#define VER_PRODUCTVERSION_STR      "1.0.0.0[=11=]"


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

从评论和 MSDN 来看,RC 脚本中唯一预定义的宏似乎是 RC_INVOKED. So, you can't automatize RC scripts. There are however T4 text templates,以及它们的 .tt 脚本。有了它们,您可以创建某种 .rc2 脚本,可以 #define 您需要的任何东西,然后您可以 #include 在 .rc 脚本中。

理论上应该可行,但从未尝试过。

有一个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)。不幸的是,它不适用于旧版本。

谢谢大家,但对我来说,这就是 Solution。我认为这是最简单的。

更新:

详细说明,以防 link 不工作:

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.