Solved

Linking a static library with resources.

Posted on 2004-09-28
6
370 Views
Last Modified: 2013-11-20
Hi

I have a problem i cannot solve and perhaps you may help.
But first i explain what i did.

I create a static MFC library.
The library includes some classes and ressources.
I change the resources ID to be sure to not use the same IDS as in the MFC exe i will link the library.
I build the library and all is ok.

Now i open my MFC exe project to link the library in.
I add the library ressources header file and the library rc file in my own rc file.
I add the library itself to my project.
I compile and all is ok.

Now the problem occurs at runtime.
I launch my application and the program make very strange exception for example in new operator (very standard new) or other type of code that works perfectly without adding the library.

Does somebody know what i did wrong ?

THanks


0
Comment
Question by:eric3333
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 12171186
>>I launch my application and the program make very strange exception for example in new
>>operator

Is the static library set to "Use MFC in a shared library"? It should (and so should the other components), in order to avoid conflicts.

BTW, the "usual" way is to have resources in a DLL (resource-only, if needed) rather than in static libs. See e.g. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_Create_a_Resource.2d.Only_DLL.asp ("Creating a Resource-Only DLL")
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 150 total points
ID: 12171876
>> Does somebody know what i did wrong ?

Not exactly, but i would like to make a guess:

The compiled resources of an executable were added separately to the executable file. That's why you may edit resources of an executable by using a resource editor. You added compiled resources both to the executable and to the static library. Most likely the resources now weren't linked to one contigous resource block, what might lead to the (addressing) problems you described.

What to do?

Remove the rc file from the static library and include it from your application's resource file (use menu View - Resource Includes - Compile-time directives). Add the resource header to the "Read-only symbol directives". Or use a separate resource dll as the link of jkr describes.

Regards, Alex




0
 
LVL 6

Assisted Solution

by:Amritpal Singh
Amritpal Singh earned 150 total points
ID: 12177059
plz have a look at the following link

http://www.differentpla.net/~roger/devel/tips/vc/resources_in_libs/

may be u can find wat's wrong
BOL
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:eric3333
ID: 12177566
HI everybody.

I found the problem. I am just an idiot.
Both the library and the exe uses MFC.
And i link a release version of the library with a debug version of the exe. And all the problems come from this.
Now all works fine.

One point for itsmeandnobodyelse.
When you add a RC in a library the RC is not linked to the library because a library cannot integrate resources.
Only DLL can be linked with rc.

I share the points to everybody. Thanks again.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12177717
>>> because a library cannot integrate resources.

Thank for the info. I didn't know what happens if you add an rc file to static library project.

Regards, Alex
0
 

Author Comment

by:eric3333
ID: 12177740
Yes
In fact when you add a rc to a library you can use studio but only for this.
The rc is not linked.
Best regards
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 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

17 Experts available now in Live!

Get 1:1 Help Now