Add blender launcher application when building with MSVC
[blender.git] / source / creator / creator_launch_win.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2014 by Blender Foundation.
19  * All rights reserved.
20  *
21  * Contributor(s): Sergey Sharybin.
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 #pragma comment(linker, "/subsystem:windows")
27
28 /* Binary name to launch. */
29 #define BLENDER_BINARY "blender-app.exe"
30
31 #define WIN32_LEAN_AND_MEAN
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <windows.h>
35
36 int WINAPI WinMain(HINSTANCE hInstance,
37                    HINSTANCE hPrevInstance,
38                    LPSTR lpCmdLine,
39                    int nCmdShow)
40 {
41         PROCESS_INFORMATION processInformation = {0};
42         STARTUPINFOA startupInfo = {0};
43         BOOL result;
44
45         _putenv_s("OMP_WAIT_POLICY", "PASSIVE");
46
47         startupInfo.cb = sizeof(startupInfo);
48         result = CreateProcessA(NULL, BLENDER_BINARY, NULL, NULL, FALSE,
49                                0, NULL, NULL,
50                                &startupInfo, &processInformation);
51
52         if (!result) {
53                 fprintf(stderr, "Error launching " BLENDER_BINARY "\n");
54                 return EXIT_FAILURE;
55         }
56
57         WaitForSingleObject(processInformation.hProcess, INFINITE);
58
59         CloseHandle(processInformation.hProcess);
60         CloseHandle(processInformation.hThread);
61
62         return EXIT_SUCCESS;
63 }