Windows 右键扩展菜单实现中遇到的问题
Windows 右键扩展菜单实现中遇到的问题
1. 右键扩展实现目标
实现效果如下:
![](http://images0.cnblogs.com/blog/488281/201306/09104739-8e4651a060684244aa813660ea4222ba.png)
对于文本文件点击右键,在右键菜单中出现“SimpleShlExt Text Item”菜单项。
2. 开发环境
Windows7 32位
VS2005
3. 教程与参考资料
《Windows Shell扩展编程完全指南》 请按照该指南的第一个例子做。
《ATL开发指南》(用于补充学习)
4. 遇到问题
A. Shell COM 从 VC6 移植到 VC2003或2005报错
error C2787: 'IContextMenu' : no GUID has been associated with this object
error C2440: 'initializing' : cannot convert from 'DWORD_PTR' to 'const IID *'
error C2440: 'initializing' : cannot convert from 'ATL::_ATL_CREATORARGFUNC (__stdcall *)' to 'DWORD_PTR'
error C2440: 'initializing' : cannot convert from 'DWORD_PTR' to 'const IID *'
error C2440: 'initializing' : cannot convert from 'ATL::_ATL_CREATORARGFUNC (__stdcall *)' to 'DWORD_PTR'
根据博客《Shell COM 从 VC6 移植到 VC2003或2005的问题 》中的解释:
There are two <comdef.h> header files in VC.NET, one in Vc7/include and the other in Vc7/PlatformSDK/include.
The former splits off the smart pointer typedefs into comdefsp.h, and it doesn't include IContextMenu. The latter does.
You can try to #include the PlatformSDK header directly, change your INCLUDE path order。
You can try to #include the PlatformSDK header directly, change your INCLUDE path order。
所以下载windows较新的PlatformSDK , 5.2.3790.1830.15.PlatformSDK_Svr2003SP1_rtm,可以从微软官网直接下载
安装后C:\Program Files\Microsoft Platform SDK\Include
打开comdef.h文件,可以看到缺失的GUID。
![](http://images0.cnblogs.com/blog/488281/201306/09104739-f7fc9d6b17724ba98611b7324fe0c17c.png)
调整include路径
VS2005->Tools->Options
![](http://images0.cnblogs.com/blog/488281/201306/09104740-41b09b5438e043118767c98f05c6213f.png)
B. 编译后,注册后仍没有效果
通常VS2005生成的rgs文件包含了下面的内容
![](http://images0.cnblogs.com/blog/488281/201306/09104740-fa3e1ae1efb94a31be65bc23aba48c3c.png)
而这三项仅仅是向注册表注册了你开发的DLL,而Explorer还不知道,也不知该在什么时候调用。
所以要增加下面的内容。
![](http://images0.cnblogs.com/blog/488281/201306/09104740-82868d484eaa4ebfb823fe6d0d440948.png)
修改rgs文件,增加上面的内容。
注册后,在注册表中,可以看到下面的内容。
![](http://images0.cnblogs.com/blog/488281/201306/09104741-9f120e8215a744fd9c16b9448ec76b86.png)
解决完这两个问题,我的右键菜单扩展功能已实现。