| 872 | } |
| 873 | |
| 874 | bool Utils::myCreateProcess(const std::wstring &exePath, const std::wstring &workingDir) |
| 875 | { |
| 876 | STARTUPINFOW si = { sizeof(si) }; |
| 877 | PROCESS_INFORMATION pi = {}; |
| 878 | std::wstring cmdLine = exePath; // CreateProcess 会修改 cmdLine |
| 879 | |
| 880 | BOOL success = CreateProcessW( |
| 881 | nullptr, |
| 882 | &cmdLine[0], // 可写缓冲区 |
| 883 | nullptr, |
| 884 | nullptr, |
| 885 | FALSE, |
| 886 | 0, |
| 887 | nullptr, |
| 888 | workingDir.c_str(), |
| 889 | &si, |
| 890 | &pi |
| 891 | ); |
| 892 | |
| 893 | if (!success) { |
| 894 | DWORD err = GetLastError(); |
| 895 | LPWSTR msgBuf = nullptr; |
| 896 | FormatMessageW( |
| 897 | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 898 | nullptr, |
| 899 | err, |
| 900 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 901 | (LPWSTR)&msgBuf, |
| 902 | 0, |
| 903 | nullptr |
| 904 | ); |
| 905 | |
| 906 | // 这里改用 qWarning 输出 |
| 907 | qWarning().noquote() |
| 908 | << QStringLiteral("CreateProcessW failed with error %1: %2") |
| 909 | .arg(err) |
| 910 | // 注意:msgBuf 是 wchar_t*;我们要转换到 QString |
| 911 | .arg(msgBuf ? QString::fromWCharArray(msgBuf).trimmed() : QStringLiteral("Unknown Error")); |
| 912 | |
| 913 | if (msgBuf) |
| 914 | LocalFree(msgBuf); |
| 915 | |
| 916 | return false; |
| 917 | } |
| 918 | |
| 919 | // 进程成功创建 |
| 920 | CloseHandle(pi.hProcess); |
| 921 | CloseHandle(pi.hThread); |
| 922 | |
| 923 | qDebug().noquote() |
| 924 | << QStringLiteral("CreateProcessW succeeded for: %1").arg(QString::fromWCharArray(exePath.c_str())); |
| 925 | return true; |
| 926 | } |
| 927 | |
| 928 | |
| 929 | std::vector<cv::Point> Utils::getCircleContour(int cx, int cy, int r){ |
nothing calls this directly
no outgoing calls
no test coverage detected