Mar*_*ila 7 c++ browser windows webview microsoft-edge
我已按照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);
}
}
Run Code Online (Sandbox Code Playgroud)
我有:
为什么找不到我的 Edge 安装的任何想法?
可能浏览器的版本与最新版本的 SDK 不兼容,您可能需要返回某些版本才能使其工作,如下列表所示:
https://docs.microsoft.com/en-us/microsoft-edge/hosting/webview2/releasenotes
编辑:正如 WebView2 的一位开发人员所告知的,目前 WebView2 仍处于预览版,因此最新版本的 Webview2 始终会伴随最新的 Canary 版本的 Edge。
https://github.com/MicrosoftEdge/WebViewFeedback/issues/103#issuecomment-575287157
小智 5
您必须安装 WebView2 运行时才能运行兼容的应用程序。
另外,您需要升级NuGet包,也许在您的代码中您仍然有“预发布版本”的引用。在该版本中,缺少“WebView2Environment”,它是一种“WebView2Experiment”。
归档时间: |
|
查看次数: |
13481 次 |
最近记录: |