hPipe = CreateNamedPipe(
lpszPipename, // pipe name
PIPE_ACCESS_DUPLEX, // read/write access
PIPE_TYPE_MESSAGE | // message type pipe
PIPE_READMODE_MESSAGE | // message-read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // max. instances
100, // output buffer size
100, // input buffer size
0, // client time-out
NULL); // default security attribute
DWORD totalBytesAvailable;
PeekNamedPipe(
hPipe , // __in HANDLE hNamedPipe,
NULL, // __out_opt LPVOID lpBuffer,
0, // __in DWORD nBufferSize,
NULL, // __out_opt LPDWORD lpBytesRead,
&totalBytesAvailable, // __out_opt LPDWORD lpTotalBytesAvail,
NULL // __out_opt LPDWORD lpBytesLeftThisMessage
);
if(totalBytesAvailable allows)
WriteFile(tmp_pipe, pBuffer, BufferLen, &dwWritten, NULL);
正如你看到我用PeekNamedPipe
来获得可用空间,但事实证明,totalBytesAvailable
总是0
,如何正确地做到这一点?如何检查窗口中c在WriteFile之前是否有足够的空间?
修复了复制粘贴问题。 – Alan 2010-09-11 06:51:29
@Frerich - 当然,我在SO上度过的时光。它知道这对艾伦没有任何价值,但我当然在乎。考虑到它的价格,懒惰的答案是愚蠢的。 – 2010-09-15 13:43:58
我想你写信给'hPipe',而不是一些未知的'tmp_pipe'? – pascal 2010-09-21 01:47:54