简体   繁体   English

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

[英]error LNK2001: unresolved external symbol CATID_AppContainerCompatible

I am trying to register BHO with APPcontainer.Now as per the blog http://blogs.msdn.com/b/ieinternals/archive/2012/03/23/understanding-ie10-enhanced-protected-mode-network-security-addons-cookies-metro-desktop.aspx 我试图用APPcontainer注册BHO。现在根据博客http://blogs.msdn.com/b/ieinternals/archive/2012/03/23/understanding-ie10-enhanced-protected-mode-network-security-插件饼干-城域desktop.aspx

,I have defined following in same cpp file as DLLRegister ,我在与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);
        }

When I try to compile this code I am getting following error: 当我尝试编译此代码时,我收到以下错误:

unresolved external symbol CATID_AppContainerCompatible

Not sure why this is coming. 不知道为什么会这样。 I can navigate to CATID_AppContainerCompatible definition by right click on it. 我可以通过右键单击导航到CATID_AppContainerCompatible定义。 any suggesitons?? 任何建议?

I solved the issue. 我解决了这个问题。 since DEFINE_GUID declares GUID as extern I need to put const GUID CATID_AppContainerCompatible ; 因为DEFINE_GUID将GUID声明为extern我需要将const GUID CATID_AppContainerCompatible ; in my file .After putting that statement its compiling. 在我的文件中。将该语句放入其编译之后。

DEFINE_GUID behavior depends on presence of INITGUID definition. DEFINE_GUID行为取决于INITGUID定义的存在。 This is a very frequent problem, so it makes no sense to repeat the details once again, here is further reading: How to avoid error "LNK2001 unresolved external" by using DEFINE_GUID . 这是一个非常常见的问题,因此再次重复细节是没有意义的,这里有进一步阅读: 如何使用DEFINE_GUID避免错误“LNK2001 unresolved external”

To avoid falling into this trap you can use __declspec(uuid(...)) specifier and let compiler sort GUIDs out automatically, eg: 为避免陷入此陷阱,您可以使用__declspec(uuid(...))说明符,让编译器自动对GUID进行排序,例如:

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

More on this: Referencing GUIDs 更多相关内容: 引用GUID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM