Solved

Static library with resource - how to link resource to application

Posted on 2002-06-24
9
712 Views
Last Modified: 2012-05-04
I have a static library VC++ project. I put some resources into it. I compile it and I got a .lib file + a .res file.
I created another application which links with that lib file. Everything works ok, but the application seems not be able to load the resource in my static library. I heard somebody said static libs don't contain resource and we must link .res file explicitly. But MS VC++ only accept one .res file per project, so I cannot link the library's .res file without remove my application's .res file.
What do I do ?
0
Comment
Question by:daitt
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 2

Expert Comment

by:willstones
ID: 7104020
Only thing I can think of is to copy the res from your library into your new project, then add all of your new resources to that.  Not sure if it will work, but worth a try.
0
 
LVL 3

Expert Comment

by:Crius
ID: 7104246
A .res file is actually a compiled .rc file, it's a binary file. I know of no way to add more things to a .res file, nor should you.

What I've always done is duplicate the resources and IDs in the .rc and resource.h files of the .exe project... It may not be the most desirable way of doing things, but it definitely works.
0
 
LVL 2

Expert Comment

by:willstones
ID: 7104276
Thats what I meant.... ;)  Same difference.
0
 
LVL 3

Author Comment

by:daitt
ID: 7104305
I'm building something like an SDK, so I want an easy way for application developers to import my library into their application. My library uses some resources internally, so I don't want to show them to the app developers because it makes things complex when developers have to add some resources without knowing what they are.
Any idea make things easier? What is the way other people using when dealing with this?
Thanks for your help
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 1

Expert Comment

by:Levant
ID: 7106651
As Cruis pointed out, .res is a compiled .rc file. But there is a way of including your .rc file from the LIB into your application's .rc file. If you're using Visual Studio (I'm using 6.0 and suppose it works in any version) you go to the resource tab, right click on your project and one of the menus you should see is called: "Resource Includes...". Choose it and add an include to your LIB's .rc file in the "Compiler-time directives" section. It surely works.

0
 
LVL 16

Accepted Solution

by:
AlexNek earned 50 total points
ID: 7108183
2 daitt
[Levant] show you correct way. But you need some additional steps.
Dialog "Resource included" contain 3 edit fields:
1.Symbol Header File
2.Read only Symbol directives
3.Compile Time Directives

Follow the next steps, please:
- In LIB project rename resource.h to rc_MyLib.h (by sample) using Dialog "Resource included" field 1.
- Check that you have different resource id range in LIB and in MAIN projects. Correct id's if you need.
- In MAIN project Dialog "Resource included" field 2 add #include "rc_MyLib.h"
- In MAIN project Dialog "Resource included" field 3 add #include "MyLib.rc". If you use multi language resource you must add this line in all sections.
- In MAIN project setting/resources/additional resource include directories add relative path to your LIB project.
- Rebuild all prjoects.


0
 
LVL 3

Author Comment

by:daitt
ID: 7109902
I followed all the steps AlexNek described above and it works perfectly. Of course I had to add the .ico and .cur files into my main project folder but it's ok, the developers just need to follow these steps.

I accepted AlexNek's comment because it's more complete. I also posted a 50 points question for Levant at:
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=cplusprog&qid=20316310

Levant, please come and propose an answer to take your points.
Thanks for your helps
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 7110082
Thank you [daitt]
You don't need to copy *.ico files to your main project. We used the next directory structures:

project root
  Main
    res
  Lib
    res
 
where res directory contain .ico .res and other resource files except .rc .h

I forgot one step, you need to rename "resource.h" in your LIB sources too.
0
 
LVL 3

Author Comment

by:daitt
ID: 7110159
I deliver my lib as a folder, so I had to copy everything users need into that folder. That includes rc file, resource.h file (renamed), .ico and .cur files.
Yeah I changed my source code to use the new resource header file, otherwise it wouldn't compile.
Thanks
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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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.

867 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

18 Experts available now in Live!

Get 1:1 Help Now