• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

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
#endif

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.

TIA
0
mrwad99
Asked:
mrwad99
3 Solutions
 
AndyAinscowCommented:
put the code into the cpp/h files instead.  
use the #ifdef block to remove or disable the menu/toolbar items
0
 
jimwassonCommented:
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.
0
 
rcarlanCommented:
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).

Radu
0
 
AndyAinscowCommented:
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.
0
 
mrwad99Author Commented:
Thanks for those suggestions all; Radu's one was ultimately the easiest so was accepted as the solution.

Cheers.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now