错误LNK2001:未解析的外部符号CATID_AppContainerCompatible

时间:2013-08-17 12:15:41

标签: c++ internet-explorer windows-8 com

我正在尝试使用APPcontainer注册BHO。现在根据博客http://blogs.msdn.com/b/ieinternals/archive/2012/03/23/understanding-ie10-enhanced-protected-mode-network-security-addons-cookies-metro-desktop.aspx

,我在与DLLRegister

相同的cpp文件中定义了以下内容
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 ;放入我的文件中。将该语句放入其编译之后。

1 个答案:

答案 0 :(得分: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