Solved

Linking a static library with resources.

Posted on 2004-09-28
6
371 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need Help INsttalling wget on Mavericks OS X 3 90
Strange date stored 22 106
Tab names are off by one 5 53
how to use laptop or pad camera in vb.net windows application 2 49
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

912 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