MFC程序中添加ICONTEXTMENU菜单 VS2005编译错误

来源:互联网 发布:知乎开放注册时间 编辑:程序博客网 时间:2024/05/24 06:31

想在自己的MFC程序中添加ICONTEXTMENU菜单,于是找到了这篇文章:

 

自己动手写一个简单的Windows shell扩展程序

 

但是按照作者指示下载的代码是VC6的代码,在VS2005下编译,会有错误提示

BEGIN_COM_MAP(CImportShellExt)

       COM_INTERFACE_ENTRY(IImportShellExt)

       COM_INTERFACE_ENTRY(IDispatch)

       COM_INTERFACE_ENTRY(IShellExtInit)

       COM_INTERFACE_ENTRY(IContextMenu)

END_COM_MAP()

第五行代码出错,错误信息为;



1>d:\test\importshell\importshell\importshellext.h(46): error C2787: 'IContextMenu' : no GUID has been associated with this object
1>d:\test\importshell\importshell\importshellext.h(46) : error C2440:'initializing' : cannot convert from 'DWORD_PTR' to 'const IID *'
1>        Conversion from integral type to pointer typerequires reinterpret_cast, C-style cast or function-style cast
1>d:\test\importshell\importshell\importshellext.h(46) : error C2440:'initializing' : cannot convert from 'ATL::_ATL_CREATORARGFUNC (__stdcall *)'to 'DWORD_PTR'

查找到了如下的解决方法:

VS2005& VS2008C++转换问题总结

以下转自此篇文章:

1转换VS6.0

ATL,看到 http://www.codeproject.com/shell/shellextguide1.asp测试了一下,发现 VC6 编译,VC8

 

COM_INTERFACE_ENTRY(IContextMenu)


处提示错误:

no GUIDhas been associated with this object

上面 URL的文章,已经给出解决方案了,就是升 Platform SDK,并把 $(VCInstallDir)PlatformSDK\include 放在 Include第一位,或者不放第一也至少要在 ($VCInstallDir)include前面!

我自己发现法是,

1> 加一句定

struct __declspec(uuid("000214E4-0000-0000-C000-000000000046"))IContextMenu;

 

2> 不要用 

COM_INTERFACE_ENTRY(IContextMenu)


换成 

COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu)

 

#include <shlguid.h>


当然第一种方法是最好的,在写WTL 程序时也要求这样做,不过要是暂时没条件升级 Platform SDK,倒是可以先用用另外两个办法。

 

2. vs2008->vs2005 (本人试验过,确有效)

VS2008.sln .vcproj VS2005

编译个WowModelViewer就不用装VS2008了。

.sln文件中:

Microsoft Visual Studio Solution File, Format Version10.00

# Visual Studio 2008

修改

Microsoft Visual Studio Solution File, Format Version9.00

# Visual Studio 2005


.vcproj文件中:

<<>="VisualC++"Version="9.00"Name="wowmodelview"ProjectGUID="{DCA0C667-2A7A-4FCE-AD02-466F7A380E0C}"RootNamespace="wowmodelview"<>="Win32Proj"<>="131072<>


开头的这句把9.00改为8.00就可以了。


3.vc目用vs2005

4.无法打开,can not open files即无法找到文件,因于包含目录设置需要修改。

VS2005例:

需要修改以下三个包含目

i
c++编译-》常-》附加包含目

ii、link接器-》附加包含目

iii
源-》附加包含目

修改法如下:

1>
注意路径置是否有

2>
尽量将相路径改为绝对路径。

 

5.lib文件

 

The first step iscreate an import library. Start a MSVS Command Prompt, and go to the GnuTLSinstallation directory.

 

<def:libgnutls-26.def FilesGnuTLSbin>lib>

 

 

This willcreate a libgnutls-26.lib that can be used as a import library for VisualStudio projects.

 

Build asample program to test it as follows:

 

< C:Program 1.6.0foo FilesGnuTLSbin>foo ... libgnutls-26.lib -Dssize_t="long"include -I.. foo.c FilesGnuTLSbin>cl>

 

 

Thesesteps are not fully polished yet, but appear to work.

 

0 0