KB2465361 导致静态链接 MFC 库的应用程序文件增大

摘要翻译自:Static MFC code bloat problem from VC2010 is now in VC2008 SP1+security fix

大致原因:themehelper.cpp 使用了 afxglobals.cpp 中的内联方法 AfxLoadSystemLibraryUsingFullPath,而 afxglobals.obj 会带来其它一堆跟班,然后最终的输出文件就无形中自我膨胀了。。。

解决方法:在 stdafx.cpp 中的 #include “stdafx.h” 之后加入如下代码,其实也就是把 MFC 中的方法复制一份出来,然后重新编译程序吧~

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));
}

ps. 微软最近几次和开发环境有关的更新真是不给力啊,包括上一次 Win7 SP1 导致的 ADO 组件兼容性问题。。。

update 04/27:

官方也注意到这些问题了,但貌似目前的解决方法就是卸载更新包,继续等待~

update 06/18:

官方修正已发布,可通过 Windows Update 来升级。

This entry was posted in 软件开发 and tagged , . Bookmark the permalink.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s