I want to define _AFX_NO_MFC_CONTROLS_IN_DIALOGS for a MFC project. This define is supposed to reduce considerably the executable size. See https://blogs.msdn.microsoft.com/vcblog/2012/02/06/reducing-the-size-of-statically-linked-mfc-applications-in-vc11/ for more details.
I created a "Mfc Application" using the wizard. I kept all default options except that I use "Use MFC in a static library" (this is mandatory for me).
At this point, the project builds.
Then, I add the following line in the stdafx.h file:
#define _AFX_NO_MFC_CONTROLS_IN_DIALOGS
At this point, I get some linker errors:
1>uafxcwd.lib(afxctrlcontainer2.obj) : error LNK2005: "void __cdecl AfxRegisterMFCCtrlClasses(void)" (?AfxRegisterMFCCtrlClasses@@YAXXZ) already defined in afxnmcdd.lib(afxctrlcontainer2.obj)
1>uafxcwd.lib(afxctrlcontainer2.obj) : error LNK2005: "protected: void __thiscall CMFCControlContainer::PreUnsubclassControl(class CWnd *)" (?PreUnsubclassControl@CMFCControlContainer@@IAEXPAVCWnd@@@Z) already defined in afxnmcdd.lib(afxctrlcontainer2.obj)
1>uafxcwd.lib(afxctrlcontainer2.obj) : error LNK2005: "public: int __thiscall CMFCControlContainer::SubclassDlgControls(void)" (?SubclassDlgControls@CMFCControlContainer@@QAEHXZ) already defined in afxnmcdd.lib(afxctrlcontainer2.obj)
But if I go in the project settings and change the character set from Unicode to Multi-Byte, everything is fine.. Anybody knows what is going on? I need to integrate this change in some big and old MFC projects, so I absolutely need to keep the "Use Unicode Character Set" flag.
Defining _AFX_NO_MFC_CONTROLS_IN_DIALOGS is not enough, you have to make sure that you don't use extended MFC classes like CDialogEx and CWinAppEx (which are used by MFC application wizard by default). Replace them with CDialog and CWinApp. After that you will propably get some compiler errors from code that initialize various GUI "manager" instances. Just remove this code.
Even easier, when using MFC application wizard to create a new app, set the checkbox for "no extended MFC controls" (only available for dialog-based apps). Then it won't generate code that uses CDialogEx and CWinAppEx and I think it will also define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With