Category Archives: MFC

_DllMain@12 already defined

We recently faced this linkage error: error LNK2005: _DllMain@12 already defined in MSVCRT.lib(dllmain.obj) Searching gives ~36K results as of July 2012, many of which seem high quality (StackOverflow, MS, CodeProject etc.), and I was certain it would be a simple … Continue reading

Posted in Debugging, MFC | 6 Comments

On AFX_MODULE_STATE, Appendix

My recent AFX_MODULE_STATE plunge was driven by some real world problems. In parallel to the write-up I mailed the current MFC chief maintainer, Pat Brenner – who directly invited such user interaction. The correspondence that ensued makes semi-official claims that … Continue reading

Posted in MFC | Leave a comment

On AFX_MODULE_STATE, or – Avoiding afxCurrentInstanceHandle Asserts, Part 2

(Part 1.) The AFX_MANAGE_STATE macro is an iceberg-tip of some heavy machinery, whose documentation leaves much to be desired. Here’s an attempt to fill in some more blanks. Mid-Depth Dive Answering a question raised at part 1, the basic statement … Continue reading

Posted in MFC | Leave a comment

On AFX_MODULE_STATE, or – Avoiding afxCurrentInstanceHandle Asserts, Part 1

All too often I see one of these asserts fire: These are coded in afxwin1.inl, and are part of the MFC high level accessors: If these asserts fire for you too, there’s a good chance you’re missing some afx module … Continue reading

Posted in MFC | Leave a comment

Three F-keys Gotchas

We recently did a small internal app, that had to use all 12 F-keys – which turned out to be surprisingly cumbersome. I hadn’t found this stuff concentrated on a single place, and certainly it could have saved me some … Continue reading

Posted in MFC, Win32 | Leave a comment

AfxIsValidAddress (and Others) Don’t Work as Advertised

MFC exposes a some memory debugging facilities such as AfxIsValidAddress, which (for debug builds) supposedly – Tests any memory address to ensure that it is contained entirely within the program’s memory space. Or does it?   AfxIsValidAddress only delegates the call … Continue reading

Posted in MFC, Win32 | Leave a comment