您的位置:首页 > 其它

VS2010和VS2008 KB2465361之后,MFC静态链接 EXE体积变大问题

2011-05-07 19:03 525 查看
原文链接:http://tedwvc.wordpress.com/2011/04/16/static-mfc-code-bloat-problem-from-vc2010-is-now-in-vc2008-sp1security-fix/

大意是:

在KB2465361之后。themehelper.cpp 中调用了afxglobals.cpp中的 AfxLoadSystemLibraryUsingFullPath函数。造成afxglobals.obj 的引入。从而产生代码至少增加1.2M。

解决方法

1.卸载KB2465361,这个方法太弱智了。不小心也许又打上了。

2.在你自己的工程的stdafx.cpp中增加以下代码

]// this is our own local copy of the AfxLoadSystemLibraryUsingFullPath function
HMODULE AfxLoadSystemLibraryUsingFullPath(const WCHAR *pszLibrary)
{
WCHAR wszLoadPath[MAX_PATH+1];
if (::GetSystemDirectoryW(wszLoadPath, _countof(wszLoadPath)) == 0)
{
return NULL;
}
if (wszLoadPath[wcslen(wszLoadPath)-1] != L'//')
{
if (wcscat_s(wszLoadPath, _countof(wszLoadPath), L"//") != 0)
{
return NULL;
}
}
if (wcscat_s(wszLoadPath, _countof(wszLoadPath), pszLibrary) != 0)
{
return NULL;
}
return(::AfxCtxLoadLibraryW(wszLoadPath));
}


其实这段代码与afxglobals.cpp中的代码一样。目的只是避免引入afxglobals.obj。

这样,你的程序体积又恢复正常了。减肥成功。。。恭喜恭喜。

推荐下面的方法

1、stdafx.h中注释掉

//#include <afxcontrolbars.h> // 功能区和控件条的 MFC 支持

2、app中将从CWinAppEx派生改成从CWinApp派生(直接在 stdafx.h 里
#define CWinAppEx CWinApp)

3、副作用:会导致一些头文件需要自己加

打了VS2008 SP1补丁会将CWinApp升级为CWinAppEx..这也是增肥的原因之一
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: