AUI Framework  master
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-2025 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
   26template<typename Child, typename Base>
   27class AComBase: public Base {
   28public:
   29    virtual ~AComBase() = default;
   30
   31    ULONG __stdcall AddRef() override {
   32        ++mRefCounter;
   33        return 0;
   34    }
   35
   36    ULONG __stdcall Release() override {
   37        if (--mRefCounter == 0) {
   38            delete this;
   39        }
   40        return 0;
   41    }
   42
   43    HRESULT __stdcall QueryInterface(const IID& riid, void** ppv) override {
   44        static const QITAB qit[] = {
   45                QITABENT(Child, Base),
   46                { 0 },
   47        };
   48        return QISearch(this, qit, riid, ppv);
   49    }
   50
   51private:
   52    std::atomic_uint mRefCounter = 1;
   53};
   54
   55
Helper class implementing COM AddRef Release, and QueryInterface.
Definition AComBase.h:27