vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Mon Jul 20 22:23:58 2015 +0300| [371dda7105972f94065e49c6145960a6d9134fb9] | committer: Rémi Denis-Courmont
win32: fallback for SetThreadErrorMode() SetThreadErrorMode() is necessary for correct plugin loader semantics, but it is only available on Windows 7 and later, so it needs to be loaded at run-time if it is to be used. On Windows 2008 and older, a fallback is provided to the extent possible. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=371dda7105972f94065e49c6145960a6d9134fb9 --- src/win32/plugin.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/win32/plugin.c b/src/win32/plugin.c index a9e0e6c..3024f3d 100644 --- a/src/win32/plugin.c +++ b/src/win32/plugin.c @@ -33,6 +33,39 @@ #include <windows.h> #include <wchar.h> +#if (_WIN32_WINNT < 0x601) +static BOOL WINAPI SetThreadErrorModeFallback(DWORD mode, DWORD *oldmode) +{ + /* TODO: cache the pointer */ + HANDLE h = GetModuleHandle(_T("kernel32.dll")); + if (unlikely(h == NULL)) + return FALSE; + + BOOL WINAPI (*SetThreadErrorModeReal)(DWORD, DWORD *); + + SetThreadErrorModeReal = GetProcAddress(h, "SetThreadErrorMode"); + if (SetThreadErrorModeReal != NULL) + return SetThreadErrorModeReal(mode, oldmode); + +# if (_WIN32_WINNT >= 0x600) + DWORD curmode = GetErrorMode(); +# else + UINT WINAPI (*GetErrorModeReal)(void); + DWORD curmode = 0; + + GetErrorModeReal = (void *)GetProcAddress(h, "GetErrorMode"); + if (GetErrorModeReal != NULL) + curmode = GetErrorModeReal(); +# endif + if ((mode & SEM_FAILCRITICALERRORS) != (curmode & SEM_FAILCRITICALERRORS)) + return FALSE; + if (oldmode != NULL) + *oldmode = curmode; + return TRUE; +} +# define SetThreadErrorMode SetThreadErrorModeFallback +#endif + static char *GetWindowsError( void ) { wchar_t wmsg[256]; @@ -58,14 +91,14 @@ int module_Load( vlc_object_t *p_this, const char *psz_file, return -1; module_handle_t handle = NULL; -#if (_WIN32_WINNT >= 0x601) && !VLC_WINSTORE_APP +#if !VLC_WINSTORE_APP DWORD mode; if (SetThreadErrorMode (SEM_FAILCRITICALERRORS, &mode) != 0) #endif { handle = LoadLibraryW (wfile); -#if (_WIN32_WINNT >= 0x601) && !VLC_WINSTORE_APP +#if !VLC_WINSTORE_APP SetThreadErrorMode (mode, NULL); #endif } _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
