- if (parameters != "") {
- ptr_parameters = parameters.c_str();
- }
-
- /** users may start by short name in commandline without extention **/
- std::string appname = argv[0];
- if (appname.substr(appname.length() -4) != ".exe") {
- appname += ".exe";
- }
+ // Allow calling without an extension
+ std::string app_name = argv[0];
+ if (app_name.compare(app_name.size() - 4, 4, ".exe") != 0)
+ app_name += ".exe";
+
+ STARTUPINFO startup_info = {};
+ PROCESS_INFORMATION process_info = {};
+
+ bool success = CreateProcess(app_name.c_str(), ptr_parameters,
+ NULL, NULL, false, DETACHED_PROCESS | CREATE_UNICODE_ENVIRONMENT,
+ NULL, NULL, &startup_info, &process_info);
+
+ if (success) {
+ exit(0);
+ // NOTREACHED
+ } else {
+ char buffer[1024];
+
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
+ MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), buffer,
+ sizeof(buffer) - 1, NULL);