天天看點

4、錯誤"no GUID has been associated with this object"的解決方法

[問題描述]<?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>

下面是收集的一些問題解決過程:

1、Have 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

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

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

IContextMenu;

_COM_SMARTPTR_TYPEDEF(IContextMenu, __uuidof(IContextMenu));

3、怎樣找到Interface的GUID?

我在系統資料庫 HKCR\Interface\ 下可以找到形式為

{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee}的鍵,如果其下有預設項="Interface",則說明這個鍵就是該Interface的GUID。

有沒有其它方法?

(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"))

過了這個村,還會有下個店,還不如直接更新一下SDK來得直接保險。

參考:

[1] 比較雜,沒有記錄出處。可以GOOGLE到。

繼續閱讀