首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++/CX函数使用WRL实现链接器错误

C++/CX函数使用WRL实现链接器错误
EN

Stack Overflow用户
提问于 2012-10-23 12:37:40
回答 1查看 3.7K关注 0票数 7

可能重复: What is an undefined reference/unresolved external symbol error and how do I fix it?

我正在尝试创建不使用CX扩展的WinRT库。我需要知道软件包的名称,漫游数据文件夹,等等。我编写了一些包装器,但是当我将这个库链接到可执行项目时,我会得到链接器错误

代码语言:javascript
复制
error LNK2019: unresolved external symbol _WindowsCreateStringReference@16 referenced in function "private: void __thiscall Microsoft::WRL::Wrappers::HStringReference::CreateReference(wchar_t const *,unsigned int,unsigned int)" (?CreateReference@HStringReference@Wrappers@WRL@Microsoft@@AAEXPB_WII@Z)
error LNK2019: unresolved external symbol _WindowsDeleteString@4 referenced in function "public: __thiscall Microsoft::WRL::Wrappers::HStringReference::~HStringReference(void)" (??1HStringReference@Wrappers@WRL@Microsoft@@QAE@XZ)
error LNK2019: unresolved external symbol _WindowsGetStringRawBuffer@8 referenced in function "long __cdecl aponialib::winrt::GetFullName(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > &)" (?GetFullName@winrt@aponialib@@YAJAAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z)
error LNK2019: unresolved external symbol __imp__RoGetActivationFactory@12 referenced in function "long __cdecl Windows::Foundation::GetActivationFactory<struct ABI::Windows::Storage::IApplicationDataStatics>(struct HSTRING__ *,struct ABI::Windows::Storage::IApplicationDataStatics * *)" (??$GetActivationFactory@UIApplicationDataStatics@Storage@Windows@ABI@@@Foundation@Windows@@YAJPAUHSTRING__@@PAPAUIApplicationDataStatics@Storage@1ABI@@@Z)

这是包名包装器

代码语言:javascript
复制
// including in .h
#include <windows.h>
#include <string>
#include <Strsafe.h>
#include <Winstring.h>

#include <windows.storage.h>
#include <Windows.ApplicationModel.h>
#include <windows.Foundation.h>
#include <wrl/client.h>
#include <wrl/wrappers/corewrappers.h>

//...

HRESULT GetFullName(std::wstring &fullName)
{
    HRESULT hr;
    Microsoft::WRL::ComPtr<ABI::Windows::ApplicationModel::IPackageStatics> packageStatics;

    hr = Windows::Foundation::GetActivationFactory(Microsoft::WRL::Wrappers::HStringReference(RuntimeClass_Windows_ApplicationModel_Package).Get(), &packageStatics);
    if (FAILED(hr))
        return hr;

    Microsoft::WRL::ComPtr<ABI::Windows::ApplicationModel::IPackage> package;
    hr = packageStatics->get_Current(&package);
    if (FAILED(hr))
        return hr;

    Microsoft::WRL::ComPtr<ABI::Windows::ApplicationModel::IPackageId> packageId;
    hr = package->get_Id(&packageId);
    if (FAILED(hr))
        return hr;

    HSTRING name;
    hr = packageId->get_FullName(&name);
    if (FAILED(hr))
        return hr;

    UINT32 length;
    PCWSTR value = WindowsGetStringRawBuffer(name, &length);
    fullName = value;
    WindowsDeleteString(name);
    return S_OK;
}

也许我不懂WRL而且我用错了。

谢谢你的帮助:)托马斯

EN

回答 1

Stack Overflow用户

发布于 2012-10-23 13:34:23

链接器错误发生的原因可能是

要么找不到函数定义

或者忘记在项目属性中添加.lib文件。

代码语言:javascript
复制
Project properties-->Linker-->Input-->Additional Dependencies
票数 -4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13030578

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档