diff options
-rw-r--r-- | platform/windows/godot_win.cpp | 107 |
1 files changed, 25 insertions, 82 deletions
diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp index 0e74f63510..81c90d9dd0 100644 --- a/platform/windows/godot_win.cpp +++ b/platform/windows/godot_win.cpp @@ -115,29 +115,24 @@ PCHAR* return argv; } -char* mb_to_utf8(const char* mbs) { - - int wlen = MultiByteToWideChar(CP_ACP,0,mbs,-1,NULL,0); // returns 0 if failed - wchar_t *wbuf = new wchar_t[wlen + 1]; - MultiByteToWideChar(CP_ACP,0,mbs,-1,wbuf,wlen); - wbuf[wlen]=0; - - int ulen = WideCharToMultiByte(CP_UTF8,0,wbuf,-1,NULL,0,NULL,NULL); +char* wc_to_utf8(const wchar_t* wc) { + int ulen = WideCharToMultiByte(CP_UTF8,0,wc,-1,NULL,0,NULL,NULL); char * ubuf = new char[ulen + 1]; - WideCharToMultiByte(CP_UTF8,0,wbuf,-1,ubuf,ulen,NULL,NULL); + WideCharToMultiByte(CP_UTF8,0,wc,-1,ubuf,ulen,NULL,NULL); ubuf[ulen] = 0; return ubuf; } -int main(int argc, char** argv) { +int widechar_main(int argc, wchar_t** argv) { OS_Windows os(NULL); setlocale(LC_CTYPE, ""); char ** argv_utf8 = new char*[argc]; + for(int i=0; i<argc; ++i) { - argv_utf8[i] = mb_to_utf8(argv[i]); + argv_utf8[i] = wc_to_utf8(argv[i]); } Main::setup(argv_utf8[0], argc - 1, &argv_utf8[1]); @@ -154,82 +149,30 @@ int main(int argc, char** argv) { return os.get_exit_code(); }; -HINSTANCE godot_hinstance = NULL; - -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - - int argc; - char** argv; - - char* arg; - int index; - int result; - - // count the arguments - - argc = 1; - arg = lpCmdLine; - - while (arg[0] != 0) { - - while (arg[0] != 0 && arg[0] == ' ') { - arg++; - } - - if (arg[0] != 0) { - - argc++; - - while (arg[0] != 0 && arg[0] != ' ') { - arg++; - } - - } - - } - - // tokenize the arguments - - argv = (char**)malloc(argc * sizeof(char*)); - - arg = lpCmdLine; - index = 1; - - while (arg[0] != 0) { - - while (arg[0] != 0 && arg[0] == ' ') { - arg++; - } - - if (arg[0] != 0) { - - argv[index] = arg; - index++; - - while (arg[0] != 0 && arg[0] != ' ') { - arg++; - } - - if (arg[0] != 0) { - arg[0] = 0; - arg++; - } - - } +int main(int _argc, char** _argv) { + // _argc and _argv are ignored + // we are going to use the WideChar version of them instead - } + LPWSTR *wc_argv; + int argc; + int result; - // put the program name into argv[0] + wc_argv = CommandLineToArgvW(GetCommandLineW(), &argc); - char filename[_MAX_PATH]; + if( NULL == wc_argv ) { + wprintf(L"CommandLineToArgvW failed\n"); + return 0; + } - GetModuleFileName(NULL, filename, _MAX_PATH); - argv[0] = filename; + result = widechar_main(argc, wc_argv); - // call the user specified main function + LocalFree(wc_argv); + return result; +} - result = main(argc, argv); +HINSTANCE godot_hinstance = NULL; - free(argv); - return result; +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { + godot_hinstance = hInstance; + return main(0,NULL); } |