LINK 2019 Unresolved external symbol "CaptureUiThreadContext" when adding .then() to async cpp code

StackOverflow https://stackoverflow.com/questions/16658070

Question

Hey I have a very frustrating bug.

I have a c++ windows phone 8 app and I am trying to use the StreamSocket.

Before I explain, here is the code that causes the error:

using namespace Windows::Networking;
using namespace Windows::Networking::Sockets;
using namespace Windows::Storage::Streams;

// --- monkey api code ---
void HttpPost(String url,String data,Array<String > result) {
    //url.ToCString<wchar_t>()
    auto uri = ref new Windows::Foundation::Uri(url.ToWinRTString());

    StreamSocket^ clientSocket = ref new StreamSocket();

    HostName^ serverHost = ref new HostName(uri->Host);

    Print("connecting");
    //task<void>(clientSocket->ConnectAsync(serverHost, uri->SchemeName, SocketProtectionLevel::SslAllowNullEncryption)).then([] (task<void> previousTask) {
        Print("connected!");
    //});
}

If I compile the project the snippet comes from, as-is, it will work. If I uncomment the two lines at the bottom, I get an unresolved error:

Error 1 error LNK2019: unresolved external symbol "long __stdcall CaptureUiThreadContext(struct IContextCallback * *)" (?CaptureUiThreadContext@@YGJPAPAUIContextCallback@@@Z) referenced in function "public: void __thiscall Concurrency::details::_ContextCallback::_Resolve(bool)" (?_Resolve@_ContextCallback@details@Concurrency@@QAEX_N@Z) C:\dev\proj

I have googled for "CaptureUiThreadContext" and there is one search result which doesn't offer any help. There is no reference to it in my code or libraries I use. Does anyone have any words of wisdom to help me resolve this?

What header or lib am I missing that contains this?

This is my reference http://msdn.microsoft.com/library/windows/apps/jj150597.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-2

Était-ce utile?

La solution

It works for me by copying in your code into a fresh WP8 app from the Direct3DApp template.

The linker command line is including "WindowsPhoneCore.lib" "RuntimeObject.lib" "PhoneAppModelHost.lib" /NODEFAULTLIB:"ole32.lib".

Do you have WindowsPhoneCore.lib included?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top