#include <stdlib.h>
#include <windows.h>
+#ifndef UNDER_CE
+static char *FromWide (const wchar_t *wide)
+{
+ size_t len;
+ len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
+
+ char *out = (char *)malloc (len);
+ if (out)
+ WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
+ return out;
+}
+#else
static int parse_cmdline (char *line, char ***argvp)
{
char **argv = malloc (sizeof (char *));
argv[argc++] = line;
more:
- while (*line && !strchr ("\t ", *line))
+ while (*line && !strchr ("\t ", *line))
line++;
- if (line > argv[argc - 1] && line[-1] == quote)
- /* End of quoted parameter */
- line[-1] = 0;
- else
+ if (line > argv[argc - 1] && line[-1] == quote)
+ /* End of quoted parameter */
+ line[-1] = 0;
+ else
if (*line && quote)
- {
- /* Space within a quote */
- line++;
- goto more;
- }
- else
+ {
+ /* Space within a quote */
+ line++;
+ goto more;
+ }
+ else
/* End of unquoted parameter */
if (*line)
*line++ = 0;
*argvp = argv;
return argc;
}
-
-#ifdef UNDER_CE
-# define wWinMain WinMain
#endif
-/*****************************************************************************
- * wWinMain: parse command line, start interface and spawn threads.
- *****************************************************************************/
-int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPWSTR lpCmdLine, int nCmdShow )
+int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
+#ifndef UNDER_CE
+ LPSTR lpCmdLine,
+#else
+ LPWSTR lpCmdLine,
+#endif
+ int nCmdShow )
{
- char **argv, psz_cmdline[wcslen(lpCmdLine) * 4 + 1];
int argc, ret;
-
- (void)hInstance; (void)hPrevInstance; (void)nCmdShow;
+#ifndef UNDER_CE
+ wchar_t **wargv = CommandLineToArgvW (GetCommandLine (), &argc);
+ if (wargv == NULL)
+ return 1;
+
+ char *argv[argc + 1];
+ for (int i = 0; i < argc; i++)
+ argv[i] = FromWide (wargv[i]);
+ argv[argc] = NULL;
+ LocalFree (wargv);
+#else
+ char **argv, psz_cmdline[wcslen(lpCmdLine) * 4];
WideCharToMultiByte( CP_UTF8, 0, lpCmdLine, -1,
psz_cmdline, sizeof (psz_cmdline), NULL, NULL );
argc = parse_cmdline (psz_cmdline, &argv);
+#endif
libvlc_exception_t ex, dummy;
libvlc_exception_init (&ex);
libvlc_exception_init (&dummy);
/* Initialize libvlc */
- libvlc_instance_t *vlc = libvlc_new (argc, (const char **)argv, &ex);
+ libvlc_instance_t *vlc;
+ vlc = libvlc_new (argc - 1, (const char **)argv + 1, &ex);
if (vlc != NULL)
{
libvlc_add_intf (vlc, NULL, &ex);
libvlc_wait (vlc);
libvlc_release (vlc);
}
- free (argv);
ret = libvlc_exception_raised (&ex);
libvlc_exception_clear (&ex);
libvlc_exception_clear (&dummy);
- return ret;
-}
-#ifndef IF_MINGW_SUPPORTED_UNICODE
-int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR args, int nCmdShow)
-{
- /* This makes little sense, but at least it links properly */
- wchar_t lpCmdLine[(strlen (args) + 1) * 3];
- MultiByteToWideChar (CP_ACP, 0, args, -1, lpCmdLine, sizeof (lpCmdLine));
- return wWinMain (hInstance, hPrevInstance, lpCmdLine, nCmdShow);
+ for (int i = 0; i < argc; i++)
+ free (argv[i]);
+
+ (void)hInstance; (void)hPrevInstance; (void)lpCmdLine; (void)nCmdShow;
+ return ret;
}
-#endif