| 145 | } |
| 146 | |
| 147 | void* DynamicLibrary::getSymbol(const std::string& symbol_name) |
| 148 | { |
| 149 | if (!handle_) |
| 150 | { |
| 151 | last_error_ = "Library not loaded"; |
| 152 | return nullptr; |
| 153 | } |
| 154 | |
| 155 | #ifdef _WIN32 |
| 156 | SetLastError(0); |
| 157 | void* symbol = reinterpret_cast<void*>(GetProcAddress(static_cast<HMODULE>(handle_), symbol_name.c_str())); |
| 158 | |
| 159 | if (!symbol) |
| 160 | { |
| 161 | last_error_ = getWindowsError(); |
| 162 | if (last_error_.empty()) |
| 163 | { |
| 164 | last_error_ = "Symbol not found: " + symbol_name; |
| 165 | } |
| 166 | return nullptr; |
| 167 | } |
| 168 | #else |
| 169 | dlerror(); |
| 170 | void* symbol = dlsym(handle_, symbol_name.c_str()); |
| 171 | |
| 172 | const char* error = dlerror(); |
| 173 | if (error) |
| 174 | { |
| 175 | last_error_ = error; |
| 176 | return nullptr; |
| 177 | } |
| 178 | #endif |
| 179 | |
| 180 | last_error_.clear(); |
| 181 | return symbol; |
| 182 | } |
| 183 | |
| 184 | bool DynamicLibrary::isLoaded() const |
| 185 | { |
nothing calls this directly
no test coverage detected