userrmgs
userrmgs

Reputation: 323

Dialog resources in a static library

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.

Upvotes: 2

Views: 734

Answers (1)

Adrian Mole
Adrian Mole

Reputation: 51894

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!

Upvotes: 2

Related Questions