views:

1199

answers:

5

Hi Folks,

I'm programming in C++ on Visual Studio 2005. My question deals with .rc files. You can manually place include directives like (#include "blah.h"), at the top of an .rc file. But that's bad news since the first time someone opens the .rc file in the resource editor, it gets overwritten. I know there is a place to make these defines so that they don't get trashed but I can't find it and googling hasn't helped. Anyone know?

A: 

I'm not completely sure why you're trying to do, but modifying the resource files manually probably isn't a good idea.

I believe general practice for VC++ for globally-accessible values is to define them in stdafx.h (at least that's how I've seen it done), or to create something like a "globals.h" header file and include that wherever you need it. It really depends on what you're trying to accomplish though.

Herms
+3  A: 

You want to Include Resources at Compile Time (MSDN).

Chris
Just found it too. Thanks!http://msdn.microsoft.com/en-us/library/6e7446zd(VS.71).aspx
+2  A: 

Add your #include to the file in the normal way, but also add it to one the three "TEXTINCLUDE" sections in the file, like so:

2 TEXTINCLUDE
BEGIN
    "#include ""windows.h""\r\n"
     "#include ""blah.h\r\n"
     "\0"
 END

Note the following details:

  • Each line is contained in quotes
  • Use pairs of quotes, e.g., "" to place a quote character inline
  • End each line with \r\n
  • End the TEXTINCLUDE block with "\0"

Statements placed in the "1 TEXTINCLUDE" block will be written to the beginning of the .rc file when the file is re-written by the resource editor. Statements placed in the 2 and 3 blocks follow, so you can guarantee relative include file order by using the appropriately numbered block.

If your existing rc file does not already include TEXTINCLUDE blocks, use the new file wizard from the Solution Explorer pane to add a new rc file, then use that as a template.

dgvid
This under the hood approach is working for me too. I need to edit the .rc file directly like this for my asian language .rc's. VS hangs when I try to use the IDE to add a resource include.
+1  A: 

Within Visual Studio IDE, right-click on the .rc file (in the Resource View panel), and select "Resource includes" from the shortcut menu. When the dialog opens, use its "Compile-time directives" area to enter whatever you want to include in the .rc file. For example, if you want your 64-bit and 32-bit builds to use different icons, you could include the appropriate resource file for each build as follows:

#ifdef WIN64
#include "Icons64.rc"
#else
#include "Icons32.rc"
#endif
Andrei Belogortseff
+1  A: 

All the gory details can be found in MFC Technote #35.

-Ron

Ron Pihlgren