Loading...
Searching...
No Matches
juce::DynamicLibrary Class Reference

Detailed Description

Handles the opening and closing of DLLs.

This class can be used to open a DLL and get some function pointers from it. Since the DLL is freed when this object is deleted, it's handy for managing library lifetimes using RAII.


The documentation for this class was generated from the following file:

Public Member Functions

 DynamicLibrary ()=default
 Creates an unopened DynamicLibrary object.
 DynamicLibrary (const String &name)
 Creates an opened DynamicLibrary object.
 DynamicLibrary (DynamicLibrary &&other) noexcept
 Move constructor.
 ~DynamicLibrary ()
 Destructor.
bool open (const String &name)
 Opens a DLL.
void close ()
 Releases the currently-open DLL, or has no effect if none was open.
void * getFunction (const String &functionName) noexcept
 Tries to find a named function in the currently-open DLL and returns a pointer to it.
template<typename Fn>
Fn * getFunction (const String &functionName) noexcept
 Tries to find a named function in the currently-open DLL and returns a pointer to it, cast to the requested function type.
bool isOpen () const noexcept
 Returns true if the library was successfully found and opened.
void * getNativeHandle () const noexcept
 Returns the platform-specific native library handle.

Constructors and Destructors

◆ DynamicLibrary() [1/3]

juce::DynamicLibrary::DynamicLibrary ( )
default

Creates an unopened DynamicLibrary object.

Call open() to actually open one.

Referenced by DynamicLibrary().

◆ DynamicLibrary() [2/3]

juce::DynamicLibrary::DynamicLibrary ( const String & name)
inline

Creates an opened DynamicLibrary object.

References name, and open().

◆ DynamicLibrary() [3/3]

juce::DynamicLibrary::DynamicLibrary ( DynamicLibrary && other)
inlinenoexcept

Move constructor.

References DynamicLibrary().

◆ ~DynamicLibrary()

juce::DynamicLibrary::~DynamicLibrary ( )
inline

Destructor.

If a library is currently open, it will be closed when this object is destroyed.

References close().

Member Functions

◆ open()

bool juce::DynamicLibrary::open ( const String & name)

Opens a DLL.

The name and the method by which it gets found is platform-specific, and may or may not include a path, depending on the OS.

If a library is already open when this method is called, it will first close the library before attempting to load the new one.

Returns
true if the library was successfully found and opened.

References name.

Referenced by DynamicLibrary().

◆ close()

void juce::DynamicLibrary::close ( )

Releases the currently-open DLL, or has no effect if none was open.

Referenced by ~DynamicLibrary().

◆ getFunction() [1/2]

void * juce::DynamicLibrary::getFunction ( const String & functionName)
noexcept

Tries to find a named function in the currently-open DLL and returns a pointer to it.

If the library is not currently open, or if the named function cannot be found, this method will return a null pointer.

Referenced by getFunction().

◆ getFunction() [2/2]

template<typename Fn>
Fn * juce::DynamicLibrary::getFunction ( const String & functionName)
inlinenoexcept

Tries to find a named function in the currently-open DLL and returns a pointer to it, cast to the requested function type.

If the library is not currently open, or if the named function cannot be found, this method will return a null pointer.

The template parameter must be a function type, e.g.

auto fn = library.getFunction<void*(const char*)> ("someFunction");

It is the caller's responsibility to ensure that the requested function signature matches the actual function exported by the dynamic library. Passing an incorrect signature will result in undefined behaviour.

References getFunction().

◆ isOpen()

bool juce::DynamicLibrary::isOpen ( ) const
inlinenoexcept

Returns true if the library was successfully found and opened.

◆ getNativeHandle()

void * juce::DynamicLibrary::getNativeHandle ( ) const
inlinenoexcept

Returns the platform-specific native library handle.

You'll need to cast this to whatever is appropriate for the OS that's in use.

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram