OSX: make some more symbols global only, this may prevent clashes on older systems...
[blender.git] / source / creator / creator_launch_win.c
index 0f186f643dbf035453d168bac6ff8e21e0044bc7..a7e04b2dafc6a955de44479d02dd43c0d2f63110 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
-#pragma comment(linker, "/subsystem:windows")
-
 /* Binary name to launch. */
-#define BLENDER_BINARY "blender-app.exe"
+#define BLENDER_BINARY L"blender-app.exe"
 
 #define WIN32_LEAN_AND_MEAN
 #include <stdio.h>
 #include <stdlib.h>
+
 #include <windows.h>
+#include <Shellapi.h>
+
+#include "utfconv.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_winstuff.h"
+
+static void local_hacks_do(void)
+{
+       _putenv_s("OMP_WAIT_POLICY", "PASSIVE");
+}
 
-int WINAPI WinMain(HINSTANCE hInstance,
-                   HINSTANCE hPrevInstance,
-                   LPSTR lpCmdLine,
-                   int nCmdShow)
+int main(int argc, const char **UNUSED(argv_c))
 {
        PROCESS_INFORMATION processInformation = {0};
-       STARTUPINFOA startupInfo = {0};
+       STARTUPINFOW startupInfo = {0};
        BOOL result;
+       wchar_t command[65536];
+       int i, len = sizeof(command) / sizeof(wchar_t);
+       wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc);
+       int argci = 0;
 
-       _putenv_s("OMP_WAIT_POLICY", "PASSIVE");
+       local_hacks_do();
+
+       wcsncpy(command, BLENDER_BINARY, len - 1);
+       len -= wcslen(BLENDER_BINARY);
+       for (i = 1; i < argc; ++i) {
+               wcsncat(command, L" \"", len - 2);
+               wcsncat(command, argv_16[i], len - 3);
+               len -= wcslen(argv_16[i]) + 1;
+               wcsncat(command, L"\"", len - 1);
+       }
+
+       LocalFree(argv_16);
 
        startupInfo.cb = sizeof(startupInfo);
-       result = CreateProcessA(NULL, BLENDER_BINARY, NULL, NULL, FALSE,
-                              0, NULL, NULL,
-                              &startupInfo, &processInformation);
+       result = CreateProcessW(NULL, command, NULL, NULL, TRUE,
+                               0, NULL, NULL,
+                               &startupInfo, &processInformation);
 
        if (!result) {
-               fprintf(stderr, "Error launching " BLENDER_BINARY "\n");
+               fprintf(stderr, "%S\n", L"Error launching " BLENDER_BINARY);
                return EXIT_FAILURE;
        }