【问题标题】:error LNK2001: unresolved external symbol CATID_AppContainerCompatible错误 LNK2001:未解析的外部符号 CATID_AppContainerCompatible
【发布时间】:2013-08-19 18:26:59
【问题描述】:

我正在尝试向 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 ; 放入我的文件中。在放入该语句后进行编译。

【问题讨论】:

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

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-03
    • 2014-09-27
    • 2018-08-14
    • 2018-08-24
    • 2020-08-21
    • 2016-09-04
    相关资源
    最近更新 更多