Skip to content

Commit 981aacf

Browse files
authored
Merge pull request #78 from MicrosoftEdge/user/luflore/query-fix
Use try_query for CoreWebView2_3 interface
2 parents 10db37a + ba5082b commit 981aacf

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

SampleApps/WebView2APISample/AppWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
716716
m_creationModeId == IDM_CREATION_MODE_TARGET_DCOMP);
717717
NewComponent<ControlComponent>(this, &m_toolbar);
718718

719-
m_webView3 = coreWebView2.query<ICoreWebView2_3>();
719+
m_webView3 = coreWebView2.try_query<ICoreWebView2_3>();
720720
if (m_webView3)
721721
{
722722
//! [AddVirtualHostNameToFolderMapping]

SampleApps/WebView2APISample/SettingsComponent.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ SettingsComponent::SettingsComponent(
4242
old->m_settings.try_query<ICoreWebView2ExperimentalSettings>();
4343
wil::com_ptr<ICoreWebView2ExperimentalSettings> experimental_settings_new;
4444
experimental_settings_new = m_settings.try_query<ICoreWebView2ExperimentalSettings>();
45-
LPWSTR user_agent;
46-
CHECK_FAILURE(experimental_settings_old->get_UserAgent(&user_agent));
47-
CHECK_FAILURE(experimental_settings_new->put_UserAgent(user_agent));
45+
if (experimental_settings_old && experimental_settings_new)
46+
{
47+
LPWSTR user_agent;
48+
CHECK_FAILURE(experimental_settings_old->get_UserAgent(&user_agent));
49+
CHECK_FAILURE(experimental_settings_new->put_UserAgent(user_agent));
50+
}
4851
SetBlockImages(old->m_blockImages);
4952
SetReplaceImages(old->m_replaceImages);
5053
m_deferScriptDialogs = old->m_deferScriptDialogs;

0 commit comments

Comments
 (0)