程序parent.c主要代码:
...
void main()
{...
CreateProcess(NULL,
"son.exe",
&SecAttributes,
&SecAttributes,
TRUE,
CREATE_NO_WINDOW,
NULL,
NULL,
&StartupInfo,
&ProcessInfo);
....}其中son.exe是由son.c文件生成的.
son.c 的代码如下:
void main()
{
int a[2]={10,20};
printf("%d",a[3]);
}.
很明显:son.c中的a[3]是访问数组越界了.
所以上面的parent.exe在调用son.exe时,由于son.exe存在数组访问越界,所以son.exe会弹出一个警告对话框,问你要关闭它还是要重试或者忽略.现在我的问题时,在parent.c中如何通过代码来实现不让son.exe弹出那个可恶的警告,也就是当son.exe存在run time error时parent.exe就强行关闭son.exe,获得son.exe出错的错误描述,而不要让son.exe弹出那个可恶的警告对话框.
...
void main()
{...
CreateProcess(NULL,
"son.exe",
&SecAttributes,
&SecAttributes,
TRUE,
CREATE_NO_WINDOW,
NULL,
NULL,
&StartupInfo,
&ProcessInfo);
....}其中son.exe是由son.c文件生成的.
son.c 的代码如下:
void main()
{
int a[2]={10,20};
printf("%d",a[3]);
}.
很明显:son.c中的a[3]是访问数组越界了.
所以上面的parent.exe在调用son.exe时,由于son.exe存在数组访问越界,所以son.exe会弹出一个警告对话框,问你要关闭它还是要重试或者忽略.现在我的问题时,在parent.c中如何通过代码来实现不让son.exe弹出那个可恶的警告,也就是当son.exe存在run time error时parent.exe就强行关闭son.exe,获得son.exe出错的错误描述,而不要让son.exe弹出那个可恶的警告对话框.
UINT uMode // process error mode
);Each process has an associated error mode that indicates to the system how the application is going to respond to serious errors. A child process inherits the error mode of its parent process.用这个在Parent.c里设置一下,然后son.c会基层Parent的设置
但是son.exe还是会弹出警告框啊,救命啊
LPCTSTR lpApplicationName, // name of executable module
LPTSTR lpCommandLine, // command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
BOOL bInheritHandles, // handle inheritance option
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // new environment block
LPCTSTR lpCurrentDirectory, // current directory name
LPSTARTUPINFO lpStartupInfo, // startup information
LPPROCESS_INFORMATION lpProcessInformation // process information
);那个BOOL bInheritHandles要True
但就是得不到效果
{
STARTUPINFO si = {sizeof(si)};
PROCESS_INFORMATION pi;
BOOL b = CreateProcess(NULL,
"a.exe",
NULL,
NULL,
TRUE,
DEBUG_PROCESS,
NULL,
NULL,
&si,
&pi); DEBUG_EVENT dbg = {0};
while (WaitForDebugEvent(&dbg, INFINITE)) {
if (dbg.dwDebugEventCode == EXCEPTION_DEBUG_EVENT) {
if (dbg.u.Exception.ExceptionRecord.ExceptionCode
== EXCEPTION_ACCESS_VIOLATION) {
MessageBox(NULL, "EXCEPTION_ACCESS_VIOLATION", NULL, MB_OK);
TerminateProcess(pi.hProcess, 0);
break;
}
}
else if (dbg.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) {
MessageBox(NULL, "EXIT_PROCESS_DEBUG_EVENT", NULL, MB_OK);
break;
}
b = ContinueDebugEvent(dbg.dwProcessId, dbg.dwThreadId, DBG_CONTINUE);
} CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}/*
//a.exe
void main()
{
int *p = NULL;
*p = 0;
}
*/