note : GetExitCodeProcess
发布日期:2021-06-30 22:04:15 浏览次数:2 分类:技术文章

本文共 1822 字,大约阅读时间需要 6 分钟。

// ExitCodeRecv.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include 
#include
/** 有个安装程序,安装结束(安装成功,安装失败)后, 会写一个.ini文件 可以从中读安装结果值. 对于非定制程序, 可以读取程序的退出码. 效果应该是一样的 而且读取程序退出码,比读取安装程序的ini输出文件要简洁.*/int _tmain(int argc, _TCHAR* argv[]){ BOOL bRc = FALSE; STARTUPINFO si; PROCESS_INFORMATION pi; WCHAR cCmdLine[MAX_PATH]; DWORD dwExitCode = 0; ::ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); ::ZeroMemory(&pi, sizeof(PPROCESS_INFORMATION)); ::ZeroMemory(cCmdLine, sizeof(cCmdLine)); wcscpy_s(cCmdLine, L"D:\\LsWorkDir\\Demo\\testExitCode\\subProg\\bin\\ExitCodeSend.exe"); bRc = ::CreateProcessW( NULL, cCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); if (!bRc) { _tprintf(L"Error CreateProcessW \r\n"); goto _tmain_END; } WaitForSingleObject(pi.hProcess, INFINITE); bRc = GetExitCodeProcess(pi.hProcess, &dwExitCode); if (!bRc) { _tprintf(L"Error CreateProcessW \r\n"); goto _tmain_END; } _tprintf(L"subProg dwExitCode = 0x%X\r\n", dwExitCode);_tmain_END: if (NULL != pi.hProcess) CloseHandle(pi.hProcess); if (NULL != pi.hThread) CloseHandle(pi.hThread); getwchar(); return 0;}
// ExitCodeSend.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include 
#include
#include
int _tmain(int argc, _TCHAR* argv[]){ int iRc = 0; srand((UINT)time(NULL)); iRc = rand(); _tprintf(L"return code = 0x%X\r\n", iRc); getwchar(); return iRc;}

测试程序的输出都打到调用者UI上了.

return code = 0x6980subProg dwExitCode = 0x6980

转载地址:https://lostspeed.blog.csdn.net/article/details/15804833 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:demo : 用宏简化大型switch/case - LoadStringW
下一篇:note : test Mutex

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月29日 17时46分43秒