gpt4 book ai didi

c++ - 错误 LNK2001 : unresolved external symbol CATID_AppContainerCompatible

转载 作者:行者123 更新时间:2023-11-30 01:57:44 28 4
gpt4 key购买 nike

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

最佳答案

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

关于c++ - 错误 LNK2001 : unresolved external symbol CATID_AppContainerCompatible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18288708/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com