diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-08-07 22:20:43 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-08-07 22:22:57 +0400 |
commit | 57c4871146269a34522ad50c43cb55fe773f3bdf (patch) | |
tree | 92c909a5b7a696bdda21c5b969671ef477ecacc3 /intern | |
parent | a108532eb93d96a2c8dea7e21533d953d0eee2c3 (diff) |
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.
Diffstat (limited to 'intern')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemWin32.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index 91ac8545018..bc2a210fb1e 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; } |