-1

I want to implement a "named pipe" for exchanging double arrays between a C# and a Python process does anyone know about that?

I find some code but I can't understand

1 Answers1

-2
[DllImport("kernel32.dll")]
static extern unsafe int CreateNamedPipe(
    string lpName, uint dwOpenMode, uint dwPipeMode,
    uint nMaxInstances, int nOutBufferSize,
    int nInBufferSize, int nDefaultTimeOut,
    ref SECURITY_ATTRIBUTES lpSecurityAttributes
    );

[DllImport("kernel32.dll")]
static extern unsafe int ConnectNamedPipe(
    int hNamedPipe,
    ref OVERLAPPED lpOverlapped
    );

[DllImport("kernel32.dll")]
static extern unsafe int DisconnectNamedPipe(
    int hNamedPipe
    );

[DllImport("kernel32.dll")]
static extern unsafe int WriteFile(
    int hFile, void* lpBuffer,
    int nNumberOfBytesToWrite,
    int* lpNumberOfBytesWritten,
    ref OVERLAPPED lpOverlapped
    );

[DllImport("kernel32.dll")]
static extern unsafe int ReadFile(
    int hFile, void* lpBuffer,
    int nNumberOfBytesToRead,
    int* lpNumberOfBytesRead,
    ref OVERLAPPED lpOverlapped
    );

[DllImport("kernel32.dll")]
static extern unsafe int CloseHandle(
    int hObject
    );

A:

This method is for communicating with a separate process using a Windows named pipe. If you want to communicate between two threads in the same process (or between two processes on the same machine), you would use a MemoryMappedFile or P/Invoke CreateFileMapping and MapViewOfFile.

Michael Ruth
  • 2,938
  • 1
  • 20
  • 27
  • There's a whole namespace `System.IO.Pipes` that deals with named pipes in the .net framework, so there's no need to use p/invoke from C# for that purpose – NineBerry Dec 06 '22 at 17:55