]> git.sesse.net Git - vlc/blob - bin/winvlc.c
Win32: do not pass argv[0] to libvlc - fixes #1920
[vlc] / bin / winvlc.c
1 /*****************************************************************************
2  * winvlc.c: the Windows VLC player
3  *****************************************************************************
4  * Copyright (C) 1998-2008 the VideoLAN team
5  *
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
11  *
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.
16  *
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.
21  *
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  *****************************************************************************/
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #define UNICODE
32 #include <vlc/vlc.h>
33 #include <string.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <windows.h>
37
38 static char *FromWide (const wchar_t *wide)
39 {
40     size_t len;
41     len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
42
43     char *out = (char *)malloc (len);
44     if (out)
45         WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
46     return out;
47 }
48
49
50 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
51 #ifndef UNDER_CE
52                     LPSTR lpCmdLine,
53 #else
54                     LPWSTR lpCmdLine,
55 #endif
56                     int nCmdShow )
57 {
58     int argc, ret;
59     wchar_t **wargv = CommandLineToArgvW (GetCommandLine (), &argc);
60     if (wargv == NULL)
61         return 1;
62
63     char *argv[argc + 1];
64     for (int i = 0; i < argc; i++)
65         argv[i] = FromWide (wargv[i]);
66     argv[argc] = NULL;
67     LocalFree (wargv);
68
69     libvlc_exception_t ex, dummy;
70     libvlc_exception_init (&ex);
71     libvlc_exception_init (&dummy);
72
73     /* Initialize libvlc */
74     libvlc_instance_t *vlc;
75     vlc = libvlc_new (argc - 1, (const char **)argv + 1, &ex);
76     if (vlc != NULL)
77     {
78         libvlc_add_intf (vlc, NULL, &ex);
79         libvlc_playlist_play (vlc, -1, 0, NULL, &dummy);
80         libvlc_wait (vlc);
81         libvlc_release (vlc);
82     }
83     free (argv);
84
85     ret = libvlc_exception_raised (&ex);
86     libvlc_exception_clear (&ex);
87     libvlc_exception_clear (&dummy);
88
89     for (int i = 0; i < argc; i++)
90         free (argv[i]);
91
92     (void)hInstance; (void)hPrevInstance; (void)lpCmdLine; (void)nCmdShow;
93     return ret;
94 }