Resource loading fails in a static library (.lib)
-
Hey all. I had a DLL project (using MFC) that I recently decided to convert to a statically-linked library. Everything seemed to go smoothly, but when I try to use my library in a test application, all the resource-loading calls in the library fail. That is to say, the library project has a resource file containing some resources used in the library; a string table, a couple of bitmaps, a dialog box or two, etc. Elsewhere in the library code, there's a routine that, say, wants to get a string from the string table. So I have something like this:
CString str; VERIFY(str.LoadString(IDS_STRINGID);
When I run an application that uses this part of the library, the LoadString() function fails (returns 0). The same seems to apply for dialog boxes, bitmaps, and all other resources. A quick debug trace revealed that it was passing the correct numeric value for the resource ID; it just seemingly could not load the resource. I've never tried making a static library containing resources before, so I really have no idea what needs to be done. I'm assuming there is something in particular that I need to do so that the resources can be loaded correctly from the library. Does anyone know what I could do in this situation? Any help would be greatly appreciated. -
Hey all. I had a DLL project (using MFC) that I recently decided to convert to a statically-linked library. Everything seemed to go smoothly, but when I try to use my library in a test application, all the resource-loading calls in the library fail. That is to say, the library project has a resource file containing some resources used in the library; a string table, a couple of bitmaps, a dialog box or two, etc. Elsewhere in the library code, there's a routine that, say, wants to get a string from the string table. So I have something like this:
CString str; VERIFY(str.LoadString(IDS_STRINGID);
When I run an application that uses this part of the library, the LoadString() function fails (returns 0). The same seems to apply for dialog boxes, bitmaps, and all other resources. A quick debug trace revealed that it was passing the correct numeric value for the resource ID; it just seemingly could not load the resource. I've never tried making a static library containing resources before, so I really have no idea what needs to be done. I'm assuming there is something in particular that I need to do so that the resources can be loaded correctly from the library. Does anyone know what I could do in this situation? Any help would be greatly appreciated.I have the same problem - cannot load resources that are compiled into the static library. I know that a solution to the problem exists because there are resources in the static MFC library. When I compile using VS 2002 I get warning on the .res file corresponding to the .rc file in the static library. warning LNK4221: no public symbols found; archive member will be inaccessible I think that may be a clue to the answer. Did you ever find an answer? Thanks -Rodney
-
I have the same problem - cannot load resources that are compiled into the static library. I know that a solution to the problem exists because there are resources in the static MFC library. When I compile using VS 2002 I get warning on the .res file corresponding to the .rc file in the static library. warning LNK4221: no public symbols found; archive member will be inaccessible I think that may be a clue to the answer. Did you ever find an answer? Thanks -Rodney
Actually, I did find a solution! I did a little hunting around on Google, and I found this page: http://www.differentpla.net/~roger/devel/tips/vc/resources_in_libs/[^] It's not an incredibly elegant solution, but it's very simple, easy to use, and it works well. (On Visual Studio 6, at least; I assume it will work equally well on VS 2002, but I haven't tried it. ...Come to think of it, I've been using VS 6 ever since it came out. Oh well, if it ain't broke, don't fix it! ;)) [Insert witty and relevant signature here]