AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AProgramModule.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#include <stdexcept>
   14#include <string>
   15#include <AUI/IO/APath.h>
   16#include <AUI/Common/SharedPtr.h>
   17#include <AUI/Common/AException.h>
   18
   19#if AUI_PLATFORM_WIN
   20#include <windows.h>
   21#else
   22#include <dlfcn.h>
   23
   24typedef void* HMODULE;
   25#endif
   26class AString;
   27class API_AUI_CORE AProgramModule {
   28private:
   29    HMODULE mHandle;
   30
   31    AProgramModule(const AProgramModule&) = delete;
   32
   33public:
   34    AProgramModule(HMODULE handle) noexcept : mHandle(handle) {}
   35
   36    using ProcRawPtr = void(*)();
   37
   38    class API_AUI_CORE LoadException : public AException {
   39    public:
   40        explicit LoadException(const AString& message) : AException(message) {}
   41        virtual ~LoadException() = default;
   42    };
   43
   44
   45
   46    [[nodiscard]]
   47    ProcRawPtr getProcAddressRawPtr(const AString& name) const noexcept;
   48
   49    template <typename Function>
   50    [[nodiscard]]
   51    Function* getProcAddress(const AString& name) const noexcept {
   52        return reinterpret_cast<Function*>(getProcAddressRawPtr(name));
   53    }
   54
   59    static _<AProgramModule> load(const AString& path);
   60
   66
   67    static _<AProgramModule> self();
   68};
static _< AProgramModule > load(const AString &path)
Loads a dynamic load library (shared object).
static AString getDllExtension()
Extension of a dynamic load library of current platform.
Represents a Unicode character string.
Definition AString.h:38
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179