Q:

WriteFile function "freezes"

I'm trying rewrite xCmd which can start a process on a remote machine. Basically it installs itself as a service on the target computer and then starts the requested process. Everything is working fine, but i noticed an error. xCmd is communicating through pipes, and it uses WriteFile(). My problem is, that if i run my API (or the originally, both produce this error), then for the first time it will start the requested process, but if i start it one more time, then it will "freeze out" at this line:  
WriteFile( hCommandPipe, &msg, sizeof(msg), &dwTemp, NULL );

WriteFile didn't returns any errorcode, the program just stops here. I can't even close cmd window. I can only close this, when i close on the target computer the service.
Can anyone help me to solve this? It's really annoying and i have no idea :(
Here is the function which isn't working properly:  
 BOOL ExecuteRemoteCommand()
 {
 DWORD dwTemp = 0;
 xCmdMessage msg;
 xCmdResponse response;

 ::ZeroMemory( &msg, sizeof(msg) );
 ::ZeroMemory( &response, sizeof(response) );

 FillMessage( &msg );

 // Send message to service
 WriteFile( hCommandPipe, &msg, sizeof(msg), &dwTemp, NULL );

 // Connects to remote pipes (stdout, stdin, stderr)
 if ( ConnectToRemotePipes( 5, 1000 ) )
 {
   StdOutput( _T("Ok\n\n") );

    // Waiting for response from service
    ReadFile( hCommandPipe, &response, sizeof(response), &dwTemp, NULL );
 }
 else
    StdOutput( _T("Failed\n\n") );

 if ( response.dwErrorCode == 0 ) 
    _tprintf( _T("\nRemote command returned %d(0x%X)\n"), 
              response.dwReturnCode, 
              response.dwReturnCode );
 else
    _tprintf( _T("\nRemote command failed to start. Returned error code is %d(0x%X)\n"), 
              response.dwErrorCode, 
              response.dwErrorCode );

 return TRUE;
}

Thanks in advance!
kampi

A:

I think that means that the other end of the pipe connection is not reading data out of the pipe and the pipe buffer is full.
It may also indicate that the other end has closed their pipe handle.  For anonymous pipes that would cause an error when you try to write, but I don't remember if that's also true with named pipes.

If the pipe buffer is full when an application uses the WriteFile function to write to a pipe, the write operation may not finish immediately. The write operation will be completed when a read operation (using the ReadFile function) makes more system buffer space available for the pipe.
MSDN
The write operation will block until the data is read from the pipe so that the additional buffer quota can be released.
MSDN

