Solved

Load resources from file (probably a stupid question)

Posted on 2002-07-24
10
197 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
  • 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

810 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