Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
DLLSupport.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
6#include "Stroika/Foundation/Execution/Throw.h"
7
9
10 /*
11 ********************************************************************************
12 *********************************** DLLLoader **********************************
13 ********************************************************************************
14 */
15 inline DLLLoader::operator DLLHandle () const
16 {
17 EnsureNotNull (fModule_);
18 return fModule_;
19 }
20 inline ProcAddress DLLLoader::GetProcAddress (const char* procName) const
21 {
22 AssertNotNull (fModule_);
23 RequireNotNull (procName);
24#if qStroika_Foundation_Common_Platform_Windows
25 auto result{::GetProcAddress (fModule_, procName)};
26 if (result == nullptr) {
27 Execution::ThrowSystemErrNo ();
28 }
29 return result;
30#else
31 ProcAddress addr = dlsym (fModule_, procName);
32 if (addr == nullptr) {
33 dlerror (); // clear any old error
34 addr = dlsym (fModule_, procName);
35 // interface seems to be defined only for char*, not wide strings: may need to map procName as well
36 const char* err = dlerror ();
37 if (err != nullptr) [[unlikely]] {
38 Execution::Throw (DLLException (err));
39 }
40 }
41 return addr;
42#endif
43 }
44 inline ProcAddress DLLLoader::GetProcAddress (const wchar_t* procName) const
45 {
46 AssertNotNull (fModule_);
47 RequireNotNull (procName);
48 return GetProcAddress (Characters::String{procName}.AsNarrowSDKString (Characters::eIgnoreErrors).c_str ());
49 }
50#if !qStroika_Foundation_Common_Platform_Windows
51 inline DLLException::DLLException (const char* message)
52 : Execution::RuntimeErrorException<>{Characters::String::FromNarrowSDKString (message)}
53 {
54 }
55#endif
56
57}
#define AssertNotNull(p)
Definition Assertions.h:333
#define EnsureNotNull(p)
Definition Assertions.h:340
#define RequireNotNull(p)
Definition Assertions.h:347
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
nonvirtual string AsNarrowSDKString() const
Definition String.inl:830
static String FromNarrowSDKString(const char *from)
Definition String.inl:470
nonvirtual ProcAddress GetProcAddress(const char *procName) const
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...
Definition Throw.inl:43