I am working on a C# project that uses NamedPipes for interprocess communication to exchange data between the main app and a Windows service. Creating and working with the pipe was implemented with native C functions:
Server
public const uint PIPE_ACCESS_DUPLEX = 0x00000003;
public const uint FILE_FLAG_OVERLAPPED = 0x40000000;
public const uint PIPE_WAIT = 0x00000000;
public const uint PIPE_READMODE_MESSAGE = 0x00000002;
public const uint PIPE_TYPE_MESSAGE = 0x00000004;
public const uint PIPE_UNLIMITED_INSTANCES = 255;
public const uint NMPWAIT_WAIT_FOREVER = 0xffffffff;
public const uint GENERIC_READ = (0x80000000);
public const uint GENERIC_WRITE = (0x40000000);
public const uint OPEN_EXISTING = 3;
public const uint WAIT_OBJECT_0 = 0x00000000;
public const uint ERROR_BROKEN_PIPE = 109;
public const uint ERROR_MORE_DATA = 234;
public const uint ERROR_PIPE_CONNECTED = 535;
public const uint ERROR_IO_PENDING = 997;
public const Int32 INVALID_HANDLE_VALUE = -1;
public const uint OUTPUT_BUFFER_SIZE_IN_BYTES = 32000;
public const uint INPUT_BUFFER_SIZE_IN_BYTES = 32000;
public const Int32 MAX_MESSAGE_SIZE_IN_BYTES = 1000000;
base.handle = CreateNamedPipe(@"\\.\pipe\" + name,
NamedPipe.PIPE_ACCESS_DUPLEX | NamedPipe.FILE_FLAG_OVERLAPPED,
NamedPipe.PIPE_TYPE_MESSAGE | NamedPipe.PIPE_READMODE_MESSAGE | NamedPipe.PIPE_WAIT,
NamedPipe.PIPE_UNLIMITED_INSTANCES,
NamedPipe.OUTPUT_BUFFER_SIZE_IN_BYTES,
NamedPipe.INPUT_BUFFER_SIZE_IN_BYTES,
NamedPipe.NMPWAIT_WAIT_FOREVER,
secAttr);
Client
base.handle = CreateFile(@"\\.\pipe\" + name, NamedPipe.GENERIC_READ | NamedPipe.GENERIC_WRITE, 0, null, NamedPipe.OPEN_EXISTING, 0, 0);
The main app and the windows service are currently working fine with 32bit build. However, for some reason this won't work with 64bit build. When client is trying to read from the pipe, the GetLastError always throws error = 6.
"ERROR: Invalid Handle Specified" ' error 6 = invalid handle
[DllImport("kernel32.dll", SetLastError = true)]
public static extern uint GetLastError();
Does anyone have an idea why this is not working with 64bit? I suspected that this could have something to do with the "kernel32.dll", but according to the Windows documentation, this will automatically routed to the correct 64bit dll.