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
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
20 ==============================================================================
26 class WinRTWrapper
: public DeletedAtShutdown
29 //==============================================================================
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
;
43 ComSmartPtr
<IInspectable
> inspectable
;
44 ScopedHString
runtimeClass (runtimeClassID
);
45 auto hr
= roActivateInstance (runtimeClass
.get(), inspectable
.resetAndGetPointerAddress());
48 inspectable
->QueryInterface (classUUID
, (void**) result
.resetAndGetPointerAddress());
54 template <class ComClass
>
55 ComSmartPtr
<ComClass
> getWRLFactory (const wchar_t* runtimeClassID
)
57 ComSmartPtr
<ComClass
> comPtr
;
61 ScopedHString
classID (runtimeClassID
);
63 if (classID
.get() != nullptr)
64 roGetActivationFactory (classID
.get(), __uuidof (ComClass
), (void**) comPtr
.resetAndGetPointerAddress());
70 //==============================================================================
74 ScopedHString (String
);
77 HSTRING
get() const noexcept
{ return hstr
; }
80 HSTRING hstr
= nullptr;
82 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ScopedHString
)
85 String
hStringToString (HSTRING
);
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
)