AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AComBase.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include <atomic>
15#include <shlwapi.h>
16#include <strsafe.h>
17#include <shlobj.h>
18#include <type_traits>
19
24template<typename Child, typename Base>
25class AComBase: public Base {
26public:
27 virtual ~AComBase() = default;
28
29 ULONG __stdcall AddRef() override {
30 ++mRefCounter;
31 return 0;
32 }
33
34 ULONG __stdcall Release() override {
35 if (--mRefCounter == 0) {
36 delete this;
37 }
38 return 0;
39 }
40
41 HRESULT __stdcall QueryInterface(const IID& riid, void** ppv) override {
42 static const QITAB qit[] = {
43 QITABENT(Child, Base),
44 { 0 },
45 };
46 return QISearch(this, qit, riid, ppv);
47 }
48
49private:
50 std::atomic_uint mRefCounter = 1;
51};
52
53
Helper class implementing COM AddRef Release, and QueryInterface.
Definition AComBase.h:25