WebViewRuntimeAvailable Function  
 
BOOL WINAPI WebViewRuntimeAvailable();

The WebViewRuntimeAvailable function determines whether the required runtime is installed and available.

Parameters

None.

Return Value

If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To get extended error information, call WebViewGetLastError.

Remarks

The WebViewRuntimeAvailable function checks whether the Microsoft Edge WebView2 runtime is installed and meets the minimum required version for this library. If the runtime is available, the function returns TRUE; otherwise, it returns FALSE and sets the last error code to indicate whether the runtime is missing or is an unsupported version. If the runtime is not installed, the last error code will be set to ST_ERROR_WEBVIEW2_NOT_INSTALLED. If the installed runtime is older than the minimum supported version (currently 102.0.1245.22), the last error code will be set to ST_ERROR_INVALID_WEBVIEW2_VERSION.

This function is one of the few API functions that can be called before WebViewInitialize. It allows an application to check for the availability of the WebView2 runtime at startup, and optionally provide a more helpful error message to the user before attempting to create or attach a browser control. Developers may wish to call this function during application startup or installation checks. For example, if the runtime is not present or is too old, the application can inform the user that they must install or update the Microsoft Edge WebView2 runtime in order to use features which require embedded web content.

If the function succeeds, it only guarantees that the required runtime is installed and is a sufficient version. It does not initialize or configure the runtime; that process occurs when WebViewInitialize is called.

Example

INT APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow)
{
    if (!WebViewRuntimeAvailable())
    {
        DWORD dwError = WebViewGetLastError();

        if (dwError == ST_ERROR_WEBVIEW2_NOT_INSTALLED)
        {
            MessageBoxW(NULL,
                        L"The Microsoft Edge WebView2 runtime is not installed.\n"
                        L"Please install it to continue.",
                        L"MyApp", MB_ICONERROR | MB_OK);
        }
        else
        {
            MessageBoxW(NULL,
                        L"The installed Microsoft Edge WebView2 runtime is too old.\n"
                        L"Please update to the latest version.",
                        L"MyApp", MB_ICONERROR | MB_OK);
        }

        return 0; // Exit application
    }

    // Safe to initialize the library and create a WebView2 control
    if (!WebViewInitialize(CSTOOLS12_LICENSE_KEY, NULL))
    {
        MessageBoxW(NULL,
                    L"Unable to initialize the SocketTools WebView library",
                    L"MyApp", MB_ICONERROR | MB_OK);
        return 0;
    }

    // Create your main window, attach the browser, etc.

    return 0;
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtmv12.lib

See Also