LLDB mainline
LazyImport.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_HOST_WINDOWS_LAZYIMPORT_H
10#define LLDB_HOST_WINDOWS_LAZYIMPORT_H
11
13
14namespace lldb_private {
15
16template <typename FnPtr> class LazyImport {
17public:
18 LazyImport(const wchar_t *dll, const char *symbol)
19 : m_resolved(Resolve(dll, symbol)) {}
20
21 /// Returns the resolved function pointer, or nullptr if the DLL or symbol
22 /// is unavailable on this system.
23 FnPtr get() const { return m_resolved; }
24
25 explicit operator bool() const { return m_resolved != nullptr; }
26 FnPtr operator*() const { return m_resolved; }
27
28private:
29 static FnPtr Resolve(const wchar_t *dll, const char *symbol) {
30 HMODULE module = ::LoadLibraryW(dll);
31 if (!module)
32 return nullptr;
33 return reinterpret_cast<FnPtr>(
34 reinterpret_cast<void *>(::GetProcAddress(module, symbol)));
35 }
36
38};
39
40} // namespace lldb_private
41
42#endif // LLDB_HOST_WINDOWS_LAZYIMPORT_H
static FnPtr Resolve(const wchar_t *dll, const char *symbol)
Definition LazyImport.h:29
FnPtr operator*() const
Definition LazyImport.h:26
FnPtr get() const
Returns the resolved function pointer, or nullptr if the DLL or symbol is unavailable on this system.
Definition LazyImport.h:23
LazyImport(const wchar_t *dll, const char *symbol)
Definition LazyImport.h:18
A class that represents a running process on the host machine.