如題.
在MFC程序中, 如何調用DOS程序,並通過調用,得到DOS程序運行的返回.
比如, DOS程序為;
int main ()
{
return 0;
}
調用該程序後,mfc程序得到返回值0.謝謝啦...
在MFC程序中, 如何調用DOS程序,並通過調用,得到DOS程序運行的返回.
比如, DOS程序為;
int main ()
{
return 0;
}
調用該程序後,mfc程序得到返回值0.謝謝啦...
GetExitCodeProcess得到返回值
这是例子 STARTUPINFO si;
PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) ); // Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
"MyChildProcess", // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
ErrorExit( "CreateProcess failed." );
} // Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE ); DWORD dwCode;
GetExitCodeProcess(pi.hProcess, &dwCode);
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
用GetExitCodeProcess获退了码
但是
BOOL CreateProcess(
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags, // 这个参数 传 DEBUG_ONLY_THIS_PROCESS
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);// 然后
DEBUG_EVENT DebugEv; // debugging event information
DWORD dwContinueStatus = DBG_CONTINUE; // exception continuation
for(;;)
{
// Wait for a debugging event to occur. The second parameter indicates
// that the function does not return until a debugging event occurs.
WaitForDebugEvent(&DebugEv, INFINITE);
switch (DebugEv.u.Exception.ExceptionRecord.ExceptionCode)
{
case EXIT_PROCESS_DEBUG_EVENT:
// 这里可以 从 DebugEv 可以得到 exitCode
// 具体请参考 MSDN 有例子。
...