1

I'm writing a Win32 DLL that supplies "code-only" functions; there are no resources in the DLL, and the DLL has no UI. The contents are only Utility / Helper functions.

Generally, Microsoft recommends that AFX_MANAGE_STATE(AfxGetStaticModuleState()); be at each DLL-entry point. But my understanding is that its purpose is to make sure that resources are searched and loaded properly.

If my DLL has no resources, do I still need to AFX_MANAGE_STATE? Why?

EDIT: While my DLL is not specifically MFC-oriented, I am using some basic MFC types, such as CString and CList.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
abelenky
  • 63,815
  • 23
  • 109
  • 159
  • It is highly specific to MFC, not just for resources. If you use MFC then it is unwise to skip it. The MSDN documentation for DLLs is a bit top-heavy with assumptions that you are using MFC btw. It was written a long time ago, back when using MFC was still common. – Hans Passant Oct 01 '14 at 16:11
  • 3
    As you point out, the `AFX_MANAGE_STATE` macro sets up search information when looking for resources inside the DLL. Resource lookup, however, is not all that requires state information. Among many other things, MFC's class factories (and thus serialization support) require properly initialized state information, when used from your module. If in doubt, do use `AFX_MANAGE_STATE`, even if you think you do not need it. – IInspectable Oct 01 '14 at 16:15
  • Are you even using MFC? No mention of that in the Q? – David Heffernan Oct 01 '14 at 18:44
  • Please remove `Win32` tag and replace with `MFC`. – user1793036 Oct 02 '14 at 01:31
  • There is a nice explanation of AFX_MANAGE_STATE in stack overflow http://stackoverflow.com/questions/9062034/what-does-afx-manage-stateafxgetstaticmodulestate-do-exactly – Richard Chambers May 04 '15 at 11:42

0 Answers0