Help Center

CWebView2.CWebView2CreateCoreWebView2EnvironmentCompletedHandlermethod

Implementation of the ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler callback interface.

WebViewmethoddoc-orphan
No implementation located. This member is documented, but the source scan found no matching declaration. It is likely declared in a header this scan does not resolve, or provided by a macro.

Description

Implementation of the ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler interface.

Used when the WebView2 runtime finishes creating a ICoreWebView2Environment object. The creation is initiated by calling the CreateCoreWebView2Environment or CreateCoreWebView2EnvironmentWithOptions.

This is the code of the callback class used internally by CWebView2. It is included here for documentation purposes. You will never have to call it by yourself.

Remarks

The CWebView2class implements an intenal implementation of this class. It is called in your appliacation as follows:

Examples

' ######################################################################################## ' CWebView2CreateCoreWebView2EnvironmentCompletedHandler class ' Implementation of the ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler callback interface. ' ######################################################################################## TYPE CWebView2CreateCoreWebView2EnvironmentCompletedHandler EXTENDS OBJECT

DECLARE VIRTUAL FUNCTION QueryInterface (BYVAL riid AS REFIID, BYVAL ppvObject AS LPVOID PTR) AS HRESULT DECLARE VIRTUAL FUNCTION AddRef () AS ULONG DECLARE VIRTUAL FUNCTION Release () AS ULONG DECLARE VIRTUAL FUNCTION Invoke (BYVAL errorCode AS HRESULT, BYVAL createdEnvironment AS Afx_ICoreWebView2Environment PTR) AS HRESULT

DECLARE CONSTRUCTOR DECLARE DESTRUCTOR

' Reference count for COM refCount AS ULONG = 0

END TYPE ' ########################################################################################

' ===================================================================================== ' Constructor ' ===================================================================================== PRIVATE CONSTRUCTOR CWebView2CreateCoreWebView2EnvironmentCompletedHandler CWV2_DP("") END CONSTRUCTOR ' ===================================================================================== ' ===================================================================================== ' Destructor ' ===================================================================================== PRIVATE DESTRUCTOR CWebView2CreateCoreWebView2EnvironmentCompletedHandler CWV2_DP("") END DESTRUCTOR ' =====================================================================================

' ======================================================================================== ' Returns pointers to the implemented classes and supported interfaces. ' It is never called by WebView, so we simply return S_OK. ' ======================================================================================== PRIVATE FUNCTION CWebView2CreateCoreWebView2EnvironmentCompletedHandler.QueryInterface (BYVAL riid AS REFIID, BYVAL ppvObj AS LPVOID PTR) AS HRESULT CWV2_DP("") RETURN S_OK END FUNCTION ' =====================================================================================

' ======================================================================================== ' Increments the reference count for an interface on an object. This method should be called ' for every new copy of a pointer to an interface on an object. ' ======================================================================================== PRIVATE FUNCTION CWebView2CreateCoreWebView2EnvironmentCompletedHandler.AddRef () AS ULONG refCount += 1 CWV2_DP(WSTR(refCount)) RETURN refCount END FUNCTION ' ========================================================================================

' ======================================================================================== ' Decrements the reference count for an interface on an object. ' If the count reaches 0, it deletes itself. ' ======================================================================================== PRIVATE FUNCTION CWebView2CreateCoreWebView2EnvironmentCompletedHandler.Release () AS ULONG refCount -= 1 CWV2_DP(WSTR(refCount)) IF refCount = 0 THEN

CWV2_DP("Delete class")
  Delete @this

END IF RETURN refCount END FUNCTION ' =====================================================================================

' ===================================================================================== PRIVATE FUNCTION CWebView2CreateCoreWebView2EnvironmentCompletedHandler.Invoke (BYVAL errorCode AS HRESULT, BYVAL createdEnvironment AS Afx_ICoreWebView2Environment PTR) AS HRESULT CWV2_DP("") RETURN S_OK END FUNCTION ' =====================================================================================

' // Create an instance of WebView DIM pWebView2 AS CWebView2 = CWebView2(hWin, pUserDataFolder)

' ======================================================================================== ' Constructor ' Usage 1: DIM pWebView2 AS CWebView2 = hWin ' CreateCoreWebView2Environment, so it relies on the default runtime and default user data folder. ' Usage 2: DIM pWebView2 AS CWebView2 = CWebView2(hWin, pUserDataFolder) ' Calls CreateCoreWebView2EnvironmentWithOptions, pointing to any folder you choose. ' This gives you a separate profile: cookies, cache, storage isolated from the default. ' Slightly slower startup, but perfect for multi-tab or multi-user contexts. ' ======================================================================================== PRIVATE CONSTRUCTOR CWebView2 (BYVAL hWin AS HWND, BYVAL pUserDataFolder AS WSTRING PTR = NULL) CWV2_DP("hWin: " & WSTR(hWin) & " - this: " & WSTR(@this)) ' // Initialize the COM library CoInitialize NULL ' // Store the window handle IF hWin = NULL THEN SetResult(E_POINTER): EXIT CONSTRUCTOR SetWindowLongPtrW(hWin, GWLP_USERDATA, cast(LONG_PTR, @this)) m_hwnd = hWin ' // Create the environment DIM pEnv AS CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal PTR pEnv = NEW CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal(@this) DIM hr AS HRESULT IF pUserDataFolder = NULL THEN

