Advertisement

Multiple RC files in MSVC++ project?

Started by March 24, 2001 11:33 AM
11 comments, last by treadwell99 23 years, 10 months ago
I got a problem with rc files and MSVC++: I''m having a problem using multiple *.rc files in one project in MS Visual C++ 6.0. I have three *.rc/*.rh files that contain their own dialog boxes and resources. But MSVC++ only lets me have one active while the othe two are excluded from the build. I get this message when I try to add another rc file into the project: "Multiple .rc files exist in this project. Only one can be marked as included in the build. The others will be excluded from the build." I don''t want to put all my dialog boxes and resources into one resource script file. How do I fix this? -treadwell99
I believe that you can simply include external resources in your .rc file. If you look at your .rc file in notepad, afxres.rc should already be included. I haven''t messed with this much (most of my stuff I merely make a .dll for that batch of dialogs and controls and use them that way). If you''re attempting to do common dialogs and menus or something along that line, try using a resource template (.rct).

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Advertisement
Im not entirely sure its possible to have multiple resource files in MSVC++, frankly I see no reason to need more than one. MSVC does an excellent job of adding structure and organization; it divides all the dialog boxes, menus, string tables, etc into seperate folders and makes everything look pretty.

Why do you want two seperate .rc files anyways?
Ciphersoftware website

Support the open source community

When you create an MFC project using the wizard, VC++ creates a file ProjName.rc and ProjName.rc2. This RC2 file is a part of the project but doesn''t get compiled along with everything else, it simply gets included in ProjName.rc.

If you are typing your rc files by hand then you can go ahead and add an rc2 file to your project.

Other than that, I''m pretty sure the standard is one resource file per app.
Qoy,
Yeah, I was briefly playing around with the MFC Appwizard yesterday and noticed this bit of code in the main (one and only) rc file:
  3 TEXTINCLUDE DISCARDABLE 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"	"#ifdef _WIN32\r\n"	"LANGUAGE 9, 1\r\n"	"#pragma code_page(1252)\r\n"	"#endif //_WIN32\r\n"	"#include ""res\\DlgMFCAppWizExe.rc2""  // non-Microsoft Visual C++ edited resources\r\n"	"#include ""afxres.rc""  	// Standard components\r\n"	"#endif\r\n"    "\0"END  

I believe(correct me if I''m wrong since I haven''t tried this) I can just add more *.rc2 files in the res folder and add the includes into the main rc file above and...everything will work fine? I''ll implement it this way if I can''t get the library thing to work (see below.)

Ciphersoftware,
quote:
Why do you want two seperate .rc files anyways?

reusable dialogs, mainly...so that i don''t have to cut and paste from the main application rc file if I need to...say, add them in another application later.

felisandria,
quote:
I haven''t messed with this much (most of my stuff I merely make a .dll for that batch of dialogs and controls and use them that way).


Well, here''s what I also tried (something similar to what you suggested, but still haven''t gotten it to work): I made a separate static lib (separate win32 static lib project) for my rc/rh, custom dialogs, plus other implementation files and added that lib to my main project. For example, I placed the About Box rc/rh/cpp/h dialog files into one library. Everything compiled fine with no errors and warnings but when I ran the program and selected the "About App..." MenuItem, the About Dialog does NOT pop up. I checked the IDs and init code of the About dialog but everything looks fine. I also checked the VC++ project settings included the lib path and included individual lib into the project. And I also played around if the project dependencies checkboxes to no avail.

So how the hell do you include a library into an existing project and make it work properly? Got any good links? Tips?

Thanks guys for the replies.

-treadwell99

P.S.
Is there a way to open RC files in VC++ "in text edit mode"(not using Resource View tab)?
The only way I can do this is when I get flagged for an error concerning mismatched/unknown IDs in the rc/rh where you can clicked the error in the output window popping up the rc code to edit.

You can include multiple .rc files, its just not intuitive or very obvious.

From the IDE, if you select View | Resource Includes ...
you will get the Resource Includes dialog.

You can enter additional .rc files in the section titled "Compile Time Directives", usually just after the standard "afxres.rc" include.

This actually just inserts a similar block of code in your main projects .rc file:

3 TEXTINCLUDE DISCARDABLE
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"
"#ifdef _WIN32\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#endif //_WIN32\r\n"
"#include ""res\\ResourceModify.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#include ""OXOptionTreeCtrl.rc""\r\n"
"#include ""OXCustomizeManager.rc""\r\n"
"\r\n"
"\r\n"
"#endif\r\n"
"\0"
END


-Z
Advertisement
Open your main .rc file and include the other 2 resource files with:

#include "resource2.rc"
#include "resource3.rc"

Add the main resouce to your project.

This should solve your problem.

Arun
The examples people are giving you are what I meant by "just include the .rc file". You just can't name it .rc, because the compiler has to determine a single .rc to start with and it gets upset otherwise. This is a viable technique.

If you want to know how to use other .dll's to pop up dialogs and good stuff like that, I need to know where you're starting from. Do you have a working knowledge of dynamic links via function pointers? I want to know how much you know so I know how much of a tutorial I need to write. It's a nice thing to be able to do but it's not really terribly simple. Not terribly hard, either, but not just "type this and go". Still curious?

-fel

Edited by - felisandria on March 26, 2001 6:32:52 PM
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
quote:
Still curious?

Yeah, I''m still curious.
quote:
I need to know where you''re starting from.

Well, I''m a beginner in using MFC and have limited knowledge in windows programming. ...using the book "Teach yourself MFC in 24hours." This is my first attempt in making a dialog-based MFC application. As for DLLs, the only knowledge I have is from a small chapter in the book and from flipcode.com (http://www.flipcode.com/tutorials/tut_dll01.shtml) which pretty much covers to same stuff. That''s it. So, dummy-level is fine with me.
quote:
Do you have a working knowledge of dynamic links via function pointers?

Ughmm...I''m going to say "no" on this one.
quote:
I want to know how much you know so I know how much of a tutorial I need to write.

This is something that would be cool to know but, truthfully, I don''t think I''m going to use it anytime soon. But I wouldn''t mind having this knowledge in case might need it sometimes in the future. But don''t sweat it if you don''t have time or forget--or something.

Thanks.

-treadwell99

Disclaimer: This is the way I know how to do this. I don''t know if it''s necessarily the only or the best way. Now, I know it''s good to keep a list of the libs you have currently loaded and all that good stuff, and I do that, but I''m not going to put it in here because that would be too long and I don''t have a lot of time right now.

Okay, so...

Working on the assumption that you''ve managed to make a .dll with some dialogs you want to use in it, first we''re going to have to pick up a dynamic link to the .dll containing the stuff you want to pop up. Assuming you know the library name and the function name, you have to:

// load your library with the function in it
HINSTANCE libraryInstance = LoadLibrary( strLibraryName );
// load your function
void * functionPointer = GetProcAddress( libraryInstance, strFunctionName );

Now, those two lines will pretty much load any function out of a .dll dynamically for you and give you a function pointer. This doesn''t necessarily have to be a dialog. From there you can probably figure out which functions you can use to set up and run your dialog... I would go over it but I''m a bit short on time right now.

-fel



~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~

This topic is closed to new replies.

Advertisement