解决办法:
项目属性页,项目默认值->MFC的使用,将“在共享DLL中使用MFC”,改为"在静态库中使用MFC"。
原因:
1."Choosing Use MFC In A Shared DLL minimizes your application's executable file size by allowing MFC to be accessed from a DLL. If you choose Use MFC In A Static Library instead, Visual C++ links MFC code into your application's EXE file and the file size grows considerably. Static linking uses disk space less efficiently than dynamic linking because a hard disk containing 10 statically linked MFC applications contains 10 copies of the same MFC library code. On the other hand, an application that is statically linked can be run on any PC, whether or not the MFC DLL is present. It's your call whether to link to MFC statically or dynamically, but remember that if you distribute a dynamically linked EXE, you'll need to distribute the DLL that houses MFC, too. For a release-build MFC application created with Visual C++ version 6, that DLL is named Mfc42.dll if the program uses ANSI characters and Mfc42u.dll if it uses Unicode characters."
摘自<<programming windows with MFC>>
2.静态链接,将DLL库的内容,直接添加到生成的EXE中,并作为EXE文件的一个静态部分运行。作为静态链接,你不需要担心运行时需要的相关库文件,因为都链接到EXE文件中了。
动态链接,生成的EXE文件,公包括EXE内部的内容,运行时,根据需要,加载相应的DLL。作为动态链接,你需要将运行时相关的DLL库文件放到相关的地方(1、与EXE同文件夹;2、系统环境变量Path指定的其它路径)。
关于内存访问,使用静态链接,在DLL中动态分配(new)的内存,只能由DLL回收(delete),强制EXE回收可能会有异想不到的结果。动态链接,在DLL里动态分配(new)的内在,可由EXE回收(delete)。
3.共享DLL, EXE小,但是如果系统中没有这个DLL,就无法运行。
静态链接,是把代码链接到EXE中,EXE大,但是不依赖那个DLL了。