VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_events / native / juce_win32_WinRTWrapper.cpp
blobaf4a79372db7fd3e35517378d9c87e52187dd4ae
1 /*
2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
20 ==============================================================================
23 namespace juce
26 WinRTWrapper::WinRTWrapper()
28 winRTHandle = ::LoadLibraryA ("api-ms-win-core-winrt-l1-1-0");
30 if (winRTHandle == nullptr)
31 return;
33 roInitialize = (RoInitializeFuncPtr) ::GetProcAddress (winRTHandle, "RoInitialize");
34 createHString = (WindowsCreateStringFuncPtr) ::GetProcAddress (winRTHandle, "WindowsCreateString");
35 deleteHString = (WindowsDeleteStringFuncPtr) ::GetProcAddress (winRTHandle, "WindowsDeleteString");
36 getHStringRawBuffer = (WindowsGetStringRawBufferFuncPtr) ::GetProcAddress (winRTHandle, "WindowsGetStringRawBuffer");
37 roActivateInstance = (RoActivateInstanceFuncPtr) ::GetProcAddress (winRTHandle, "RoActivateInstance");
38 roGetActivationFactory = (RoGetActivationFactoryFuncPtr) ::GetProcAddress (winRTHandle, "RoGetActivationFactory");
40 if (roInitialize == nullptr || createHString == nullptr || deleteHString == nullptr
41 || getHStringRawBuffer == nullptr || roActivateInstance == nullptr || roGetActivationFactory == nullptr)
42 return;
44 HRESULT status = roInitialize (1);
45 initialised = ! (status != S_OK && status != S_FALSE && status != 0x80010106L);
48 WinRTWrapper::~WinRTWrapper()
50 if (winRTHandle != nullptr)
51 ::FreeLibrary (winRTHandle);
53 clearSingletonInstance();
56 WinRTWrapper::ScopedHString::ScopedHString (String str)
58 if (WinRTWrapper::getInstance()->isInitialised())
59 WinRTWrapper::getInstance()->createHString (str.toWideCharPointer(),
60 static_cast<uint32_t> (str.length()),
61 &hstr);
64 WinRTWrapper::ScopedHString::~ScopedHString()
66 if (WinRTWrapper::getInstance()->isInitialised() && hstr != nullptr)
67 WinRTWrapper::getInstance()->deleteHString (hstr);
70 String WinRTWrapper::hStringToString (HSTRING hstr)
72 if (isInitialised())
73 if (const wchar_t* str = getHStringRawBuffer (hstr, nullptr))
74 return String (str);
76 return {};
80 JUCE_IMPLEMENT_SINGLETON (WinRTWrapper)