From 1aad599d2f3d133cf3b5b302469635eb1a2ea317 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Tue, 18 Jan 2022 11:40:04 -0500 Subject: [PATCH] remove GetBridgeWindow static variable --- Unpackaged.nuspec | 2 +- inc/cppxaml/XamlWindow.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Unpackaged.nuspec b/Unpackaged.nuspec index 736a02e..72720a5 100644 --- a/Unpackaged.nuspec +++ b/Unpackaged.nuspec @@ -2,7 +2,7 @@ Unpackaged - 0.0.16 + 0.0.17 Alexander Sklar Alexander Sklar false diff --git a/inc/cppxaml/XamlWindow.h b/inc/cppxaml/XamlWindow.h index 662d00e..53ef59b 100644 --- a/inc/cppxaml/XamlWindow.h +++ b/inc/cppxaml/XamlWindow.h @@ -279,13 +279,13 @@ namespace cppxaml { return (int)msg.wParam; } + mutable HWND m_hWndXamlIsland{ nullptr }; HWND GetBridgeWindow() const { - static HWND hWndXamlIsland = nullptr; - if (!hWndXamlIsland) { + if (!m_hWndXamlIsland) { auto interop = m_desktopXamlSource.as(); - winrt::check_hresult(interop->get_WindowHandle(&hWndXamlIsland)); + winrt::check_hresult(interop->get_WindowHandle(&m_hWndXamlIsland)); } - return hWndXamlIsland; + return m_hWndXamlIsland; } LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -298,7 +298,7 @@ namespace cppxaml { auto createStruct = reinterpret_cast(lParam); // Parent the DesktopWindowXamlSource object to the current window. - winrt::check_hresult(interop->AttachToWindow(m_hWnd)); // This fails due to access violation! + winrt::check_hresult(interop->AttachToWindow(m_hWnd)); this->m_ui = this->m_getUI(*this); if (m_controller && m_controller->OnUICreated) {