4、错误"no GUID has been associated with this object"的解决方法

简介: [问题描述] 用VS2008编译windows shell时,成功;相同的方法在VS2005下,提示错误: error C2787: 'IContextMenu' : no GUID has been associated with this object error C2440: 'initia...

[问题描述]<?xml:namespace prefix = o />

VS2008编译windows shell,成功;相同的方法在VS2005下,提示错误:

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'

[解决方法]

关键的问题是以下头文件没有包含正确

#include "shlobj.h"

#include "comdef.h"

#include <shlguid.h>

下面是收集的一些问题解决过程:

1Have you downloaded the Latest Platfrom SDK? If so, are your vc dirs pointing to the proper include dirs, eg: shlguid.h is getting picked up from the SDK\include and not the vc98\include. You set those in the tools-Options->directories->include dirs for VC

2There 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, or supply the missing typedef yourself, e.g.

struct __declspec(uuid("000214e4-0000-0000-c000-000000000046"))

IContextMenu;

_COM_SMARTPTR_TYPEDEF(IContextMenu, __uuidof(IContextMenu));

3、怎样找到InterfaceGUID?

我在注册表 HKCR\Interface\ 下可以找到形式为

{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee}的键,如果其下有默认项="Interface",则说明这个键就是该InterfaceGUID

有没有其它方法?

(1) VC6\common\Tools 下有个OLE/COM Object Viewer 很方便,但在VC2005下就没找到这个工具

(2) PlatformSDK\include\comdef.h 中也有GUID的定义

4__uuidof它是C++ 运算符

[总结]

如上所述,如果把PlatformSDK/include放在前面仍然不可以的话,就下载新的SDK,把include目录包含进去就好了。个人感觉手动添加这些uuid值如,struct __declspec(uuid("000214e4-0000-0000-c000-000000000046"))

IContextMenu;

_COM_SMARTPTR_TYPEDEF(IContextMenu, __uuidof(IContextMenu));

过了这个村,还会有下个店,还不如直接更新一下SDK来得直接保险。

参考:

[1] 比较杂,没有记录出处。可以GOOGLE到。

目录
相关文章
|
iOS开发
Objective-C中的associated object释放时机问题
如果对象A持有对象B,B作为A的associated object,并且表面上B没有其他被强引用的地方,那么对象A被释放时,对象B一定会同时释放吗?大部分情况下是,但真有不是的时候。最近实现代码的时候不小心就碰到了这样的特殊情况。
1349 0
|
5月前
|
Java
java判断Object对象是否为空demo
java判断Object对象是否为空demo
|
13天前
|
JavaScript
js 字符串String转对象Object
该代码示例展示了如何将一个以逗号分隔的字符串(`&#39;1.2,2,3,4,5&#39;`)转换为对象数组。通过使用`split(&#39;,&#39;)`分割字符串并`map(parseFloat)`处理每个元素,将字符串转换成浮点数数组,最终得到一个对象数组,其类型为`object`。
|
1月前
|
存储 设计模式 Python
Python中的类(Class)和对象(Object)
Python中的类(Class)和对象(Object)
27 0
|
1月前
|
存储 JavaScript
JS中Map对象与object的区别
JS中Map对象与object的区别
|
5月前
判断Object对象是否为空
判断Object对象是否为空
|
2月前
|
Java 流计算
在Flink实时任务中,POJO(Plain Old Java Object)对象的模式演进可能会引起不兼容的问题
【2月更文挑战第6天】在Flink实时任务中,POJO(Plain Old Java Object)对象的模式演进可能会引起不兼容的问题
19 3
|
3月前
|
JavaScript 前端开发 测试技术
Proxy vs Object.defineProperty:哪种对象拦截机制更适合你?
Proxy vs Object.defineProperty:哪种对象拦截机制更适合你?
|
3月前
|
存储 JavaScript 前端开发
【JavaScript】<面向对象Object>函数方法&对象创建&原型对象&作用域解析
【1月更文挑战第17天】【JavaScript】<面向对象Object>函数方法&对象创建&原型对象&作用域解析
|
3月前
|
JavaScript 前端开发
如何巧妙使用`Object.keys`方法将`JS`的一个对象的特定的值赋值给另外一个对象
如何巧妙使用`Object.keys`方法将`JS`的一个对象的特定的值赋值给另外一个对象
17 0