Search code examples
c#c++.netipcnamed-pipes

Out of order windows pipes


Currently working with pipes to communicate between processes, one in C++ and the other a C# .NET application. My .NET application is sending a long user-inputted lua script via pipes to my C++ application. However when sending, my script is all out of order. Chunks of the script are in separate locations. This is strange as I read the whole script with 1 ReadFile call.

My C# side:

private void button1_Click(object sender, EventArgs e)
{
    if (!connected)
        return;
    using (var pipe = new NamedPipeClientStream(".", "TestPipe", PipeDirection.Out))
    using (var stream = new StreamWriter(pipe)) 
    { 
        pipe.Connect();
        stream.Write(TextBox.Text);
        pipe.Flush();
    }
}

I won’t give my whole C++ code of me reading from the pipe but here is me defining the pipe:

HANDLE Pipe = CreateNamedPipe("\\\\.\\pipe\\TestPipe",
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE |PIPE_READMODE_MESSAGE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
999999,
999999,
NMPWAIT_USE_DEFAULT_WAIT,
NULL);

Am I missing something obvious that is causing writes to my pipe to become semi corrupted?

Any help would be appreciated thanks so much!


Solution

  • PAGE_READMODE_BYTE fixed my issue.