RC2104 error on #ifdef

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David W

    RC2104 error on #ifdef

    Hello,

    In a C++ MFC application I need to conditionally #include one of two additional
    resource files in my main resource file because different forms of the
    application have different names. I would also like to edit the main resource
    file with the IDE's resource editor and save it without losing the conditional
    #includes of the name-specific resource files. So, the main resource file
    includes the following:

    3 TEXTINCLUDE
    BEGIN
    "#include ""apptype.h ""
    "#ifdef APP_A" // <---- error
    "#include ""app_a.rc" "
    "#else"
    "#include ""app_b.rc" "
    "#endif"
    // the other #includes
    "\0"
    END

    However, RC is producing an RC2104 error on the marked line with the message
    "Undefined keyword or key name: #ifdef". Since RC normally understands #ifdef I
    don't understand why it complains about one in a TEXTINCLUDE. Can someone
    explain it?

    On the same subject, this is an MDI application with one menu for each of many
    different document types. I have had to put _all_ menus in both
    app-name-specific resource files, and it's only because of the "About..." item
    on the Help menu (since, by convention, this item includes the application name:
    "About AppA..." or "About AppB..."). This means that any menu changes must be
    done in both resource files. Is there an easier way to do this?

    I am using VS .NET 2003.

    David


  • David Wilkinson

    #2
    Re: RC2104 error on #ifdef

    David W wrote:
    Hello,
    >
    In a C++ MFC application I need to conditionally #include one of two additional
    resource files in my main resource file because different forms of the
    application have different names. I would also like to edit the main resource
    file with the IDE's resource editor and save it without losing the conditional
    #includes of the name-specific resource files. So, the main resource file
    includes the following:
    >
    3 TEXTINCLUDE
    BEGIN
    "#include ""apptype.h ""
    "#ifdef APP_A" // <---- error
    "#include ""app_a.rc" "
    "#else"
    "#include ""app_b.rc" "
    "#endif"
    // the other #includes
    "\0"
    END
    >
    However, RC is producing an RC2104 error on the marked line with the message
    "Undefined keyword or key name: #ifdef". Since RC normally understands #ifdef I
    don't understand why it complains about one in a TEXTINCLUDE. Can someone
    explain it?
    >
    On the same subject, this is an MDI application with one menu for each of many
    different document types. I have had to put _all_ menus in both
    app-name-specific resource files, and it's only because of the "About..." item
    on the Help menu (since, by convention, this item includes the application name:
    "About AppA..." or "About AppB..."). This means that any menu changes must be
    done in both resource files. Is there an easier way to do this?
    David:

    Not quite sure I understand what you want here, but if something cannot
    be accomplished by the conditional compilation feature of the resource
    editor, then I move the material into the .rc2 file, where you can put
    #ifdef's as you desire without upsetting the resource editor. In my case
    this is just a few strings.

    As to the About box, it is easy enough to write code in OnInitDialog to
    modify the text. Use AFX_IDS_APP_TIT LE to get the app title (this is one
    of the strings that I put in the .rc2 file).

    David Wilkinson


    Comment

    • =?Utf-8?B?V2lt?=

      #3
      RE: RC2104 error on #ifdef

      Hi,

      Can you try adding \r\n at the end of each line like this:

      3 TEXTINCLUDE
      BEGIN
      "#include ""apptype.h"\r\ n"
      "#ifdef APP_A\r\n"
      ....

      It's like that in my auto-generated .rc files. Maybe in your example he's
      concatenating the 2 strings on the same line, which would explain the error.

      Wim

      "David W" wrote:
      Hello,
      >
      In a C++ MFC application I need to conditionally #include one of two additional
      resource files in my main resource file because different forms of the
      application have different names. I would also like to edit the main resource
      file with the IDE's resource editor and save it without losing the conditional
      #includes of the name-specific resource files. So, the main resource file
      includes the following:
      >
      3 TEXTINCLUDE
      BEGIN
      "#include ""apptype.h ""
      "#ifdef APP_A" // <---- error
      "#include ""app_a.rc" "
      "#else"
      "#include ""app_b.rc" "
      "#endif"
      // the other #includes
      "\0"
      END
      >
      However, RC is producing an RC2104 error on the marked line with the message
      "Undefined keyword or key name: #ifdef". Since RC normally understands #ifdef I
      don't understand why it complains about one in a TEXTINCLUDE. Can someone
      explain it?
      >
      On the same subject, this is an MDI application with one menu for each of many
      different document types. I have had to put _all_ menus in both
      app-name-specific resource files, and it's only because of the "About..." item
      on the Help menu (since, by convention, this item includes the application name:
      "About AppA..." or "About AppB..."). This means that any menu changes must be
      done in both resource files. Is there an easier way to do this?
      >
      I am using VS .NET 2003.
      >
      David
      >
      >
      >

      Comment

      • David W

        #4
        Re: RC2104 error on #ifdef

        "David Wilkinson" <no-reply@effisols. comwrote in message
        news:e1tLfoNVHH A.3500@TK2MSFTN GP05.phx.gbl...
        David W wrote:
        >
        >Hello,
        >>
        >In a C++ MFC application I need to conditionally #include one of two
        >additional resource files in my main resource file because different forms of
        >the application have different names. I would also like to edit the main
        >resource file with the IDE's resource editor and save it without losing the
        >conditional #includes of the name-specific resource files. So, the main
        >resource file includes the following:
        >>
        >3 TEXTINCLUDE
        >BEGIN
        > "#include ""apptype.h ""
        > "#ifdef APP_A" // <---- error
        > "#include ""app_a.rc" "
        > "#else"
        > "#include ""app_b.rc" "
        > "#endif"
        >// the other #includes
        > "\0"
        >END
        >>
        >However, RC is producing an RC2104 error on the marked line with the message
        >"Undefined keyword or key name: #ifdef". Since RC normally understands #ifdef
        >I don't understand why it complains about one in a TEXTINCLUDE. Can someone
        >explain it?
        >>
        >On the same subject, this is an MDI application with one menu for each of
        >many different document types. I have had to put _all_ menus in both
        >app-name-specific resource files, and it's only because of the "About..."
        >item on the Help menu (since, by convention, this item includes the
        >application name: "About AppA..." or "About AppB..."). This means that any
        >menu changes must be done in both resource files. Is there an easier way to
        >do this?
        >
        Not quite sure I understand what you want here,
        I was hoping to understand one of:
        1. Why TEXTINCLUDE doesn't appear to do what the name suggests, i.e., simply
        insert verbatim whatever text is inside the quotes.
        2. If it does do the above, then what syntax is needed to insert the #ifdef?
        but if something cannot be accomplished by the conditional compilation feature
        of the resource editor, then I move the material into the .rc2 file, where you
        can put #ifdef's as you desire without upsetting the resource editor.
        Thanks. I might try something like that if I can't get TEXTINCLUDE to do what I
        want.
        In my case this is just a few strings.
        In my case a lot more.
        As to the About box, it is easy enough to write code in OnInitDialog to modify
        the text. Use AFX_IDS_APP_TIT LE to get the app title (this is one of the
        strings that I put in the .rc2 file).
        The About box isn't the problem (that's duplicated as well, but there's only one
        About box). The problem is the all the menus (9 of them, one for each MDI doc
        type) that lead to the About box. By convention the menu item says "About
        <appname>..." , but since the appname varies according to the #ifdef, those menus
        have to duplicated.

        David


        Comment

        • David W

          #5
          Re: RC2104 error on #ifdef

          "Wim" <Wim@discussion s.microsoft.com wrote in message
          news:EDDCC5F1-57C2-42A9-89B6-B812C29271B5@mi crosoft.com...
          Hi,
          >
          Can you try adding \r\n at the end of each line like this:
          >
          3 TEXTINCLUDE
          BEGIN
          "#include ""apptype.h"\r\ n"
          "#ifdef APP_A\r\n"
          ...
          >
          It's like that in my auto-generated .rc files. Maybe in your example he's
          concatenating the 2 strings on the same line, which would explain the error.
          Good suggestion. Unfortunately, it didn't work. Now I get, "Undefined keyword or
          key name: \r\n".

          I notice that the wizard-generated #includes that were already in that
          TEXTINCLUDE did not have \r\n before the closing quote, though one line had
          "\r\n" on its own.

          David


          Comment

          • David W

            #6
            Re: RC2104 error on #ifdef

            "David W" <no@email.provi dedwrote in message
            news:4AKCh.3434 5$b6.261605@nas al.pacific.net. au...
            "Wim" <Wim@discussion s.microsoft.com wrote in message
            news:EDDCC5F1-57C2-42A9-89B6-B812C29271B5@mi crosoft.com...
            >Hi,
            >>
            >Can you try adding \r\n at the end of each line like this:
            >>
            >3 TEXTINCLUDE
            >BEGIN
            > "#include ""apptype.h"\r\ n"
            > "#ifdef APP_A\r\n"
            >...
            >>
            >It's like that in my auto-generated .rc files. Maybe in your example he's
            >concatenatin g the 2 strings on the same line, which would explain the error.
            >
            Good suggestion. Unfortunately, it didn't work. Now I get, "Undefined keyword
            or key name: \r\n".
            >
            I notice that the wizard-generated #includes that were already in that
            TEXTINCLUDE did not have \r\n before the closing quote, though one line had
            "\r\n" on its own.
            I take that back. There is a comment on each line that's part of the included
            text, and the \n\r is there. I'm pretty sure now that it was just a syntax
            problem all along. You can count 5 quote marks in the apptype.h line, whereas
            there should be an even number, and the \n\r was needed as well.

            David


            Comment

            • David Wilkinson

              #7
              Re: RC2104 error on #ifdef

              David W wrote:
              >>As to the About box, it is easy enough to write code in OnInitDialog to modify
              >>the text. Use AFX_IDS_APP_TIT LE to get the app title (this is one of the
              >>strings that I put in the .rc2 file).
              >
              >
              The About box isn't the problem (that's duplicated as well, but there's only one
              About box). The problem is the all the menus (9 of them, one for each MDI doc
              type) that lead to the About box. By convention the menu item says "About
              <appname>..." , but since the appname varies according to the #ifdef, those menus
              have to duplicated.
              David:

              Well, you could write an ON_UPDATE_COMMA ND_UI handler to modify the
              displayed menu text.

              David Wilkinson

              Comment

              • Ben Voigt

                #8
                Re: RC2104 error on #ifdef


                "David W" <no@email.provi dedwrote in message
                news:2tMCh.3434 9$b6.261549@nas al.pacific.net. au...
                "David W" <no@email.provi dedwrote in message
                news:4AKCh.3434 5$b6.261605@nas al.pacific.net. au...
                >"Wim" <Wim@discussion s.microsoft.com wrote in message
                >news:EDDCC5F 1-57C2-42A9-89B6-B812C29271B5@mi crosoft.com...
                >>Hi,
                >>>
                >>Can you try adding \r\n at the end of each line like this:
                >>>
                >>3 TEXTINCLUDE
                >>BEGIN
                >> "#include ""apptype.h"\r\ n"
                >> "#ifdef APP_A\r\n"
                >>...
                >>>
                >>It's like that in my auto-generated .rc files. Maybe in your example
                >>he's
                >>concatenati ng the 2 strings on the same line, which would explain the
                >>error.
                >>
                >Good suggestion. Unfortunately, it didn't work. Now I get, "Undefined
                >keyword or key name: \r\n".
                >>
                >I notice that the wizard-generated #includes that were already in that
                >TEXTINCLUDE did not have \r\n before the closing quote, though one line
                >had "\r\n" on its own.
                >
                I take that back. There is a comment on each line that's part of the
                included text, and the \n\r is there. I'm pretty sure now that it was just
                a syntax problem all along. You can count 5 quote marks in the apptype.h
                line, whereas there should be an even number, and the \n\r was needed as
                well.
                Coupled with a fundamental misunderstandin g of what a pair of double quotes
                does in C++. In VB, that gives you a quote character inside your string, in
                C++ it ends one string and starts another, which the preprocessor helpfully
                stitches together (it's useful when one of the strings is a macro
                expansion).

                What you want is to use the backslash to correct escape quotes, generating
                quotes inside the string:
                "#include \"apptype.h\"\r \n"


                Comment

                • David W

                  #9
                  Re: RC2104 error on #ifdef

                  "Ben Voigt" <rbv@nospam.nos pamwrote in message
                  news:uUkxsZcVHH A.4380@TK2MSFTN GP03.phx.gbl...
                  >
                  "David W" <no@email.provi dedwrote in message
                  >>
                  >I take that back. There is a comment on each line that's part of the included
                  >text, and the \n\r is there. I'm pretty sure now that it was just a syntax
                  >problem all along. You can count 5 quote marks in the apptype.h line, whereas
                  >there should be an even number, and the \n\r was needed as well.
                  >
                  Coupled with a fundamental misunderstandin g of what a pair of double quotes
                  does in C++.
                  No, I know what a pair of double quotes does in C++.
                  In VB, that gives you a quote character inside your string,
                  Do you assume I'm a VBer who's new to C++? I've been writing C++ for >10 years.
                  I've hardly touched VB and know almost nothing about it.
                  in C++ it ends one string and starts another, which the preprocessor helpfully
                  stitches together (it's useful when one of the strings is a macro expansion).
                  Not necessarily anything to do with this problem, which is in _resource_ code,
                  not C++ code. For all I knew, resource code might or might not use C++ rules for
                  these things. I had no idea what it's rules were, which is why I asked.
                  What you want is to use the backslash to correct escape quotes, generating
                  quotes inside the string:
                  "#include \"apptype.h\"\r \n"
                  This is the resource code that the IDE's own wizard produces when you ask it to
                  create a skeleton MFC application. Note the double quotes.
                  3 TEXTINCLUDE
                  BEGIN
                  "#define _AFX_NO_SPLITTE R_RESOURCES\r\n "
                  "#define _AFX_NO_OLE_RES OURCES\r\n"
                  "#define _AFX_NO_TRACKER _RESOURCES\r\n"
                  "#define _AFX_NO_PROPERT Y_RESOURCES\r\n "
                  "\r\n"
                  "#if !defined(AFX_RE SOURCE_DLL) || defined(AFX_TAR G_ENU)\r\n"
                  "LANGUAGE 9, 1\r\n"
                  "#pragma code_page(1252) \r\n"
                  "#include ""res\\Temp.rc2 "" // non-Microsoft Visual C++ edited
                  resources\r\n"
                  "#include ""afxres.rc "" // Standard components\r\n"
                  "#include ""afxprint. rc"" // printing/print preview resources\r\n"
                  "#endif\r\n "
                  "\0"
                  END

                  And this is the text that results from the above:
                  #define _AFX_NO_SPLITTE R_RESOURCES
                  #define _AFX_NO_OLE_RES OURCES
                  #define _AFX_NO_TRACKER _RESOURCES
                  #define _AFX_NO_PROPERT Y_RESOURCES

                  #if !defined(AFX_RE SOURCE_DLL) || defined(AFX_TAR G_ENU)
                  LANGUAGE 9, 1
                  #pragma code_page(1252)
                  #include "res\\Temp. rc2" // non-Microsoft Visual C++ edited resources
                  #include "afxres.rc" // Standard components
                  #include "afxprint.r c" // printing/print preview resources
                  #endif
                  #endif // not APSTUDIO_INVOKE D

                  David


                  Comment

                  • David W

                    #10
                    Re: RC2104 error on #ifdef

                    "David W" <no@email.provi dedwrote in message
                    news:Pg4Dh.3450 1$b6.262327@nas al.pacific.net. au...
                    >
                    No, I know what a pair of double quotes does in C++.
                    I meant either a pair of quotes or double quotes, but not both.

                    David


                    Comment

                    • Ben Voigt

                      #11
                      Re: RC2104 error on #ifdef

                      No, I know what a pair of double quotes does in C++.
                      >
                      >In VB, that gives you a quote character inside your string,
                      >
                      Do you assume I'm a VBer who's new to C++? I've been writing C++ for >10
                      years. I've hardly touched VB and know almost nothing about it.
                      Sorry about the misinformed statements then. I simply would say that when
                      the strings already contain C++ escape sequences (\r\n), then other C++
                      escape sequences would most likely work. I suspect that \" will produce the
                      desired behavior, and would certainly be far more consistent with C++ code.

                      Resource files are run through the C preprocessor, so many of the same rules
                      apply.


                      Comment

                      Working...