Solved

Load resources from file (probably a stupid question)

Posted on 2002-07-24
10
196 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ assignment question 7 165
Cross compile release version of c++ program for linux 2 129
mixing C++ & C# in Vis Studio 2013 7 139
sorting efficency of sorting algorithm 30 99
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now