69,382
社区成员
发帖
与我相关
我的任务
分享
HANDLE hRead,hWrite; //管道读、写句柄
SECURITY_ATTRIBUTES sa; //安全描述符
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = TRUE; //创建的进程继承句柄
sa.lpSecurityDescriptor = NULL; //使用系统默认的安全描述符
if( !CreatePipe(&hRead,&hWrite,&sa,0) )
{
printf("创建管道失败\n,错误代码: %d\n", GetLastError()); return ;
}
sa.bInheritHandle = TRUE;
这样句柄才会继承The following sample code illustrates testing for end-of-file for an asynchronous read operation:
// set up overlapped structure fields
// to simplify this sample, we'll eschew an event handle
gOverLapped.Offset = 0;
gOverLapped.OffsetHigh = 0;
gOverLapped.hEvent = NULL;
// attempt an asynchronous read operation
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead,
&gOverlapped) ;
// if there was a problem, or the async. operation's still pending ...
if (!bResult)
{
// deal with the error code
switch (dwError = GetLastError())
{
case ERROR_HANDLE_EOF:
{
// we're reached the end of the file
// during the call to ReadFile
// code to handle that
}
case ERROR_IO_PENDING:
{
// asynchronous i/o is still in progress
// do something else for a while
GoDoSomethingElse() ;
// check on the results of the asynchronous read
bResult = GetOverlappedResult(hFile, &gOverlapped,
&nBytesRead, FALSE) ;
// if there was a problem ...
if (!bResult)
{
// deal with the error code
switch (dwError = GetLastError())
{
case ERROR_HANDLE_EOF:
{
// we're reached the end of the file
//during asynchronous operation
}
// deal with other error cases
}
}
} // end case
// deal with other error cases
} // end switch
} // end if