CWebView::RuntimeAvailable Method  
 
static BOOL RuntimeAvailable();

The RuntimeAvailable method determines whether the required runtime is installed and available.

Parameters

None.

Return Value

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

Remarks

The RuntimeAvailable method checks whether the Microsoft Edge WebView2 runtime is installed and meets the minimum required version for this library. If the runtime is available, the method 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 is a static method which can be called before creating an instance of the CWebView class. 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 method 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 method 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 inside the CWebView class constructor.

Example

CWebView *pWebView = NULL;

INT APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow)
{
    if (!CWebView::RuntimeAvailable())
    {
        MessageBox(NULL,
                   _T("The Microsoft Edge WebView2 runtime is not available."),
                   _T("MyApp"), MB_ICONERROR | MB_OK);

        return 0; // Exit application
    }

    // Create a new instance of the CWebView class
    pWebView = new CWebView();

    if (!pWebView->IsInitialized())
    {
        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