/* Start the bundled GUI Python with paths relative to the executable. */ #define WIN32_LEAN_AND_MEAN #include #include int WINAPI wWinMain(HINSTANCE instance, HINSTANCE previous, PWSTR args, int show) { (void)instance; (void)previous; (void)show; const int limit = 32768; wchar_t *folder = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, limit * sizeof(wchar_t)); wchar_t *python = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, limit * sizeof(wchar_t)); wchar_t *command = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, limit * sizeof(wchar_t)); DWORD code = 1; const wchar_t *message = L"Extract the entire ZIP before opening the program."; if (!folder || !python || !command) goto done; DWORD length = GetModuleFileNameW(NULL, folder, limit); if (!length || length >= (DWORD)limit) goto done; wchar_t *separator = wcsrchr(folder, L'\\'); if (!separator) goto done; *separator = 0; if (swprintf(python, limit, L"%ls\\runtime\\pythonw.exe", folder) < 0 || swprintf(command, limit, L"\"%ls\" -E -s -B \"%ls\\source\\main.py\" %ls", python, folder, args) < 0) goto done; STARTUPINFOW startup = {0}; PROCESS_INFORMATION process = {0}; startup.cb = sizeof(startup); if (!CreateProcessW(python, command, NULL, NULL, FALSE, 0, NULL, folder, &startup, &process)) goto done; WaitForSingleObject(process.hProcess, INFINITE); GetExitCodeProcess(process.hProcess, &code); CloseHandle(process.hThread); CloseHandle(process.hProcess); message = L"The program stopped. Open StepShellConsole.cmd for details."; done: if (code) MessageBoxW(NULL, message, L"STEP Exterior Shell", MB_OK | MB_ICONERROR); if (folder) HeapFree(GetProcessHeap(), 0, folder); if (python) HeapFree(GetProcessHeap(), 0, python); if (command) HeapFree(GetProcessHeap(), 0, command); return (int)code; }