| 13 | } |
| 14 | |
| 15 | HRESULT ExecEx(LPSHELLEXECUTEINFO execInfo, BOOL wait, LPDWORD exitCode) { |
| 16 | if (wait) { |
| 17 | execInfo->fMask |= SEE_MASK_NOCLOSEPROCESS; |
| 18 | } |
| 19 | |
| 20 | if (!ShellExecuteEx(execInfo)) { |
| 21 | return HRESULT_FROM_WIN32(GetLastError()); |
| 22 | } |
| 23 | |
| 24 | HRESULT hr = S_OK; |
| 25 | |
| 26 | if (wait) { |
| 27 | if (execInfo->hProcess == NULL) { |
| 28 | hr = HRESULT_FROM_WIN32(GetLastError()); |
| 29 | CHECK_HR(L"ShellExecuteEx didn't return a handle"); |
| 30 | hr = E_FAIL; |
| 31 | } |
| 32 | |
| 33 | WaitForSingleObject(execInfo->hProcess, INFINITE); |
| 34 | |
| 35 | if (exitCode != NULL && GetExitCodeProcess(execInfo->hProcess, exitCode) == 0) { |
| 36 | hr = HRESULT_FROM_WIN32(GetLastError()); |
| 37 | CHECK_HR(L"GetExitCodeProcess failed"); |
| 38 | } |
| 39 | |
| 40 | CloseHandle(execInfo->hProcess); |
| 41 | } else if (exitCode != NULL) { |
| 42 | *exitCode = 0; |
| 43 | } |
| 44 | |
| 45 | return hr; |
| 46 | } |
no outgoing calls
no test coverage detected