c++ - 将 WRL 用于 C++/CX 函数 - 链接器错误

标签 c++ visual-c++ windows-runtime wrl

<分区>

Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?

我正在尝试制作不使用 CX 扩展的 WinRT 库。我需要获取包名、漫游数据文件夹等。我写了一些包装器,但是当我将这个库链接到可执行项目时,出现链接器错误

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)

这是包名包装器

// 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,我用错了。

谢谢你的帮助:) 托马斯

最佳答案

发生链接器错误我可能是

要么找不到函数定义

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

Project properties-->Linker-->Input-->Additional Dependencies

关于c++ - 将 WRL 用于 C++/CX 函数 - 链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13030578/

相关文章:

c++ - 插入到 2-3-4 树中

com - DCOM 简单教程

c++ - WinRT API 无法获取 IDeviceIoControl

c# - protobuf-csharp-port 是否支持 Windows RT?

wpf - 由不同View组成的View的DataTemplate

c++ - Qt 容器如何作为参数传递给共享库的函数?

c++ - 有没有办法将一个对象注入(inject)另一个对象的结构?

c++ - 为什么程序循环而不是要求输入?

c++ - 如何在 map 中更正存储 LPTSTR

visual-studio-2010 - 使用 Visual Studio 的调试器查看动态分配的空终止字符串