0

I have a Windows Universal C++ App with a WebView, which is calling a Javascript function that returns a string. Now I want to convert a Windows::Foundation::IAsyncOperation<String^>^ to an std::string

Here is the code that calls the Javascript function

Windows::Foundation::IAsyncOperation<String^>^ result = this->webView1->InvokeScriptAsync("JSfunction", arguments);

I'd like to have result as a std::string

sergiol
  • 3,926
  • 4
  • 40
  • 77
Maximilian
  • 611
  • 1
  • 5
  • 22

1 Answers1

1

result is not of type String^, it is IAsyncOperation<String^>, an asynchronous operation that will return a String^ to its caller.

To get the result of type String^, call the GetResults method on the IAsyncOperation.

String^ result = this->webView1->InvokeScriptAsync("JSfunction", arguments)->GetResults();

Then you can convert String^ to std::string following Q: C++/CLI Converting from System::String^ to std::string.

kennyzx
  • 12,605
  • 6
  • 36
  • 79