Joseph M. Newcomer replied to mk
12-Feb-10 08:51 AM

See below...
****
MFC DLLs were never intended to be "self-contained" in the fashion you interpret. MFC is
and always has been a set of version-specific libraries that work with an executable
image.
The Windows API DLLs are also not "self contained"; some APIs have been deprecated (most
of the Win16 APIs are gone, for example MoveTo); others have been added, on each release.
Therefore, you cannot be guaranteed that you can run an executable built for OS version
n+1 on version n or lower.
****
****
Any interface you export from an MFC-based DLL has potential problems. Key here is that
you must build a truly isolated component. It may not return any MFC-based objects to its
caller, may not rely on any MFC-based state (such as the handle map), and must present a
pure C-compatible interface to its callers. Extension DLLs violate the assumption that it
does not need to rely on any MFC-based state, and therefore present serious problems.
Note that this is true for any library system; it is not limited to MFC. Consider if I
have a database library in a DLL. I wrote another DLL which uses the database library. My
DLL, call it A, was built with database library version 1.0. You want to use my library,
but you only have database library version 2.0. Lots of luck. It probably will not work,
for a variety of reasons. Try mixing two versions of the C runtime.
In other words, you have some unrealistic expectations of the MFC DLLs, and when they
do not live up to your unrealsitic expectations, you think this is a condemnation of the
MFC concept. It is not. It is true for nearly any library set in existence, and the few
execeptions are extremely rare.
Note that you cannot substitute GDI32.DLL from Vista for the GDI32.DLL that comes with
Win7. Is that a condemnation of the Windows kernel?
Microsoft goes through IMMENSE amounts of effort to try to maintain the stability of the
Win32 API interface. This is rarely justified by anything outside. For years, they
maintained a common MFC runtime, MFC42.DLL, which had the property that it kept changing
and extending, but was compatible with MFC 4.2, 5.x and 6.x. Eventually, this became
impossible to continue doing. They abandoned this approach with MFC70. So yes, you now
have to produce versions of your extension DLLs compatible with MFC70, MFC71, MFC80 and
MFC90. As well as U and D versions. I know of no workarounds for this piece of reality.
it is how the world works.
Note also that static linking does not solve this; rather, static linking makes this
problem immediately serious, since each DLL has its own private copy of the MFC library
linked into it, and these copies do not share anything. This means you get the problem on
every build, not just when the MFC application version changes.
joe
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm