Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2007

Tip: Looking for answers? Try searching our database.

RC2104 error on #ifdef

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David W - 20 Feb 2007 04:49 GMT
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 - 20 Feb 2007 10:30 GMT
> Hello,
>
[quoted text clipped - 28 lines]
> "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
David W - 20 Feb 2007 22:13 GMT
>> Hello,
>>
[quoted text clipped - 31 lines]
>
> 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
David Wilkinson - 21 Feb 2007 01:10 GMT
>>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
[quoted text clipped - 5 lines]
> <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
Wim - 20 Feb 2007 14:22 GMT
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

> Hello,
>
[quoted text clipped - 32 lines]
>
> David
David W - 20 Feb 2007 22:18 GMT
> Hi,
>
[quoted text clipped - 8 lines]
> 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
David W - 21 Feb 2007 00:27 GMT
>> Hi,
>>
[quoted text clipped - 15 lines]
> 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
Ben Voigt - 21 Feb 2007 14:43 GMT
>>> Hi,
>>>
[quoted text clipped - 23 lines]
> 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"
David W - 21 Feb 2007 22:59 GMT
> "David W" <no@email.provided> wrote in message
>>
[quoted text clipped - 5 lines]
> 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
David W - 21 Feb 2007 23:57 GMT
> 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
Ben Voigt - 22 Feb 2007 16:18 GMT
> 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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.