最近在VC编程时,调用 InitCommonControlsEx失败 。究其原因,是 manifest作怪。
解决方案有三:
1) Create manifest, call it YourApplicationName.manifest and add it to your application folder.
2) Create manifest and add it to your application resources.
3) Add #pragma comment(linker, "/manifestdependency:/"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'/"")
in stdafx.h.
我选择的是方案三。
InitCommonControlsEx的介绍参见:http://hi.baidu.com/luckily513/blog/item/c9b8a7b3451eeab2d8335a5d.html
从原文摘抄如下:
MFC工程中,在InitInstance()函数(一般在工程名.cpp文件中)中有这样一段代码:
*************************************************************************************
// 如果一个运行在 Windows XP 上的应用程序清单指定要
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof (InitCtrls);
// 将它设置为包括所有要在应用程序中使用的
// 公共控件类。
InitCtrls.dwICC = ICC_WIN95_CLASSES ;
InitCommonControlsEx (&InitCtrls);
**************************************************************************************
这些代码的作用,注释里已经说的很清楚了,我们先来看下这写代码是什么意思。
我们从InitCommonControlsEx 函数下手,其函数原型为:
BOOL InitCommonControlsEx (
LPINITCOMMONCONTROLSEX lpInitCtrls
);
其有一个参数lpInitCtrls, 是一个指向结构体INITCOMMONCONTROLSEX 的长指针,上面的代码先创建一个 INITCOMMONCONTROLSEX结构体对象 InitCtrls,然后将其地址作为 InitCommonControlsEx

本文探讨了在VC编程时遇到InitCommonControlsEx调用失败的问题,原因是manifest的影响。提供了三种解决方案,作者选择了在stdafx.h中添加#pragma comment(linker)指令。文章详细解释了InitCommonControlsEx函数的作用,以及manifest在DLL和应用程序管理中的角色,特别是在Windows XP之后的版本中如何避免“DLL Hell”问题。
最低0.47元/天 解锁文章
3547

被折叠的 条评论
为什么被折叠?



