如何有条件编译VC6资源

发布于 2024-07-14 20:57:03 字数 1057 浏览 17 评论 0原文

根据以环境变量的形式设置的编译开关(值为 COMPILE_ACOMPILE_B),我想使用不同的设置来编译我的应用程序,例如 application名称和启动屏幕。

我到目前为止:

  1. 在“Project / Settings / C/C++ / Preprocessor Definitions”中我添加了 $(COMPILESWITCH) (结果是命令行选项 /D "$(COMPILESWITCH) ”)。

  2. 在stdafx.h中我可以使用以下代码,这意味着我通过命令行参数正确定义了预处理器定义:


    #if defined COMPILE_A
    #   define IDB_SPLASH IDB_SPLASH_A
    # elif defined COMPILE_B
    #   define IDB_SPLASH IDB_SPLASH_B
    # else
    #   error Unknown or undefined target compile switch; cannot compile!
    # endif

但我注意到“ResourceView / [右键] / Properties”下的“Condition”属性... 帮助文本是这样说的:

健康)状况

确定包含 资源。 例如,如果 条件是_DEBUG,这个资源 仅包含在调试中 构建。

这看起来是一种优雅的做法,对吧?

指定 _DEBUG 作为条件有效。 因此,由于 _DEBUG 是通过 /D _DEBUG 指定的,所以我的 $(COMPILESWITCH) 也应该可以工作,对吗?
由于某种原因,事实并非如此; 为什么?

或者还有其他更好的方法来实现我想要的吗?

depending on a compile switch (values are COMPILE_A or COMPILE_B), which is set in the form of an envorinment variable, I want to compile my application with different settings, like application name and splash screen.

I got this far:

  1. In "Project / Settings / C/C++ / Preprocessor Definitions" I added $(COMPILESWITCH) (results in command line option /D "$(COMPILESWITCH)").

  2. In stdafx.h I can use the following code, which means I correctly defined the preprocessor definition via the command line parameter:


    #if defined COMPILE_A
    #   define IDB_SPLASH IDB_SPLASH_A
    # elif defined COMPILE_B
    #   define IDB_SPLASH IDB_SPLASH_B
    # else
    #   error Unknown or undefined target compile switch; cannot compile!
    # endif

But I've noticed the "Condition" property under "ResourceView / [right-click] / Properties"...
The help text says this:

Condition

Determines the inclusion of
the resource. For example, if the
condition is _DEBUG, this resource
would be included only in debug
builds.

This looks like the elegant way of doing it, right?

Specifiying _DEBUG as condition works. So as _DEBUG is specified via /D _DEBUG my $(COMPILESWITCH) should also work, right?
For some reason it doesn't; why?

Or is there even another, better way to achieve what I want?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

呆° 2024-07-21 20:57:03

我想我刚刚解决了我的问题...

资源编译器使用它自己的预处理器。
因此,必须在“项目/设置/资源/预处理器定义”下添加相同的预处理器定义。

编辑:字符串资源

上述不适用于字符串资源,因为它们没有“条件”属性...

我选择使用 res\.rc2 自定义资源文件资源编辑器不会触及它。
内容看起来像这样

#if defined(COMPILE_A)
    STRINGTABLE DISCARDABLE 
    BEGIN
        IDR_MAINFRAME           "AppTitle A"
    END
#else
#   if defined(COMPILE_B)
    STRINGTABLE DISCARDABLE 
    BEGIN
        IDR_MAINFRAME           "AppTitle B"
    END
#   else
#       error Compile switch not defined or unknown; cannot compile!
#   endif
#endif

I guess I just solved my problem...

The resource compiler uses its own preprocessor.
Therefore the same preprocessor definition has to be added under "Project / Settings / Resources / Preprocessor Definitions".

Edit: String Resources

The above doesn't work for string resources as they don't have a "condition" property...

I chose to use the res\<projectname>.rc2 custom resource file which won't be touched by the resource editor.
The content looks like this

#if defined(COMPILE_A)
    STRINGTABLE DISCARDABLE 
    BEGIN
        IDR_MAINFRAME           "AppTitle A"
    END
#else
#   if defined(COMPILE_B)
    STRINGTABLE DISCARDABLE 
    BEGIN
        IDR_MAINFRAME           "AppTitle B"
    END
#   else
#       error Compile switch not defined or unknown; cannot compile!
#   endif
#endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文