Solved

Linking a static library with resources.

Posted on 2004-09-28
6
376 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 6 68
wait notify demo infinite loop 3 121
ShiftLeft challenge 21 84
zeroFront challenge 7 111
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: 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 …
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

808 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