我已按照 WebView2 入门(开发人员预览版) 中的所有说明创建使用 Microsoft Edge (Chromium) 的应用程序。但是,它无法找到 Edge 浏览器。我还尝试了示例应用程序( this 和 this ),但结果相同。我已经为 32 位和 64 位构建了应用程序。
我调用 CreateWebView2EnvironmentWithDetails()
得到的是错误 0x80070002
,即 ERROR_FILE_NOT_FOUND
( 系统找不到指定的文件。 )
HRESULT hr = CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr,
Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>(
[hWnd](HRESULT result, IWebView2Environment* env) -> HRESULT {
// Create a WebView, whose parent is the main window hWnd
env->CreateWebView(hWnd, Callback<IWebView2CreateWebViewCompletedHandler>(
[hWnd](HRESULT result, IWebView2WebView* webview) -> HRESULT {
if (webview != nullptr) {
webviewWindow = webview;
}
// Resize WebView to fit the bounds of the parent window
RECT bounds;
GetClientRect(hWnd, &bounds);
webviewWindow->put_Bounds(bounds);
// Schedule an async task to navigate to Bing
webviewWindow->Navigate(L"https://www.bing.com/");
return S_OK;
}).Get());
return S_OK;
}).Get());
if (!SUCCEEDED(hr))
{
if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
{
MessageBox(
nullptr,
L"Couldn't find Edge installation. "
"Do you have a version installed that's compatible with this "
"WebView2 SDK version?",
nullptr, MB_OK);
}
else
{
std::wstringstream formattedMessage;
formattedMessage << L"Failed to create webview environment"
<< ": 0x" << std::hex << std::setw(8) << hr;
MessageBox(nullptr, formattedMessage.str().c_str(), nullptr, MB_OK);
}
}
我有:
- Edge 版本 79.0.309.60(官方版本)测试版(64 位)
- 视窗 10.0.17134
- 视觉工作室 2019 16.4.2
任何想法为什么找不到我的 Edge 安装?
原文由 Marius Bancila 发布,翻译遵循 CC BY-SA 4.0 许可协议
我遇到了同样的错误,安装 WebView2 Runtime 后,它可以工作了。 https://developer.microsoft.com/microsoft-edge/webview2