Solved

Linking a static library with resources.

Posted on 2004-09-28
6
377 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 134
ffmpeg - "rtsp://...... Operation not permitted" 4 89
fizzArray2 challenge 1 103
Windows shortcut location resolution on double click open 4 55
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

726 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