Friday, February 26, 2010

MFC DLLs: Regular vs. Extension

Dll Version of MFC
http://msdn.microsoft.com/en-us/library/hw85e4bb(v=VS.90).aspx

http://www.codeguru.com/cpp/cpp/cpp_mfc/tutorials/article.php/c4017


MFC Extension DLL -> doesn't have _USRDLL, have DllMain generated, do not have CWinApp instance instantiated

MFC Regular DLL -> have _USRDLL, doesn't have DllMain generated, have CWinApp instantiated

When exporting a function with extern "C"inside an MFC Regular DLL dynamically linked to MFC, we need to put AFX_MANAGE_STATE macro as follows


extern "C" __declspec(dllexport) int AddFive(int x)
{
     AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
     return x + 5;
}
How to provide DllMain for MFC Regular DLL

VS2008 DLL Guide


Special care need to be taken when using Regular DLL to access external resources. See the below article: