Audio plugin host https://kx.studio/carla
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.

113 lines
4.5KB

  1. //------------------------------------------------------------------------
  2. // Project : SDK Base
  3. // Version : 1.0
  4. //
  5. // Category : Helpers
  6. // Filename : base/source/fdynlib.h
  7. // Created by : Steinberg, 1998
  8. // Description : Dynamic library loading
  9. //
  10. //-----------------------------------------------------------------------------
  11. // LICENSE
  12. // (c) 2017, Steinberg Media Technologies GmbH, All Rights Reserved
  13. //-----------------------------------------------------------------------------
  14. // Redistribution and use in source and binary forms, with or without modification,
  15. // are permitted provided that the following conditions are met:
  16. //
  17. // * Redistributions of source code must retain the above copyright notice,
  18. // this list of conditions and the following disclaimer.
  19. // * Redistributions in binary form must reproduce the above copyright notice,
  20. // this list of conditions and the following disclaimer in the documentation
  21. // and/or other materials provided with the distribution.
  22. // * Neither the name of the Steinberg Media Technologies nor the names of its
  23. // contributors may be used to endorse or promote products derived from this
  24. // software without specific prior written permission.
  25. //
  26. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  27. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  28. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  29. // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  30. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  31. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  34. // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  35. // OF THE POSSIBILITY OF SUCH DAMAGE.
  36. //-----------------------------------------------------------------------------
  37. //------------------------------------------------------------------------
  38. /** @file base/source/fdynlib.h
  39. Platform independent dynamic library loading. */
  40. //------------------------------------------------------------------------
  41. #pragma once
  42. #include "pluginterfaces/base/ftypes.h"
  43. #include "base/source/fobject.h"
  44. namespace Steinberg {
  45. //------------------------------------------------------------------------
  46. /** Platform independent dynamic library loader. */
  47. //------------------------------------------------------------------------
  48. class FDynLibrary : public FObject
  49. {
  50. public:
  51. //------------------------------------------------------------------------
  52. /** Constructor.
  53. Loads the specified dynamic library.
  54. @param[in] name the path of the library to load.
  55. @param[in] addExtension if @c true append the platform dependent default extension to @c name.
  56. @remarks
  57. - If @c name specifies a full path, the FDynLibrary searches only that path for the library.
  58. - If @c name specifies a relative path or a name without path,
  59. FDynLibrary uses a standard search strategy of the current platform to find the library;
  60. - If @c name is @c NULL the library is not loaded.
  61. - Use init() to load the library. */
  62. FDynLibrary (const tchar* name = 0, bool addExtension = true);
  63. /** Destructor.
  64. The destructor unloads the library.*/
  65. ~FDynLibrary ();
  66. /** Loads the library if not already loaded.
  67. This function is normally called by FDynLibrary().
  68. @remarks If the library is already loaded, this call has no effect. */
  69. bool init (const tchar* name, bool addExtension = true);
  70. /** Returns the address of the procedure @c name */
  71. void* getProcAddress (const char* name);
  72. /** Returns true when the library was successfully loaded. */
  73. bool isLoaded () {return isloaded;}
  74. /** Unloads the library if it is loaded.
  75. This function is called by ~FDynLibrary (). */
  76. bool unload ();
  77. /** Returns the platform dependent representation of the library instance. */
  78. void* getPlatformInstance () const { return instance; }
  79. #if MAC
  80. /** Returns @c true if the library is a bundle (Mac only). */
  81. bool isBundleLib () const {return isBundle;}
  82. #endif
  83. //------------------------------------------------------------------------
  84. OBJ_METHODS(FDynLibrary, FObject)
  85. protected:
  86. bool isloaded;
  87. void* instance;
  88. #if MAC
  89. void* firstSymbol;
  90. bool isBundle;
  91. #endif
  92. };
  93. //------------------------------------------------------------------------
  94. } // namespace Steinberg