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 #include "rtc_base/win/get_activation_factory.h" 12 13 #include <libloaderapi.h> 14 #include <roapi.h> 15 16 namespace { 17 LoadComBaseFunction(const char * function_name)18FARPROC LoadComBaseFunction(const char* function_name) { 19 static HMODULE const handle = 20 ::LoadLibraryExW(L"combase.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); 21 return handle ? ::GetProcAddress(handle, function_name) : nullptr; 22 } 23 GetRoGetActivationFactoryFunction()24decltype(&::RoGetActivationFactory) GetRoGetActivationFactoryFunction() { 25 static decltype(&::RoGetActivationFactory) const function = 26 reinterpret_cast<decltype(&::RoGetActivationFactory)>( 27 LoadComBaseFunction("RoGetActivationFactory")); 28 return function; 29 } 30 31 } // namespace 32 33 namespace webrtc { 34 ResolveCoreWinRTDelayload()35bool ResolveCoreWinRTDelayload() { 36 return GetRoGetActivationFactoryFunction() && 37 ResolveCoreWinRTStringDelayload(); 38 } 39 RoGetActivationFactoryProxy(HSTRING class_id,const IID & iid,void ** out_factory)40HRESULT RoGetActivationFactoryProxy(HSTRING class_id, 41 const IID& iid, 42 void** out_factory) { 43 auto get_factory_func = GetRoGetActivationFactoryFunction(); 44 if (!get_factory_func) 45 return E_FAIL; 46 return get_factory_func(class_id, iid, out_factory); 47 } 48 49 } // namespace webrtc 50