简体   繁体   English

在资源文件中使用宏

[英]Using Macros in Resource File

I am trying to use macros to auto-generate the build version for a C++ project. 我正在尝试使用宏来自动生成C ++项目的生成版本。

If I do the following, everything works fine. 如果执行以下操作,一切正常。

Versioning.h Versioning.h

...
#define VERSION_MAJOR 1
#define VERSION_MINOR 0
...

MyApp.rc MyApp.rc

...
#include "Versioning.h"

VS_VERSION_INFO VERSIONINFO
 FILEVERSION VERSION_MAJOR, VERSION_MINOR, 0, 0
 PRODUCTVERSION VERSION_MAJOR, VERSION_MINOR, 0, 0
 FILEFLAGSMASK 0x3fL
...

However, if I try and include anything more complex, such as math, the compiler generates errors 但是,如果我尝试包含更复杂的内容(例如数学),则编译器会生成错误

#define VERSION_MAJOR (2 / 2)

error RC1013: mismatched parentheses
error RC2104: undefined keyword or key name: /

I need to use much more complex mathematical expressions, call other classes, perform string comparison, etc. from within the macro. 我需要在宏中使用更复杂的数学表达式,调用其他类,执行字符串比较等。

My guess is that there is not something wrong with the macros I am writing, but rather a problem with the way that the resource file handles macros. 我的猜测是,我编写的宏没有什么问题,而是资源文件处理宏的方式存在问题。

Any ideas? 有任何想法吗?

Note: I am using Visual Studio Ultimate 2013 Update 3. 注意:我正在使用Visual Studio Ultimate 2013 Update 3。

A Resource compiler is not as flexible as a source code compiler. 资源编译器不如源代码编译器灵活。 You cannot use complex macros in a resource script. 您不能在资源脚本中使用复杂的宏。 If you need that, you will have to use a separate preprocessor to perform the calculations and generate the necessary macro values for the Resource compiler to use. 如果需要,则必须使用单独的预处理器来执行计算并生成必要的宏值,以供资源编译器使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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