aboutsummaryrefslogtreecommitdiff
path: root/src/util/com_util.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/com_util.hpp')
-rw-r--r--src/util/com_util.hpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/util/com_util.hpp b/src/util/com_util.hpp
new file mode 100644
index 00000000..bbaf1c27
--- /dev/null
+++ b/src/util/com_util.hpp
@@ -0,0 +1,22 @@
+#pragma once
+#include "pre.hpp"
+
+#include <memory>
+
+namespace cru::util {
+
+template <typename TInterface>
+std::shared_ptr<TInterface> CreateComSharedPtr(TInterface* p) {
+ return std::shared_ptr<TInterface>(p, [](TInterface* ptr) {
+ if (ptr != nullptr) ptr->Release();
+ });
+}
+
+template <class TInterface>
+void SafeRelease(TInterface*& p) {
+ if (p != nullptr) {
+ p->Release();
+ p = nullptr;
+ }
+}
+} // namespace cru::util