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.

88 lines
3.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_DYNAMICLIBRARY_H_INCLUDED
  24. #define JUCE_DYNAMICLIBRARY_H_INCLUDED
  25. /**
  26. Handles the opening and closing of DLLs.
  27. This class can be used to open a DLL and get some function pointers from it.
  28. Since the DLL is freed when this object is deleted, it's handy for managing
  29. library lifetimes using RAII.
  30. */
  31. class JUCE_API DynamicLibrary
  32. {
  33. public:
  34. /** Creates an unopened DynamicLibrary object.
  35. Call open() to actually open one.
  36. */
  37. DynamicLibrary() noexcept : handle (nullptr) {}
  38. /**
  39. */
  40. DynamicLibrary (const String& name) : handle (nullptr) { open (name); }
  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;
  65. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DynamicLibrary)
  66. };
  67. #endif // JUCE_DYNAMICLIBRARY_H_INCLUDED