Solved

Linking a static library with resources.

Posted on 2004-09-28
6
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

705 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