1 /* 2 * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef RTC_BASE_WIN_GET_ACTIVATION_FACTORY_H_ 12 #define RTC_BASE_WIN_GET_ACTIVATION_FACTORY_H_ 13 14 #include <winerror.h> 15 16 #include "rtc_base/win/hstring.h" 17 18 namespace webrtc { 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 // Callers must check the return value of ResolveCoreWinRTDelayLoad() before 25 // using these functions. 26 27 bool ResolveCoreWinRTDelayload(); 28 29 HRESULT RoGetActivationFactoryProxy(HSTRING class_id, 30 const IID& iid, 31 void** out_factory); 32 33 // Retrieves an activation factory for the type specified. 34 template <typename InterfaceType, wchar_t const* runtime_class_id> GetActivationFactory(InterfaceType ** factory)35HRESULT GetActivationFactory(InterfaceType** factory) { 36 HSTRING class_id_hstring; 37 HRESULT hr = CreateHstring(runtime_class_id, wcslen(runtime_class_id), 38 &class_id_hstring); 39 if (FAILED(hr)) 40 return hr; 41 42 hr = RoGetActivationFactoryProxy(class_id_hstring, IID_PPV_ARGS(factory)); 43 if (FAILED(hr)) { 44 DeleteHstring(class_id_hstring); 45 return hr; 46 } 47 48 return DeleteHstring(class_id_hstring); 49 } 50 51 } // namespace webrtc 52 53 #endif // RTC_BASE_WIN_GET_ACTIVATION_FACTORY_H_ 54