[Bf-blender-cvs] [57c4871] master: Tweaks to the recent wrapper on windows
Sergey Sharybin
noreply at git.blender.org
Thu Aug 7 20:23:18 CEST 2014
Commit: 57c4871146269a34522ad50c43cb55fe773f3bdf
Author: Sergey Sharybin
Date: Fri Aug 8 00:20:43 2014 +0600
Branches: master
https://developer.blender.org/rB57c4871146269a34522ad50c43cb55fe773f3bdf
Tweaks to the recent wrapper on windows
- Forgot to handle command line arguments
- Because of the fact we need to be able to
use stdout and stderr we need to use regular
console application for the wrapper.
- Because of using regular application for the
wrapper we need to check forparent PID in the
isStartedFromCommandPrompt().
I really hope it's not gonna to become any more
complicated.
===================================================================
M intern/ghost/intern/GHOST_SystemWin32.cpp
M source/creator/creator_launch_win.c
===================================================================
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 91ac854..bc2a210 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -46,6 +46,7 @@
#include <shlobj.h>
#include <tlhelp32.h>
+#include <Psapi.h>
#include "utfconv.h"
@@ -1383,6 +1384,30 @@ void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, bool selection) const
}
}
+static DWORD GetParentProcessID(void)
+{
+ HANDLE snapshot;
+ PROCESSENTRY32 pe32 = {0};
+ DWORD ppid = 0, pid = GetCurrentProcessId();
+ snapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
+ if (snapshot == INVALID_HANDLE_VALUE) {
+ return -1;
+ }
+ pe32.dwSize = sizeof( pe32 );
+ if (!Process32First(snapshot, &pe32)) {
+ CloseHandle(snapshot);
+ return -1;
+ }
+ do {
+ if (pe32.th32ProcessID == pid) {
+ ppid = pe32.th32ParentProcessID;
+ break;
+ }
+ } while (Process32Next(snapshot, &pe32));
+ CloseHandle(snapshot);
+ return ppid;
+}
+
static bool isStartedFromCommandPrompt()
{
HWND hwnd = GetConsoleWindow();
@@ -1392,7 +1417,10 @@ static bool isStartedFromCommandPrompt()
GetWindowThreadProcessId(hwnd, &pid);
- if (pid == GetCurrentProcessId())
+ /* Because we're starting from a wrapper we need to comare with
+ * parent process ID.
+ */
+ if (pid == GetParentProcessID())
return true;
}
diff --git a/source/creator/creator_launch_win.c b/source/creator/creator_launch_win.c
index 0f186f6..e998343 100644
--- a/source/creator/creator_launch_win.c
+++ b/source/creator/creator_launch_win.c
@@ -23,8 +23,6 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#pragma comment(linker, "/subsystem:windows")
-
/* Binary name to launch. */
#define BLENDER_BINARY "blender-app.exe"
@@ -33,21 +31,29 @@
#include <stdlib.h>
#include <windows.h>
-int WINAPI WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
+int main(int argc, char **argv)
{
PROCESS_INFORMATION processInformation = {0};
STARTUPINFOA startupInfo = {0};
BOOL result;
+ char command[65536];
+ int i, len = sizeof(command);
_putenv_s("OMP_WAIT_POLICY", "PASSIVE");
startupInfo.cb = sizeof(startupInfo);
- result = CreateProcessA(NULL, BLENDER_BINARY, NULL, NULL, FALSE,
- 0, NULL, NULL,
- &startupInfo, &processInformation);
+
+ strncpy(command, BLENDER_BINARY, len - 1);
+ len -= strlen(BLENDER_BINARY);
+ for (i = 1; i < argc; ++i) {
+ strncat(command, " ", len - 1);
+ strncat(command, argv[i], len - 2);
+ len -= strlen(argv[i]) + 1;
+ }
+
+ result = CreateProcessA(NULL, command, NULL, NULL, TRUE,
+ 0, NULL, NULL,
+ &startupInfo, &processInformation);
if (!result) {
fprintf(stderr, "Error launching " BLENDER_BINARY "\n");
More information about the Bf-blender-cvs
mailing list