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
  • 4,122
  • 4
  • 47
  • 81
Maximilian
  • 754
  • 1
  • 5
  • 26

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,845
  • 6
  • 39
  • 83