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.

juce_win32_WinRTWrapper.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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. WinRTWrapper::ScopedHString::ScopedHString (String str)
  20. {
  21. if (WinRTWrapper::getInstance()->isInitialised())
  22. WinRTWrapper::getInstance()->createHString (str.toWideCharPointer(),
  23. static_cast<uint32_t> (str.length()),
  24. &hstr);
  25. }
  26. WinRTWrapper::ScopedHString::~ScopedHString()
  27. {
  28. if (WinRTWrapper::getInstance()->isInitialised() && hstr != nullptr)
  29. WinRTWrapper::getInstance()->deleteHString (hstr);
  30. }
  31. WinRTWrapper::~WinRTWrapper()
  32. {
  33. if (winRTHandle != nullptr)
  34. ::FreeLibrary (winRTHandle);
  35. clearSingletonInstance();
  36. }
  37. String WinRTWrapper::hStringToString (HSTRING hstr)
  38. {
  39. if (isInitialised())
  40. if (const wchar_t* str = getHStringRawBuffer (hstr, nullptr))
  41. return String (str);
  42. return {};
  43. }
  44. WinRTWrapper::WinRTWrapper()
  45. {
  46. winRTHandle = ::LoadLibraryA ("api-ms-win-core-winrt-l1-1-0");
  47. if (winRTHandle == nullptr)
  48. return;
  49. roInitialize = (RoInitializeFuncPtr) ::GetProcAddress (winRTHandle, "RoInitialize");
  50. createHString = (WindowsCreateStringFuncPtr) ::GetProcAddress (winRTHandle, "WindowsCreateString");
  51. deleteHString = (WindowsDeleteStringFuncPtr) ::GetProcAddress (winRTHandle, "WindowsDeleteString");
  52. getHStringRawBuffer = (WindowsGetStringRawBufferFuncPtr) ::GetProcAddress (winRTHandle, "WindowsGetStringRawBuffer");
  53. roActivateInstance = (RoActivateInstanceFuncPtr) ::GetProcAddress (winRTHandle, "RoActivateInstance");
  54. roGetActivationFactory = (RoGetActivationFactoryFuncPtr) ::GetProcAddress (winRTHandle, "RoGetActivationFactory");
  55. if (roInitialize == nullptr || createHString == nullptr || deleteHString == nullptr
  56. || getHStringRawBuffer == nullptr || roActivateInstance == nullptr || roGetActivationFactory == nullptr)
  57. return;
  58. HRESULT status = roInitialize (1);
  59. initialised = ! (status != S_OK && status != S_FALSE && status != 0x80010106L);
  60. }
  61. JUCE_IMPLEMENT_SINGLETON (WinRTWrapper)
  62. }