Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
DLLSupport.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroia_Foundation_Execution_DLLSupport_h_
5#define _Stroia_Foundation_Execution_DLLSupport_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <filesystem>
10
11#if qStroika_Foundation_Common_Platform_Windows
12#include <Windows.h>
13#else
14#include <dlfcn.h>
15#endif
16
17#include "Stroika/Foundation/Characters/SDKString.h"
18#include "Stroika/Foundation/Execution/Exceptions.h"
19
20/*
21 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
22 */
23
25
28
29#if qStroika_Foundation_Common_Platform_Windows
30 using DLLHandle = HMODULE;
31 using ProcAddress = FARPROC;
32#else
33 using DLLHandle = void*;
34 using ProcAddress = void*;
35#endif
36
37#if !qStroika_Foundation_Common_Platform_Windows
38 class DLLException : public Execution::RuntimeErrorException<> {
39 public:
40 DLLException (const char* message);
41 };
42#endif
43
44 /**
45 * @todo - probably should have DLL-name embedded in exception message on failure and as a field of DLLException
46 * or maybe use 'declareactivity' while loading DLL?
47 */
48 class DLLLoader {
49 public:
50 /**
51 * Throws on failure.
52 * For POSIX, default flags=RTLD_NOW
53 */
54 DLLLoader (const SDKChar* dllName);
55 DLLLoader (const SDKChar* dllName, const vector<filesystem::path>& searchPath);
56#if qStroika_Foundation_Common_Platform_POSIX
57 DLLLoader (const SDKChar* dllName, int flags);
58 DLLLoader (const SDKChar* dllName, const vector<filesystem::path>& searchPath, int flags);
59#endif
60 DLLLoader (const DLLLoader&) = delete;
61 ~DLLLoader ();
62 DLLLoader& operator= (const DLLLoader&) = delete;
63
64 public:
65 nonvirtual operator DLLHandle () const;
66
67 public:
68 /**
69 * Throws on failure.
70 */
71 nonvirtual ProcAddress GetProcAddress (const char* procName) const;
72 nonvirtual ProcAddress GetProcAddress (const wchar_t* procName) const;
73
74 private:
75 DLLHandle fModule_;
76 };
77
78}
79
80/*
81 ********************************************************************************
82 ***************************** Implementation Details ***************************
83 ********************************************************************************
84 */
85#include "DLLSupport.inl"
86
87#endif /*_Stroia_Foundation_Execution_DLLSupport_h_*/
nonvirtual ProcAddress GetProcAddress(const char *procName) const
conditional_t< qTargetPlatformSDKUseswchar_t, wchar_t, char > SDKChar
Definition SDKChar.h:71
basic_string< SDKChar > SDKString
Definition SDKString.h:38