The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. /**
  20. Handles the opening and closing of DLLs.
  21. This class can be used to open a DLL and get some function pointers from it.
  22. Since the DLL is freed when this object is deleted, it's handy for managing
  23. library lifetimes using RAII.
  24. @tags{Core}
  25. */
  26. class JUCE_API DynamicLibrary
  27. {
  28. public:
  29. /** Creates an unopened DynamicLibrary object.
  30. Call open() to actually open one.
  31. */
  32. DynamicLibrary() = default;
  33. /**
  34. */
  35. DynamicLibrary (const String& name) { open (name); }
  36. /** Move constructor */
  37. DynamicLibrary (DynamicLibrary&& other) noexcept
  38. {
  39. std::swap (handle, other.handle);
  40. }
  41. /** Destructor.
  42. If a library is currently open, it will be closed when this object is destroyed.
  43. */
  44. ~DynamicLibrary() { close(); }
  45. /** Opens a DLL.
  46. The name and the method by which it gets found is of course platform-specific, and
  47. may or may not include a path, depending on the OS.
  48. If a library is already open when this method is called, it will first close the library
  49. before attempting to load the new one.
  50. @returns true if the library was successfully found and opened.
  51. */
  52. bool open (const String& name);
  53. /** Releases the currently-open DLL, or has no effect if none was open. */
  54. void close();
  55. /** Tries to find a named function in the currently-open DLL, and returns a pointer to it.
  56. If no library is open, or if the function isn't found, this will return a null pointer.
  57. */
  58. void* getFunction (const String& functionName) noexcept;
  59. /** Returns the platform-specific native library handle.
  60. You'll need to cast this to whatever is appropriate for the OS that's in use.
  61. */
  62. void* getNativeHandle() const noexcept { return handle; }
  63. private:
  64. void* handle = nullptr;
  65. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DynamicLibrary)
  66. };
  67. } // namespace juce