modules: clean up vlc_dl(open|close|sym) wrappers
[vlc.git] / src / win32 / plugin.c
bloba0d392e6e0f4842bb1a37ae4fa41286990849df3
1 /*****************************************************************************
2 * plugin.c : Low-level dynamic library handling
3 *****************************************************************************
4 * Copyright (C) 2001-2011 VLC authors and VideoLAN
6 * Authors: Sam Hocevar <sam@zoy.org>
7 * Ethan C. Baldridge <BaldridgeE@cadmus.com>
8 * Hans-Peter Jansen <hpj@urpla.net>
9 * Gildas Bazin <gbazin@videolan.org>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
30 #include <vlc_common.h>
31 #include <vlc_charset.h>
32 #include "modules/modules.h"
33 #include <windows.h>
34 #include <wchar.h>
36 char *vlc_dlerror(void)
38 wchar_t wmsg[256];
39 int i = 0, i_error = GetLastError();
41 FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
42 NULL, i_error, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
43 wmsg, 256, NULL );
45 /* Go to the end of the string */
46 while( !wmemchr( L"\r\n\0", wmsg[i], 3 ) )
47 i++;
49 snwprintf( wmsg + i, 256 - i, L" (error %i)", i_error );
50 return FromWide( wmsg );
53 void *vlc_dlopen(const char *psz_file, bool lazy)
55 wchar_t *wfile = ToWide (psz_file);
56 if (wfile == NULL)
57 return NULL;
59 HMODULE handle = NULL;
60 #if !VLC_WINSTORE_APP
61 DWORD mode;
62 if (SetThreadErrorMode (SEM_FAILCRITICALERRORS, &mode) != 0)
64 handle = LoadLibraryExW(wfile, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
65 SetThreadErrorMode (mode, NULL);
67 #else
68 handle = LoadPackagedLibrary( wfile, 0 );
69 #endif
70 free (wfile);
72 (void) lazy;
73 return handle;
76 int vlc_dlclose(void *handle)
78 FreeLibrary( handle );
79 return 0;
82 void *vlc_dlsym(void *handle, const char *psz_function)
84 return (void *)GetProcAddress(handle, psz_function);