Solved

Load resources from file (probably a stupid question)

Posted on 2002-07-24
10
200 Views
Last Modified: 2012-06-27
Hi!

I would like to have separate resources for different types of data, compilation takes too long if I include the data inte the "resource.rc" thingie in visual c++, so I thougt that I should load the data from separate files instead, but then I got stuck, how do I load from a "external" resource file like a dll or somthig and how do I use that resource when loaded and how to include that in a visual c++ project and make it compile that resource only if modified when compiling the source code which ofcource should result in a different binary file after compilation.

and another stupid question, can I store classes in "resource" files so that I get for example: 1 binary for each class and some how include these classes in some kind of load session in the main class?

I think thats about it, if you know something that is relevant to this question that I did'nt know that I needed to know about this please tell me I'm not that experienced with c++ as you probably alread know if you have read this far :)
0
Comment
Question by:maho01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 350 total points
ID: 7174081
>>how do I load from a "external" resource file like a dll
>>or somthig and how do I use that resource when loaded

That is pretty straight foward, all you have to do is loading the module using 'LoadLibrary()' (will also work for .exe files) and use the handle in the calls that access the resources:

HINSTANCE hResource = LoadLibrary ( "resource.dll");

HICON hIcon = LoadIcon ( hResource, MAKEINTRESOURCE ( ID_THEICON);

BTW: If you are using MFC, 'AfxSetResourceHandle()' is what youare looking for.

>>how do I load from a "external" resource file like a dll
>>or somthig and how do I use that resource when loaded

No, not in resource file, but you can 'store' them in DLLs also. See e.g. http://www.codeguru.com/win32/dyndllclass.shtml

0
 
LVL 1

Author Comment

by:maho01
ID: 7174100
Sounds really great I did'nt this it would be hard, I'll try this when, I get home from work, is there anything that I coul'd do wrong it does'nt look to difficult, this MFC do I wan't to use that, Last time I worked in c++ I did'nt really like MFC well the name it self says pretti much everything Microsoft Foundation Classes... is this the same **** as WFC?
0
 
LVL 86

Expert Comment

by:jkr
ID: 7174116
>>... is this the same **** as WFC?

No, it's different 's**t' :o)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:ris
ID: 7174747
>>>> and another stupid question, can I store classes in "resource" files so that I get for example: 1 binary for each class and some how include these classes in some kind of load session in the main class?

You can't put a class in a "resource" file like a bitmap image, but you can put all your classes in separate DLLs.  I want to warn you against that approach though.  I used to try that approach, but I found that most of my classes called functions in each other, and that created an insane dependancy relationship between all of the separate DLLs, making it impossible to build my project when 3 separate DLLs were all implicitly linked to each other.  Consider when you "rebuild all" in your workspace and you have 2 DLLs that are implicitly linked to each other, lets call them one.dll and two.dll: the compiler attempts to build one.dll and can't because "cannot find link library two.lib" then it tries to build two.dll and can't because "cannot find link library one.lib".

So all you can do with it at that point is explicitly link your DLLs together, which requires a lot of manual coding to load the libraries and class functions in your code, or you have to do some tricky compiler work to force output even when there are errors and then build at least twice every time you do a build.

But if your classes can stand alone without calling functions in other parts of your project, then it is actually a very good idea to put them in their own DLLs.  That way they are easily reused in other projects and easily maintained if you improve just one class, you can upgrade your old project by replacing one DLL instead of recompiling the whole thing.

I hope I didn't go too far over your head with those comments.  Let me know if anything is unclear, confusing, or incomplete and I will be happy to explain it in more detail.
0
 
LVL 1

Author Comment

by:maho01
ID: 7178185
The genius is back ;) another stupid question what would be the easiest way to create a file(know as resource.dll above) containing all my resources that I want in another file than the application would it be to simply "compile xxx.rc" or is there any other way?
0
 
LVL 86

Expert Comment

by:jkr
ID: 7178201
YOu mean a "resource-only" DLL? Just create a Win32 DLL project that contains nothing but a .rc file...
0
 
LVL 1

Expert Comment

by:ris
ID: 7178277
You have to have a DllMain too, don't you?  I could be wrong about that, but I think if you try to compile xxx.rc by itself into a DLL, you get a linker error "cannot find function: int DllMain(HANDLE, DWORD, LPVOID)" or something like that...

If you need it, this is the simplest possible DllMain code:

#include <windows.h> //for typedefs, etc.

BOOL DllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved)
{
  return TRUE;
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 7178299
>>You have to have a DllMain too, don't you?

No, not necessarily - I just checked that with one of our resource-only DLLs.
0
 
LVL 1

Author Comment

by:maho01
ID: 7178343
Works great, thanks.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7178348
Tahnk you! Completely my pleasure :o)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question