hr = CreateCoreWebView2Environment(cast(ANY PTR, pEnv))

ELSE

hr = CreateCoreWebView2EnvironmentWithOptions(NULL, pUserDataFolder, NULL, cast(ANY PTR, pEnv))

END IF SetResult(hr) CWV2_DP("pEnv: " & WSTR(pEnv) & " - hr: " & HEX(hr)) END CONSTRUCTOR ' ========================================================================================

' ######################################################################################## ' CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal class ' Implementation of the ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler callback interface. ' ######################################################################################## TYPE CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal EXTENDS OBJECT

DECLARE VIRTUAL FUNCTION QueryInterface (BYVAL riid AS REFIID, BYVAL ppvObject AS LPVOID PTR) AS HRESULT DECLARE VIRTUAL FUNCTION AddRef () AS ULONG DECLARE VIRTUAL FUNCTION Release () AS ULONG DECLARE VIRTUAL FUNCTION Invoke (BYVAL errorCode AS HRESULT, BYVAL createdEnvironment AS Afx_ICoreWebView2Environment PTR) AS HRESULT

DECLARE CONSTRUCTOR (BYVAL pWebView2 AS CWebView2 PTR) DECLARE DESTRUCTOR

' Reference count for COM refCount AS ULONG = 0 m_pWebView2 AS CWebView2 PTR

END TYPE ' ########################################################################################

' ######################################################################################## ' CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal class ' Implementation of the ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler callback interface. ' ########################################################################################

' ===================================================================================== ' Constructor ' ===================================================================================== CONSTRUCTOR CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal (BYVAL pWebView2 AS CWebView2 PTR) CWV2_DP("pWebView2: " & WSTR(pWebView2) & " - this: " & WSTR(@this)) m_pWebView2 = pWebView2 END CONSTRUCTOR ' ===================================================================================== ' ===================================================================================== ' Destructor ' ===================================================================================== DESTRUCTOR CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal CWV2_DP(WSTR(@this)) END DESTRUCTOR ' =====================================================================================

' ======================================================================================== ' Returns pointers to the implemented classes and supported interfaces. ' It is never called by WebView, so we simply return S_OK. ' ======================================================================================== FUNCTION CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal.QueryInterface (BYVAL riid AS REFIID, BYVAL ppvObj AS LPVOID PTR) AS HRESULT CWV2_DP("") RETURN S_OK END FUNCTION ' =====================================================================================

' ======================================================================================== ' Increments the reference count for an interface on an object. This method should be called ' for every new copy of a pointer to an interface on an object. ' ======================================================================================== FUNCTION CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal.AddRef () AS ULONG refCount += 1 CWV2_DP(WSTR(refCount)) RETURN refCount END FUNCTION ' ========================================================================================

' ======================================================================================== ' Decrements the reference count for an interface on an object. ' If the count reaches 0, it deletes itself. ' ======================================================================================== FUNCTION CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal.Release () AS ULONG refCount -= 1 CWV2_DP(WSTR(refCount)) IF refCount = 0 THEN

CWV2_DP("Delete class")
  Delete @this

END IF RETURN refCount END FUNCTION ' =====================================================================================

' ===================================================================================== FUNCTION CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal.Invoke (BYVAL errorCode AS HRESULT, BYVAL createdEnvironment AS Afx_ICoreWebView2Environment PTR) AS HRESULT CWV2_DP("") IF errorCode = S_OK AND m_pWebView2 <> NULL THEN

m_pWebView2->m_pEnv = createdEnvironment
  m_pWebView2->m_pEnv->AddRef
  ' // Create controller
  DIM pController AS CWebView2CreateCoreWebView2ControllerCompletedHandlerInternal PTR
  pController = NEW CWebView2CreateCoreWebView2ControllerCompletedHandlerInternal(m_pWebView2)
  m_pWebView2->m_pEnv->CreateCoreWebView2Controller(m_pWebView2->m_hWnd, cast(ANY PTR, pController))
  ' // Get the runtime versión
  DIM wszVersion AS LPWSTR
  IF m_pWebView2->m_pEnv->get_BrowserVersionString(@wszVersion) = S_OK THEN
     m_pWebView2->m_BrowserVersion = *wszVersion
     CoTaskMemFree(wszVersion)
  END IF

END IF RETURN S_OK END FUNCTION ' =====================================================================================

Reference