VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_events / native / juce_win32_WinRTWrapper.h
blobaf0e1b96fd235a52545ab3ff9e471d8234e8c0e4
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 class WinRTWrapper : public DeletedAtShutdown
28 public:
29 //==============================================================================
30 ~WinRTWrapper();
31 bool isInitialised() const noexcept { return initialised; }
33 JUCE_DECLARE_SINGLETON (WinRTWrapper, true)
35 //==============================================================================
36 template <class ComClass>
37 ComSmartPtr<ComClass> activateInstance (const wchar_t* runtimeClassID, REFCLSID classUUID)
39 ComSmartPtr<ComClass> result;
41 if (isInitialised())
43 ComSmartPtr<IInspectable> inspectable;
44 ScopedHString runtimeClass (runtimeClassID);
45 auto hr = roActivateInstance (runtimeClass.get(), inspectable.resetAndGetPointerAddress());
47 if (SUCCEEDED (hr))
48 inspectable->QueryInterface (classUUID, (void**) result.resetAndGetPointerAddress());
51 return result;
54 template <class ComClass>
55 ComSmartPtr<ComClass> getWRLFactory (const wchar_t* runtimeClassID)
57 ComSmartPtr<ComClass> comPtr;
59 if (isInitialised())
61 ScopedHString classID (runtimeClassID);
63 if (classID.get() != nullptr)
64 roGetActivationFactory (classID.get(), __uuidof (ComClass), (void**) comPtr.resetAndGetPointerAddress());
67 return comPtr;
70 //==============================================================================
71 class ScopedHString
73 public:
74 ScopedHString (String);
75 ~ScopedHString();
77 HSTRING get() const noexcept { return hstr; }
79 private:
80 HSTRING hstr = nullptr;
82 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ScopedHString)
85 String hStringToString (HSTRING);
87 private:
88 WinRTWrapper();
90 //==============================================================================
91 HMODULE winRTHandle = nullptr;
92 bool initialised = false;
94 typedef HRESULT (WINAPI* RoInitializeFuncPtr) (int);
95 typedef HRESULT (WINAPI* WindowsCreateStringFuncPtr) (LPCWSTR, UINT32, HSTRING*);
96 typedef HRESULT (WINAPI* WindowsDeleteStringFuncPtr) (HSTRING);
97 typedef PCWSTR (WINAPI* WindowsGetStringRawBufferFuncPtr) (HSTRING, UINT32*);
98 typedef HRESULT (WINAPI* RoActivateInstanceFuncPtr) (HSTRING, IInspectable**);
99 typedef HRESULT (WINAPI* RoGetActivationFactoryFuncPtr) (HSTRING, REFIID, void**);
101 RoInitializeFuncPtr roInitialize = nullptr;
102 WindowsCreateStringFuncPtr createHString = nullptr;
103 WindowsDeleteStringFuncPtr deleteHString = nullptr;
104 WindowsGetStringRawBufferFuncPtr getHStringRawBuffer = nullptr;
105 RoActivateInstanceFuncPtr roActivateInstance = nullptr;
106 RoGetActivationFactoryFuncPtr roGetActivationFactory = nullptr;
108 //==============================================================================
109 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WinRTWrapper)
112 } // namespace juce