Using WRL for C ++ / CX Functions - Linker Error

Possible duplicate:
What is an undefined link / unresolved external symbol error and how to fix it?

I am trying to create a WinRT library that does not use the CX extension. I need to get the package name, roaming data folder, etc. I wrote some shell, but when I link this library to an executable project, I get a linker error

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) 

this is the package name wrapper

 // 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; } 

Maybe I am not getting WRL and I am using it incorrectly.

Thanks for the help :) Thomas

+4
source share
1 answer

Linker Error I may be causing

Or not find the function definition

or you forget to add the .lib file to the project property

switch to

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

Source: https://habr.com/ru/post/1441545/


All Articles