1 /*############################################################################
2 # Copyright (C) Intel Corporation
4 # SPDX-License-Identifier: MIT
5 ############################################################################*/
7 #include "windows/mfx_load_dll.h"
8 #include "windows/mfx_dispatcher.h"
15 const wchar_t *const defaultDLLName[2] = { L"libmfxhw64.dll", L"libvplswref64.dll" };
16 const wchar_t *const defaultAudioDLLName[2] = { L"libmfxaudiosw64.dll", L"libmfxaudiosw64.dll" };
17 const wchar_t *const defaultOneVPLDLLName = { L"libmfx64-gen.dll" };
19 const wchar_t *const defaultPluginDLLName[2] = { L"mfxplugin64_hw.dll", L"mfxplugin64_sw.dll" };
20 #if defined(MEDIASDK_UWP_DISPATCHER)
21 const wchar_t *const IntelGFXAPIDLLName = { L"intel_gfx_api-x64.dll" };
25 const wchar_t *const defaultDLLName[2] = { L"libmfxhw32.dll", L"libvplswref32.dll" };
27 const wchar_t *const defaultAudioDLLName[2] = { L"libmfxaudiosw32.dll", L"libmfxaudiosw32.dll" };
29 const wchar_t *const defaultOneVPLDLLName = { L"libmfx32-gen.dll" };
31 const wchar_t *const defaultPluginDLLName[2] = { L"mfxplugin32_hw.dll", L"mfxplugin32_sw.dll" };
33 #if defined(MEDIASDK_UWP_DISPATCHER)
34 const wchar_t *const IntelGFXAPIDLLName = { L"intel_gfx_api-x86.dll" };
37 #endif // (defined(_WIN64))
41 mfxStatus mfx_get_default_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType) {
43 return MFX_ERR_NULL_PTR;
46 // there are only 2 implementation with default DLL names
48 return 0 == wcscpy_s(pPath, pathSize, defaultDLLName[implType & 1]) ? MFX_ERR_NONE
51 wcscpy(pPath, defaultDLLName[implType & 1]);
54 } // mfxStatus mfx_get_default_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType)
56 mfxStatus mfx_get_default_onevpl_dll_name(wchar_t *pPath, size_t pathSize) {
58 return MFX_ERR_NULL_PTR;
61 // there are only 2 implementation with default DLL names
63 return 0 == wcscpy_s(pPath, pathSize, defaultOneVPLDLLName) ? MFX_ERR_NONE : MFX_ERR_UNKNOWN;
65 wcscpy(pPath, defaultOneVPLDLLName);
68 } // mfxStatus mfx_get_default_onevpl_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType)
70 #if defined(MEDIASDK_UWP_DISPATCHER)
71 mfxStatus mfx_get_default_intel_gfx_api_dll_name(wchar_t *pPath, size_t pathSize) {
73 return MFX_ERR_NULL_PTR;
77 return 0 == wcscpy_s(pPath, pathSize, IntelGFXAPIDLLName) ? MFX_ERR_NONE : MFX_ERR_UNKNOWN;
79 wcscpy(pPath, IntelGFXAPIDLLName);
82 } // mfx_get_default_intel_gfx_api_dll_name(wchar_t *pPath, size_t pathSize)
85 mfxStatus mfx_get_default_plugin_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType) {
87 return MFX_ERR_NULL_PTR;
90 // there are only 2 implementation with default DLL names
92 return 0 == wcscpy_s(pPath, pathSize, defaultPluginDLLName[implType & 1]) ? MFX_ERR_NONE
95 wcscpy(pPath, defaultPluginDLLName[implType & 1]);
100 mfxStatus mfx_get_default_audio_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType) {
102 return MFX_ERR_NULL_PTR;
105 // there are only 2 implementation with default DLL names
107 return 0 == wcscpy_s(pPath, pathSize, defaultAudioDLLName[implType & 1]) ? MFX_ERR_NONE
110 wcscpy(pPath, defaultAudioDLLName[implType & 1]);
113 } // mfxStatus mfx_get_default_audio_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType)
115 mfxModuleHandle mfx_dll_load(const wchar_t *pFileName) {
116 mfxModuleHandle hModule = (mfxModuleHandle)0;
119 if (NULL == pFileName) {
122 #if !defined(MEDIASDK_UWP_DISPATCHER)
123 // set the silent error mode
124 DWORD prevErrorMode = 0;
125 #if (_WIN32_WINNT >= 0x0600)
126 SetThreadErrorMode(SEM_FAILCRITICALERRORS, &prevErrorMode);
128 prevErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
130 #endif // !defined(MEDIASDK_UWP_DISPATCHER)
132 // load the library's module
133 #if !defined(MEDIASDK_ARM_LOADER)
134 hModule = LoadLibraryExW(pFileName, NULL, 0);
137 #if !defined(MEDIASDK_UWP_DISPATCHER)
138 // set the previous error mode
139 #if (_WIN32_WINNT >= 0x0600)
140 SetThreadErrorMode(prevErrorMode, NULL);
142 SetErrorMode(prevErrorMode);
144 #endif // !defined(MEDIASDK_UWP_DISPATCHER)
148 } // mfxModuleHandle mfx_dll_load(const wchar_t *pFileName)
150 mfxFunctionPointer mfx_dll_get_addr(mfxModuleHandle handle, const char *pFunctionName) {
151 if (NULL == handle) {
155 return (mfxFunctionPointer)GetProcAddress((HMODULE)handle, pFunctionName);
156 } // mfxFunctionPointer mfx_dll_get_addr(mfxModuleHandle handle, const char *pFunctionName)
158 bool mfx_dll_free(mfxModuleHandle handle) {
159 if (NULL == handle) {
163 BOOL bRes = FreeLibrary((HMODULE)handle);
166 } // bool mfx_dll_free(mfxModuleHandle handle)
168 #if !defined(MEDIASDK_UWP_DISPATCHER)
169 mfxModuleHandle mfx_get_dll_handle(const wchar_t *pFileName) {
170 mfxModuleHandle hModule = (mfxModuleHandle)0;
173 if (NULL == pFileName) {
177 // set the silent error mode
178 DWORD prevErrorMode = 0;
179 #if (_WIN32_WINNT >= 0x0600)
180 SetThreadErrorMode(SEM_FAILCRITICALERRORS, &prevErrorMode);
182 prevErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
184 // load the library's module
185 GetModuleHandleExW(0, pFileName, (HMODULE *)&hModule);
186 // set the previous error mode
187 #if (_WIN32_WINNT >= 0x0600)
188 SetThreadErrorMode(prevErrorMode, NULL);
190 SetErrorMode(prevErrorMode);
194 #endif //!defined(MEDIASDK_UWP_DISPATCHER)