os.args: fix os.args[0] when compiling graphical apps on windows

pull/6248/head
Delyan Angelov 2020-08-28 22:39:52 +03:00
parent 02bece54a6
commit 30fc374fc5
1 changed files with 2 additions and 1 deletions

View File

@ -53,11 +53,12 @@ fn (mut g Gen) gen_c_main_header() {
g.writeln('int main(int ___argc, char** ___argv){') g.writeln('int main(int ___argc, char** ___argv){')
} }
if g.pref.os == .windows && g.is_gui_app() { if g.pref.os == .windows && g.is_gui_app() {
g.writeln('\tLPWSTR full_cmd_line = GetCommandLineW(); // NB: do not use cmd_line')
g.writeln('\ttypedef LPWSTR*(WINAPI *cmd_line_to_argv)(LPCWSTR, int*);') g.writeln('\ttypedef LPWSTR*(WINAPI *cmd_line_to_argv)(LPCWSTR, int*);')
g.writeln('\tHMODULE shell32_module = LoadLibrary(L"shell32.dll");') g.writeln('\tHMODULE shell32_module = LoadLibrary(L"shell32.dll");')
g.writeln('\tcmd_line_to_argv CommandLineToArgvW = (cmd_line_to_argv)GetProcAddress(shell32_module, "CommandLineToArgvW");') g.writeln('\tcmd_line_to_argv CommandLineToArgvW = (cmd_line_to_argv)GetProcAddress(shell32_module, "CommandLineToArgvW");')
g.writeln('\tint ___argc;') g.writeln('\tint ___argc;')
g.writeln('\twchar_t** ___argv = CommandLineToArgvW(cmd_line, &___argc);') g.writeln('\twchar_t** ___argv = CommandLineToArgvW(full_cmd_line, &___argc);')
} }
g.writeln('\t_vinit();') g.writeln('\t_vinit();')
if g.pref.is_prof { if g.pref.is_prof {