I have an COM STA, that hosts an ICoreWebView2.
I try to get the complete HTML block and I found a documentation to achieve this with a script. Here my code:
hr = m_spWebView->ExecuteScript(L"document.body.outerHTML",
Callback<ICoreWebView2ExecuteScriptCompletedHandler>(
[&val](HRESULT hr, LPCWSTR result) -> HRESULT
{
if (SUCCEEDED(hr))
val = result;
return S_OK;
}
).Get()
);
This code works, but it is executed asynchronous. So it takes some time to get the result. In fact I can see that the result arrives when the message pump is executed the next time (as I expect for an STA).
In C# I would use an await to wait for the completion. But using C++ there is nothing like this. Using an event wouldn't work, because I have an STA I would block the thread and the answer will never arrive.
Is there any way to call a function that waits for the completion in C++? Or another help would be to use ExecuteScript synchron.