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