Visual studio mangles resource file: is prevention possible ?

Posted on 2005-04-21
Last Modified: 2013-11-20
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.

Question by:mrwad99
    LVL 43

    Assisted Solution

    put the code into the cpp/h files instead.  
    use the #ifdef block to remove or disable the menu/toolbar items
    LVL 7

    Assisted Solution

    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.
    LVL 9

    Accepted Solution

    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).

    LVL 43

    Expert Comment

    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.
    LVL 19

    Author Comment

    Thanks for those suggestions all; Radu's one was ultimately the easiest so was accepted as the solution.


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Importing  SSL Certificate into Firefox using GPO 28 180
    sumDigits challenge 9 72
    fizzArray  challenge 1 28
    fix34  challenge 9 70
    Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
    Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now