Visual studio mangles resource file: is prevention possible ?

Ah hello.

I have a resource file, that contains several #if defined statements.  The purpose of these is simply to only provide certain functionality if a symbol is defined.

For example,

#if defined (_LIMITED_FEATURE)
            MENUITEM "Limited Feature.",                ID_FILE_LIMITED_FEATURE

But I find that occasionally visual studio will remove all my #if defined statements (meaning all menu items are available regardless of any symbol I may define), which is a total pain.  Is there any way I can prevent it doing this ?  I have been advised it is something to do with the macro APSTUDIO_INVOKED, but Googling only brings back other people's resource files: not useful.

LVL 19
Who is Participating?
rcarlanConnect With a Mentor Commented:
Select the corresponding resource entry from under the ResourceView, bring up Properties (Alt+Enter) and set a condition (e.g. _LIMITED_FEATURE).

You may also have the same resource ID appear several times with different definitions and conditions - e.g. MODEL_STANDARD, MODEL_PRO, etc applied to different definitions of the same MENU resource entry.

With this approach you can still use the VS resource editor to edit and manage these resources (whereas in the .rc2 you would have to edit things manually as text).

AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
put the code into the cpp/h files instead.  
use the #ifdef block to remove or disable the menu/toolbar items
jimwassonConnect With a Mentor Commented:
I'd suggest putting it into the project's .rc2 file which is for "non-Microsoft Visual C++ edited resources".
You should find it in your "res" subdirectory.
AndyAinscowFreelance programmer / ConsultantCommented:
A further point (you have probably considered) is the whole design concept.
I prefer that the end user (paying customer?) sees that some functionality that is only available in the version they pay <more> for (advertising in a word ! ).  
If there is a good reason that some functionality should be hidden then I find code easier to maintain if the mechanism to hide is in one location not a bit in the resource editor, another bit in the header and in a further two/three places in the cpp file.  (MessageMap, OnCommand, OnUpdateCommand).  Yes it is fractionally larger, yes it takes 0.01 seconds longer to launch.  If it is a huge ammount of code to hide then it could be in a dll and only invoked with LoadLibrary, GetProcAddress so the exe has little extra code in it.
mrwad99Author Commented:
Thanks for those suggestions all; Radu's one was ultimately the easiest so was accepted as the solution.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.