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
3.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. class WinRTWrapper : public DeletedAtShutdown
  20. {
  21. public:
  22. //==============================================================================
  23. ~WinRTWrapper();
  24. bool isInitialised() const noexcept { return initialised; }
  25. JUCE_DECLARE_SINGLETON (WinRTWrapper, true)
  26. //==============================================================================
  27. template <class ComClass>
  28. ComSmartPtr<ComClass> activateInstance (const wchar_t* runtimeClassID, REFCLSID classUUID)
  29. {
  30. ComSmartPtr<ComClass> result;
  31. if (isInitialised())
  32. {
  33. ComSmartPtr<IInspectable> inspectable;
  34. ScopedHString runtimeClass (runtimeClassID);
  35. auto hr = roActivateInstance (runtimeClass.get(), inspectable.resetAndGetPointerAddress());
  36. if (SUCCEEDED (hr))
  37. inspectable->QueryInterface (classUUID, (void**) result.resetAndGetPointerAddress());
  38. }
  39. return result;
  40. }
  41. template <class ComClass>
  42. ComSmartPtr<ComClass> getWRLFactory (const wchar_t* runtimeClassID)
  43. {
  44. ComSmartPtr<ComClass> comPtr;
  45. if (isInitialised())
  46. {
  47. ScopedHString classID (runtimeClassID);
  48. if (classID.get() != nullptr)
  49. roGetActivationFactory (classID.get(), __uuidof (ComClass), (void**) comPtr.resetAndGetPointerAddress());
  50. }
  51. return comPtr;
  52. }
  53. //==============================================================================
  54. class ScopedHString
  55. {
  56. public:
  57. ScopedHString (String);
  58. ~ScopedHString();
  59. HSTRING get() const noexcept { return hstr; }
  60. private:
  61. HSTRING hstr = nullptr;
  62. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ScopedHString)
  63. };
  64. String hStringToString (HSTRING);
  65. private:
  66. WinRTWrapper();
  67. //==============================================================================
  68. HMODULE winRTHandle = nullptr;
  69. bool initialised = false;
  70. typedef HRESULT (WINAPI* RoInitializeFuncPtr) (int);
  71. typedef HRESULT (WINAPI* WindowsCreateStringFuncPtr) (LPCWSTR, UINT32, HSTRING*);
  72. typedef HRESULT (WINAPI* WindowsDeleteStringFuncPtr) (HSTRING);
  73. typedef PCWSTR (WINAPI* WindowsGetStringRawBufferFuncPtr) (HSTRING, UINT32*);
  74. typedef HRESULT (WINAPI* RoActivateInstanceFuncPtr) (HSTRING, IInspectable**);
  75. typedef HRESULT (WINAPI* RoGetActivationFactoryFuncPtr) (HSTRING, REFIID, void**);
  76. RoInitializeFuncPtr roInitialize = nullptr;
  77. WindowsCreateStringFuncPtr createHString = nullptr;
  78. WindowsDeleteStringFuncPtr deleteHString = nullptr;
  79. WindowsGetStringRawBufferFuncPtr getHStringRawBuffer = nullptr;
  80. RoActivateInstanceFuncPtr roActivateInstance = nullptr;
  81. RoGetActivationFactoryFuncPtr roGetActivationFactory = nullptr;
  82. //==============================================================================
  83. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WinRTWrapper)
  84. };
  85. } // namespace juce