1 /*****************************************************************************
2 * plugin.c : Low-level dynamic library handling
3 *****************************************************************************
4 * Copyright (C) 2001-2011 the VideoLAN team
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
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 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 General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
30 #include <vlc_common.h>
31 #include <vlc_charset.h>
32 #include "modules/modules.h"
36 static char *GetWindowsError( void )
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),
45 /* Go to the end of the string */
46 while( !wmemchr( L"\r\n\0", wmsg[i], 3 ) )
49 snwprintf( wmsg + i, 256 - i, L" (error %i)", i_error );
50 return FromWide( wmsg );
53 int module_Load( vlc_object_t *p_this, const char *psz_file,
54 module_handle_t *p_handle, bool lazy )
56 wchar_t *wfile = ToWide (psz_file);
60 module_handle_t handle;
62 /* FIXME: this is not thread-safe -- Courmisch */
63 UINT mode = SetErrorMode (SEM_FAILCRITICALERRORS);
64 SetErrorMode (mode|SEM_FAILCRITICALERRORS);
67 handle = LoadLibraryW (wfile);
76 char *psz_err = GetWindowsError();
77 msg_Warn( p_this, "cannot load module `%s' (%s)", psz_file, psz_err );
87 void module_Unload( module_handle_t handle )
89 FreeLibrary( handle );
92 void *module_Lookup( module_handle_t handle, const char *psz_function )
95 wchar_t wide[strlen( psz_function ) + 1];
98 wide[i] = psz_function[i]; /* UTF-16 <- ASCII */
99 while( psz_function[i++] );
101 return (void *)GetProcAddress( handle, wide );
104 return (void *)GetProcAddress( handle, (char *)psz_function );