1

I have a C resource file called resources.rc, which contains the following line to specify the icon used for a project

    1000 ICON  "icon222.ico"

I would like to use this same resource file for several projects using a pre processor conditional depending on the project..

e.g

    #if __PROJECT__ == "myapp.exe"
    1000 ICON "icon222.ico"
    #endif

    #if __PROJECT__ == "myotherapp.exe"
    1000 ICON "icon777.ico"
    #endif

Is there a standard C macro or definition that could be used to achieve something like this ?

alk
  • 69,737
  • 10
  • 105
  • 255
  • 1
    No, not in standard C. You need to give the define as command line switch. You should add the compiler and build system you are using to the question (both text and tags). – hyde Apr 01 '13 at 06:13
  • Maybe, you should modify `Makefile`... Even in that, I don't know, if .rc files support dynamic selection like `#if`. Worst case, have 2 separate .rc files & Makefile would choose one of them based on `__PROJECT__`... – anishsane Apr 01 '13 at 06:36

1 Answers1

1

As far as I known there is no predefined macro carring a project specific value setup by VC.

So just select one yourself like MYPROJECTNAME and #define it differently in each of your projects and then do test this in your rc file as by your posting.

I'm not sure anymore whether VC uses the pre-processor on the rc file automagically or if you need to apply some mods to VC's build process to have it do this.


Update:

To have this feature added using ${EXENAME} in terms of having global (solition wide) settings for VC a way to go might be shown here: Visual c++ 2008: how to have global settings defined in a solution or/and here: Can I pass a preprocessor definition to the resource compiler through the command line?

Community
  • 1
  • 1
alk
  • 69,737
  • 10
  • 105
  • 255
  • it works fine if I define MYPROJECTNAME , but I want to make this automatic - so I can just create a new project , and some definition would automatically be set,, something like __FILE__ , but __EXENAME__ –  Apr 01 '13 at 09:44
  • @AshodApakian: The C build process is translation unit orientated, at least until it comes to linking. So everything referrs to the module (*.c file) being processed. This is reflected by the availablility of `__FILE__` and `__LINE__`. Even MS does not seem to have added something to this paradigm, as you might like to read here: http://msdn.microsoft.com/en-us/library/b0084kay%28v=vs.110%29.aspx – alk Apr 01 '13 at 09:52