473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 3491
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_TITLE 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******@effisols.comwrote in message
news:e1**************@TK2MSFTNGP05.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_TITLE 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*@discussions.microsoft.comwrote in message
news:ED**********************************@microsof t.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.providedwrote in message
news:4A*******************@nasal.pacific.net.au...
"Wim" <Wi*@discussions.microsoft.comwrote in message
news:ED**********************************@microsof t.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.
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_TITLE 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_COMMAND_UI handler to modify the
displayed menu text.

David Wilkinson

Feb 21 '07 #7

"David W" <no@email.providedwrote in message
news:2t*******************@nasal.pacific.net.au...
"David W" <no@email.providedwrote in message
news:4A*******************@nasal.pacific.net.au...
>"Wim" <Wi*@discussions.microsoft.comwrote in message
news:ED**********************************@microso ft.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.

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 misunderstanding 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.nospamwrote in message
news:uU**************@TK2MSFTNGP03.phx.gbl...
>
"David W" <no@email.providedwrote 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 misunderstanding 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_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_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_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_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.rc" // printing/print preview resources
#endif
#endif // not APSTUDIO_INVOKED

David
Feb 21 '07 #9
"David W" <no@email.providedwrote in message
news:Pg*******************@nasal.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
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.
Feb 22 '07 #11

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

Similar topics

1
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: ----------------------------------------...
1
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
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...
4
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: ----------------------------------------...
1
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...
3
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*...
3
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...

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.