473,651 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Feb 20 '07 #1
10 3532
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
Feb 20 '07 #2
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
Feb 20 '07 #3
"David Wilkinson" <no******@effis ols.comwrote in message
news:e1******** ******@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
Feb 20 '07 #4
"Wim" <Wi*@discussion s.microsoft.com wrote in message
news:ED******** *************** ***********@mic rosoft.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
Feb 20 '07 #5
"David W" <no@email.provi dedwrote in message
news:4A******** ***********@nas al.pacific.net. au...
"Wim" <Wi*@discussion s.microsoft.com wrote in message
news:ED******** *************** ***********@mic rosoft.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
Feb 21 '07 #6
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

Feb 21 '07 #7

"David W" <no@email.provi dedwrote in message
news:2t******** ***********@nas al.pacific.net. au...
"David W" <no@email.provi dedwrote in message
news:4A******** ***********@nas al.pacific.net. au...
>"Wim" <Wi*@discussion s.microsoft.com wrote in message
news:ED******* *************** ************@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"
Feb 21 '07 #8
"Ben Voigt" <rb*@nospam.nos pamwrote in message
news:uU******** ******@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
Feb 21 '07 #9
"David W" <no@email.provi dedwrote in message
news:Pg******** ***********@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
Feb 22 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3431
by: yanwan | last post by:
Hello I am now compling a project, but in one source file of this project, I met this problem. It seems very strange. Below is this source file: ---------------------------------------- #include "icarus_types.h" #ifdef WIN32 #include <GL/glu.h>
1
1306
by: DiskMan | last post by:
System: Redhat 7.2 Kernel-2.6.11.8 GCC-3.4.3 CCC-6.5.9 Binutils-2.15 Make-3.80 GTK/GLIB-2.6.7 For some reason my Linux box is suddenly having issues trying to read ;
3
2954
by: Generic Usenet Account | last post by:
This is a two-part question. (1) I have implemented a "Datastructure Registry" template class. I am getting no compiler warnings with older compilers, but newer compilers are generating the following error messages: warning: implicit typename is deprecated, please see the documentation for details Can someone kindly suggest how to get rid of these warnings? The source code follows.
4
3426
by: yanwan | last post by:
Hello I am now compling a project, but in one source file of this project, I met this problem. It seems very strange. Below is this source file: ---------------------------------------- #include "icarus_types.h" #ifdef WIN32 #include <GL/glu.h>
1
2156
by: Vishal Saxena | last post by:
Hi, I am new to this news group, hope to get prompt solution from you, gurus of VC. Well i had a project developed in VC++ 6.0, it uses Adobe Plugin Development SDK, I am trying to upgrade my project to VC++.NET, below is the code snipplet from the project
3
3138
by: tomrmgc | last post by:
I have some code that compiles and links fine in VC6 but does not link in VC7. Here are the relevant parts of the code: class AView : public CScrollView { .... public: AFX_DISPMAP_ENTRY* _dispatchEntries; UINT _dispatchEntryCount; DWORD _dwStockPropMask;
3
5472
by: Steve Jaworski | last post by:
Using VS2005Beta 2 I have VC++/CLI class defined in a Class Library DLL as: #foo.h namespace foo { public ref class Convert { public: static Obj^ ToObj(UnmanagedObj* uObj);
21
6875
by: one2001boy | last post by:
PostMessage() function returns ERROR_NOT_ENOUGH_QUOTA after running in a loop for 700 times, but the disk space and memory are still big enough. any suggestion to resolve this problem? thanks.
6
27830
by: anirbid.banerjee | last post by:
Hi, I need to write a macro which would have a lot many conditional #ifdef ... #endif blocks in it. #define _xx_macro (x) { ... \ ... \ /* some code (); */ #ifdef _SOME_STMT \ ... \ ... \
0
8349
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8695
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8460
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7296
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.