1 /*****************************************************************************
2 * winvlc.c: the Windows VLC player
3 *****************************************************************************
4 * Copyright (C) 1998-2008 the VideoLAN team
6 * Authors: Vincent Seguin <seguin@via.ecp.fr>
7 * Samuel Hocevar <sam@zoy.org>
8 * Gildas Bazin <gbazin@videolan.org>
9 * Derk-Jan Hartman <hartman at videolan dot org>
10 * Lots of other people, see the libvlc AUTHORS file
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
39 static char *FromWide (const wchar_t *wide)
42 len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
44 char *out = (char *)malloc (len);
46 WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
50 static int parse_cmdline (char *line, char ***argvp)
52 char **argv = malloc (sizeof (char *));
59 /* Skips white spaces */
60 while (strchr ("\t ", *line))
65 /* Starts a new parameter */
66 argv = realloc (argv, (argc + 2) * sizeof (char *));
75 while (*line && !strchr ("\t ", *line))
78 if (line > argv[argc - 1] && line[-1] == quote)
79 /* End of quoted parameter */
84 /* Space within a quote */
89 /* End of unquoted parameter */
99 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
109 wchar_t **wargv = CommandLineToArgvW (GetCommandLine (), &argc);
113 char *argv[argc + 1];
114 for (int i = 0; i < argc; i++)
115 argv[i] = FromWide (wargv[i]);
119 char **argv, psz_cmdline[wcslen(lpCmdLine) * 4];
121 WideCharToMultiByte( CP_UTF8, 0, lpCmdLine, -1,
122 psz_cmdline, sizeof (psz_cmdline), NULL, NULL );
124 argc = parse_cmdline (psz_cmdline, &argv);
127 libvlc_exception_t ex, dummy;
128 libvlc_exception_init (&ex);
129 libvlc_exception_init (&dummy);
131 /* Initialize libvlc */
132 libvlc_instance_t *vlc;
133 vlc = libvlc_new (argc - 1, (const char **)argv + 1, &ex);
136 libvlc_add_intf (vlc, NULL, &ex);
137 libvlc_playlist_play (vlc, -1, 0, NULL, &dummy);
139 libvlc_release (vlc);
142 ret = libvlc_exception_raised (&ex);
143 libvlc_exception_clear (&ex);
144 libvlc_exception_clear (&dummy);
146 for (int i = 0; i < argc; i++)
149 (void)hInstance; (void)hPrevInstance; (void)lpCmdLine; (void)nCmdShow;