2
votes

I have a problem with dialog and icon resources in my static library. I have created a MFC static library with Visual Studio 2008.

I am calling Func() in the static library from Win32 application, It tries to launch a MFC dialog in the static library.

When trying to access the resource I am getting afxCurrentResourceHandle is NULL assertion.

I add this line AFX_MANAGE_STATE(AfxGetStaticModuleState()); in the Func() as the first line. But it didn't help.

I need to use only static library. As per requirement, I should not use dll.

Please help me how to launch a dialog in MFC static library from a non MFC application.

1
@Algirdas The link u suggested does not solve the problem.userrmgs
OT: This question strikes me close to home, since I am, currently, in process of fixing a defect, which occurred because someone moved code to a static lib (from a .dll), which resulted in certain dialog failing to be displayed..Algirdas Preidžius
"The link u suggested does not solve the problem." What solution do you want? Static libs can't contain embedded resources. And the linked question explains that, while providing several solutions, around such limitation.Algirdas Preidžius
Yes, that's the problem, that I was seeing as well. Please re-read the duplicate suggestion, so you would understand the possible ways to solve the problem. TLDR version of it, as I already stated: static library can't contain resources.Algirdas Preidžius

1 Answers

2
votes

The problem here is that a static library doesn't have an 'associated .res file'. If you are trying to migrate a DLL with resources to a static library, then you will need to also 'export' the resource script (its .rc file plus any associated .rc2 files and other referenced resources) to the client program!

So, just as you would have an #include "module.h" line in the .cpp source(s), you will also need an #include "module.rc" in your program's main .rc file (or, at least, in a file that it includes).

Note: Other fixes that folks have tried, like linking explicitly with extra (pre-compiled) .res files won't work! Although the internal structure of a binary .res file is very similar to any other .obj file, the linker will only ever include one!