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.

83 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_DYNAMICLIBRARY_JUCEHEADER__
  19. #define __JUCE_DYNAMICLIBRARY_JUCEHEADER__
  20. /**
  21. Handles the opening and closing of DLLs.
  22. This class can be used to open a DLL and get some function pointers from it.
  23. Since the DLL is freed when this object is deleted, it's handy for managing
  24. library lifetimes using RAII.
  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() noexcept : handle (nullptr) {}
  33. /**
  34. */
  35. DynamicLibrary (const String& name) : handle (nullptr) { open (name); }
  36. /** Destructor.
  37. If a library is currently open, it will be closed when this object is destroyed.
  38. */
  39. ~DynamicLibrary() { close(); }
  40. /** Opens a DLL.
  41. The name and the method by which it gets found is of course platform-specific, and
  42. may or may not include a path, depending on the OS.
  43. If a library is already open when this method is called, it will first close the library
  44. before attempting to load the new one.
  45. @returns true if the library was successfully found and opened.
  46. */
  47. bool open (const String& name);
  48. /** Releases the currently-open DLL, or has no effect if none was open. */
  49. void close();
  50. /** Tries to find a named function in the currently-open DLL, and returns a pointer to it.
  51. If no library is open, or if the function isn't found, this will return a null pointer.
  52. */
  53. void* getFunction (const String& functionName) noexcept;
  54. /** Returns the platform-specific native library handle.
  55. You'll need to cast this to whatever is appropriate for the OS that's in use.
  56. */
  57. void* getNativeHandle() const noexcept { return handle; }
  58. private:
  59. void* handle;
  60. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DynamicLibrary);
  61. };
  62. #endif // __JUCE_DYNAMICLIBRARY_JUCEHEADER__