1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_WIN_CORE_WINRT_UTIL_H_
6 #define BASE_WIN_CORE_WINRT_UTIL_H_
7 
8 #include <hstring.h>
9 #include <inspectable.h>
10 #include <roapi.h>
11 #include <windef.h>
12 
13 #include "base/base_export.h"
14 #include "base/strings/string16.h"
15 #include "base/win/scoped_hstring.h"
16 
17 namespace base {
18 namespace win {
19 
20 // Provides access to Core WinRT functions which may not be available on
21 // Windows 7. Loads functions dynamically at runtime to prevent library
22 // dependencies.
23 
24 BASE_EXPORT bool ResolveCoreWinRTDelayload();
25 
26 // The following stubs are provided for when component build is enabled, in
27 // order to avoid the propagation of delay-loading CoreWinRT to other modules.
28 
29 BASE_EXPORT HRESULT RoInitialize(RO_INIT_TYPE init_type);
30 
31 BASE_EXPORT void RoUninitialize();
32 
33 BASE_EXPORT HRESULT RoGetActivationFactory(HSTRING class_id,
34                                            const IID& iid,
35                                            void** out_factory);
36 
37 BASE_EXPORT HRESULT RoActivateInstance(HSTRING class_id,
38                                        IInspectable** instance);
39 
40 // Retrieves an activation factory for the type specified.
41 template <typename InterfaceType, wchar_t const* runtime_class_id>
GetActivationFactory(InterfaceType ** factory)42 HRESULT GetActivationFactory(InterfaceType** factory) {
43   ScopedHString class_id_hstring = ScopedHString::Create(runtime_class_id);
44   if (!class_id_hstring.is_valid())
45     return E_FAIL;
46 
47   return base::win::RoGetActivationFactory(class_id_hstring.get(),
48                                            IID_PPV_ARGS(factory));
49 }
50 
51 }  // namespace win
52 }  // namespace base
53 
54 #endif  // BASE_WIN_CORE_WINRT_UTIL_H_
55