2025-11-27 14:15:20 +08:00
|
|
|
#include <basalt_char.hpp>
|
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
|
|
#if defined(BASALT_OS_WINDOWS)
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace Basalt::Presenter {
|
|
|
|
|
|
|
|
|
|
enum class DllKind {
|
|
|
|
|
RenderEngine,
|
|
|
|
|
DataDeliver,
|
|
|
|
|
ObjectLoader,
|
|
|
|
|
AnimationLoader,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DllLoader {
|
|
|
|
|
public:
|
|
|
|
|
#if defined(BASALT_OS_WINDOWS)
|
|
|
|
|
using Handle = HMODULE;
|
|
|
|
|
#else
|
2025-11-27 20:48:35 +08:00
|
|
|
using Handle = void*;
|
2025-11-27 14:15:20 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
DllLoader(DllKind kind, const std::basic_string_view<BSCHAR> filename);
|
|
|
|
|
~DllLoader();
|
|
|
|
|
|
2025-11-27 20:48:35 +08:00
|
|
|
public:
|
|
|
|
|
template<typename T>
|
|
|
|
|
T* CreateInstance() {
|
|
|
|
|
if (!m_Handle) return nullptr;
|
|
|
|
|
|
|
|
|
|
using Fct = T* (*) ();
|
|
|
|
|
constexpr char EXPOSE_FUNC_NAME[] = "BSCreateInstance";
|
|
|
|
|
#if defined(BASALT_OS_WINDOWS)
|
|
|
|
|
auto fct = (Fct) GetProcAddress(m_Handle, EXPOSE_FUNC_NAME);
|
|
|
|
|
#else
|
|
|
|
|
auto fct = (Fct) dlsym(m_Handle, EXPOSE_FUNC_NAME);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return fct();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-27 14:15:20 +08:00
|
|
|
private:
|
|
|
|
|
Handle m_Handle;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Basalt::Presenter
|