[XAudio2] avoid leak + fix voice creation for closest match
[xbmc.git] / xbmc / DynamicDll.cpp
blob29538f99f17400efb30cff9f3fe46d2b5167c7a3
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "DynamicDll.h"
11 #include "SectionLoader.h"
12 #include "utils/FileUtils.h"
13 #include "utils/log.h"
15 DllDynamic::DllDynamic()
17 m_dll=NULL;
18 m_DelayUnload=true;
21 DllDynamic::DllDynamic(const std::string& strDllName):
22 m_strDllName(strDllName)
24 m_dll=NULL;
25 m_DelayUnload=true;
28 DllDynamic::~DllDynamic()
30 Unload();
33 bool DllDynamic::Load()
35 if (m_dll)
36 return true;
38 if (!(m_dll=CSectionLoader::LoadDLL(m_strDllName, m_DelayUnload, LoadSymbols())))
39 return false;
41 if (!ResolveExports())
43 CLog::Log(LOGERROR, "Unable to resolve exports from dll {}", m_strDllName);
44 Unload();
45 return false;
48 return true;
51 void DllDynamic::Unload()
53 if(m_dll)
54 CSectionLoader::UnloadDLL(m_strDllName);
55 m_dll=NULL;
58 bool DllDynamic::CanLoad()
60 return CFileUtils::Exists(m_strDllName);
63 bool DllDynamic::EnableDelayedUnload(bool bOnOff)
65 if (m_dll)
66 return false;
68 m_DelayUnload=bOnOff;
70 return true;
73 bool DllDynamic::SetFile(const std::string& strDllName)
75 if (m_dll)
76 return false;
78 m_strDllName=strDllName;
79 return true;