子进程源代码:
void CProcessChildView::OnMypipeWrite()
{
// TODO: Add your command handler code here
char buf[] = "Hello, I am child process! I love my baby so much!" ;
DWORD dwWrite = 0 ;
if (!WriteFile(m_hWrite, buf, strlen(buf) + 1, & dwWrite, NULL))
{
MessageBox("child process write failed.." );
}
}
void CProcessChildView::OnMypipeRead()
{
// TODO: Add your command handler code here
char buf[100] = "
父进程源代码:
void CProcessParentView::OnPipeCreate()
{
// TODO: Add your command handler code here
SECURITY_ATTRIBUTES sa;
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
sa.nLength = sizeof (SECURITY_ATTRIBUTES);
if (!CreatePipe(&m_hRead, &m_hWrite, &sa, 0 ))
{
MessageBox("Create anymouse pipe failed!" );
return ;
}
STARTUPINFO sui;
PROCESS_INFORMATION pi;
ZeroMemory(&sui, sizeof (STARTUPINFO));
sui.cb = sizeof (STARTUPINFO);
sui.dwFlags = STARTF_USESTDHANDLES;
sui.hStdInput = m_hRead;
sui.hStdOutput = m_hWrite;
sui.hStdError = GetStdHandle(STD_ERROR_HANDLE);
if (!CreateProcess("E:/program/ProcessChild/ProcessChild/Debug/ProcessChild.exe", NULL, NULL, NULL, TRUE, 0, NULL, NULL, &sui, & pi))
{
DWORD dw = GetLastError();
char buf[10] = "