Skip to content

Commit

Permalink
win32: remove -municode from mpv binary
Browse files Browse the repository at this point in the history
If this is used, the runtime expects that wmain() instead of main() is
defined. This caused me severe problems in a certain now irrelevant
case. I think it's a good idea to avoid this special case.

We can just use main() and call GetCommandLineW() instead. This function
returns a single string, so use CommandLineToArgvW() to split it, and
hope it has the same semantics. Should this ever return NULL, hope that
it leaves argc at 0.

Untested, I think.
  • Loading branch information
wm4 committed Sep 19, 2019
1 parent 3e22ed4 commit 943fc88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions osdep/main-fn-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
#include "osdep/terminal.h"
#include "osdep/main-fn.h"

int wmain(int argc, wchar_t *argv[]);

// mpv does its own wildcard expansion in the option parser
int _dowildcard = 0;

static bool is_valid_handle(HANDLE h)
{
return h != INVALID_HANDLE_VALUE && h != NULL &&
Expand Down Expand Up @@ -48,7 +43,7 @@ static void microsoft_nonsense(void)
pSetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE);
}

int wmain(int argc, wchar_t *argv[])
int main(int argc_, char **argv_)
{
microsoft_nonsense();

Expand All @@ -61,11 +56,14 @@ int wmain(int argc, wchar_t *argv[])
// is expecting mpv to show some UI, so enable the pseudo-GUI profile.
bool gui = !has_console && !has_redirected_stdio();

int argc = 0;
wchar_t **argv = CommandLineToArgvW(GetCommandLineW(), &argc);

int argv_len = 0;
char **argv_u8 = NULL;

// Build mpv's UTF-8 argv, and add the pseudo-GUI profile if necessary
if (argv[0])
if (argc > 0 && argv[0])
MP_TARRAY_APPEND(NULL, argv_u8, argv_len, mp_to_utf8(argv_u8, argv[0]));
if (gui) {
MP_TARRAY_APPEND(NULL, argv_u8, argv_len,
Expand Down
4 changes: 2 additions & 2 deletions waftools/detections/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def __add_mswin_flags__(ctx):

def __add_mingw_flags__(ctx):
__add_mswin_flags__(ctx)
ctx.env.CFLAGS += ['-municode', '-D__USE_MINGW_ANSI_STDIO=1']
ctx.env.LAST_LINKFLAGS += ['-municode', '-mwindows']
ctx.env.CFLAGS += ['-D__USE_MINGW_ANSI_STDIO=1']
ctx.env.LAST_LINKFLAGS += ['-mwindows']

def __add_cygwin_flags__(ctx):
__add_mswin_flags__(ctx)
Expand Down

0 comments on commit 943fc88

Please sign in to comment.