Monado OpenXR Runtime
u_win32_com_guard.hpp
Go to the documentation of this file.
1 // Copyright 2022, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief An object that serves to keep the reference count of COM initialization greater than 0.
6  *
7  * @author Rylie Pavlik <rylie.pavlik@collabora.com>
8  * @ingroup aux_util
9  *
10  */
11 #pragma once
12 
13 #include "xrt/xrt_config_os.h"
14 
15 #if defined(XRT_OS_WINDOWS)
16 
17 #include "xrt/xrt_windows.h"
18 #include "combaseapi.h"
19 
20 namespace xrt::auxiliary::util {
21 
22 /**
23  * This object makes sure that Windows doesn't close out COM while we're holding on to COM objects.
24  *
25  * We don't know if the calling thread has initialized COM or how, so this just increments the ref count without
26  * really expressing an opinion.
27  */
28 class ComGuard
29 {
30 public:
31  ComGuard();
32  ~ComGuard();
33 
34  ComGuard(ComGuard const &) = delete;
35  ComGuard(ComGuard &&) = delete;
36  ComGuard &
37  operator=(ComGuard const &) = delete;
38  ComGuard &
39  operator=(ComGuard &&) = delete;
40 
41 private:
42  CO_MTA_USAGE_COOKIE m_cookie;
43 };
44 
45 } // namespace xrt::auxiliary::util
46 
47 #endif // defined(XRT_OS_WINDOWS) && defined(XRT_HAVE_WIL)
Auto detect OS and certain features.
A minimal way to include Windows.h.