0

I am trying to create a named pipe in vc++. I am used to C and I hope that the error is not just related to me not being familiar with c++. The code I am using is the following:

#ifdef DEBUG
printf("%s\n%s\n", this->pipe_name, this->pipe_path);
#endif
this->pipe = CreateNamedPipe(
    this->pipe_path,
    PIPE_ACCESS_DUPLEX,
    PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT,
    1,
    this->pipe_buffer_size_kb * 1024,
    this->pipe_buffer_size_kb * 1024,
    NMPWAIT_USE_DEFAULT_WAIT,
    NULL);

if (this->pipe != INVALID_HANDLE_VALUE) // Setup successful
    return true;

if (GetLastError() != ERROR_PIPE_BUSY)  // Some unexpected error occured
{
#ifdef DEBUG
    printf("Failed to create named pipe: %d\n", GetLastError());
#endif
    return false;
}

pipe_buffer_size_kb is 8

The output I am getting is the following:

>.\run.exe
p0
\\.\rftb\p0
Failed to create named pipe: 3

As an IDE I use Microsoft Visual Studio Community 2017 (Product details: Microsoft Visual Basic 2017) I've used an empty project template and added DEBUG and _CRT_SECURE_NO_WARNINGS as preprocessor definitions.

Any help is appreciated.

Miistogun
  • 45
  • 5
  • 1
    Reading the docs the name of the pipe may be incorrect. Have a read of: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365150(v=vs.85).aspx The way I read it the pipe name must start with `\\.\pipe\ ` – Richard Critten Dec 09 '17 at 18:38
  • It's working that way. Than you, I thought it was of scheme \\.\pipe_name\instance_name. But I don't get what's considered as an instance then. – Miistogun Dec 09 '17 at 18:43
  • This code needs improvement. I get INVALID_HANDLE_VALUE returned. – eddyq Jan 28 '20 at 21:01
  • My string looks like this: \\\\.\\pipe\\pipe_com1 but I get INVALID_HANDLE_VALUE – eddyq Jan 28 '20 at 21:20

2 Answers2

3

The MSDN docs state:

The unique pipe name. This string must have the following form:

\\.\pipe\pipename

The pipename part of the name can include any character other than a backslash, including numbers and special characters. The entire pipe name string can be up to 256 characters long. Pipe names are not case sensitive.

Your pipe name is invalid because it does not match that pattern.

besc
  • 2,507
  • 13
  • 10
1

Your path is \\.\rftb\p0 but afaik all named pipes in Windows reside under \\.\pipe\. Change yout path to e.g. \\.\pipe\p0 and it will likely work.

Nj0rd
  • 62
  • 1
  • 3