基于Chromium Edge的WebView2不起作用

问题描述 投票:0回答:1

我已按照Getting Started with WebView2 (developer preview)中的所有说明创建了一个使用Microsoft Edge(Chromium)的应用程序。但是,它无法找到Edge浏览器。我还尝试了示例应用程序(thisthis),但结果相同。我已经为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位)
  • Windows 10.0.17134
  • Visual Studio 2019 16.4.2

为什么找不到我的Edge安装的任何想法?

c++ windows browser webview microsoft-edge
1个回答
0
投票

可能浏览器的版本与SDK的最新版本不兼容,您可能必须返回以下版本才能使用它,请按照以下列表操作:

https://docs.microsoft.com/en-us/microsoft-edge/hosting/webview2/releasenotes

© www.soinside.com 2019 - 2024. All rights reserved.