Link to home
Start Free TrialLog in
Avatar of daitt
daittFlag for Viet Nam

asked on

Static library with resource - how to link resource to application

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 ?
Avatar of willstones
willstones

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.
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.
Thats what I meant.... ;)  Same difference.
Avatar of daitt

ASKER

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
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.

ASKER CERTIFIED SOLUTION
Avatar of AlexNek
AlexNek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of daitt

ASKER

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:
https://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
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.
Avatar of daitt

ASKER

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