2013-08-17 82 views
1

我试图用APPcontainer.Now注册为BHO按照博客http://blogs.msdn.com/b/ieinternals/archive/2012/03/23/understanding-ie10-enhanced-protected-mode-network-security-addons-cookies-metro-desktop.aspx错误LNK2001:解析外部符号CATID_AppContainerCompatible

,我已经定义在同一CPP文件以下内容作为DLLRegister

DEFINE_GUID(CATID_AppContainerCompatible, 0x59fb2056,0xd625,0x48d0,0xa9,0x44,0x1a,0x85,0xb5,0xab,0x26,0x40);  


STDAPI DllRegisterServer(void) 
{ 
    // let ATL handle this 
    HRESULT hr = _AtlModule.DllRegisterServer(); 

    ICatRegister* pcr = NULL ; 

     hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr); 
     if (FAILED(hr)) 
      return hr; 
     if (SUCCEEDED(hr)) 
     { 
      // Register this category as being "implemented" by 
      // the class. 
      CATID rgcatid[1] ; 
      rgcatid[0] = CATID_AppContainerCompatible; 
      hr = pcr->RegisterClassImplCategories(CLSID_ABC, 1, rgcatid); 
     } 

当我尝试编译此代码我得到以下错误:

unresolved external symbol CATID_AppContainerCompatible 

不知道为什么会出现这种情况。通过右键点击它,我可以导航到CATID_AppContainerCompatible定义。 任何暗示?

我解决了这个问题。由于DEFINE_GUID将GUID声明为extern,因此我需要将const GUID CATID_AppContainerCompatible ;放入我的文件中。将该语句编译后。

+0

的#include initguid.h,而不是包括guiddef。 H。它确保INITGUID宏被定义,并且您将拥有可链接的外部定义。 –

回答

4

DEFINE_GUID行为取决于INITGUID定义的存在。这是一个非常常见的问题,因此再次重复这些细节是没有意义的,这里是进一步阅读:How to avoid error "LNK2001 unresolved external" by using DEFINE_GUID

为了避免掉入这个陷阱,您可以使用__declspec(uuid(...))符,并自动让编译器排序的GUID出来,如:

class __declspec(uuid("{26AFA816-359E-4094-90A8-BA73DE0035FA}")) 
    AppContainerCompatible; 
// ... 
rgcatid[0] = __uuidof(AppContainerCompatible); //CATID_AppContainerCompatible; 

更多内容:Referencing GUIDs

相关问题