Commit 371dda71 authored by Rémi Denis-Courmont's avatar 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.
parent cd76bf4e
......@@ -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
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment