Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Load resources from file (probably a stupid question)

Posted on 2002-07-24
10
Medium Priority
?
204 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 1400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

722 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