Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8732747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:29:39+00:00 2026-06-13T09:29:39+00:00

I am using windows named pipe example. When I run sample programs to create

  • 0

I am using windows named pipe example. When I run sample programs to create pipe, write something and receive it in client program everything is just fine. When I move client code into dll, which runs in windows service it just won’t receive sent bytes.

Server’s code is as follows:

ThreadParams * params = reinterpret_cast<ThreadParams*>(args);
CString * connectionString = params->connectString;

HANDLE hPipe;
DWORD dwBytesRead;
TCHAR buf[1024];
int len;

hPipe = CreateNamedPipe(PIPE_NAME,  // Name
                        PIPE_ACCESS_OUTBOUND | WRITE_OWNER, // OpenMode
                        PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, // PipeMode
                        2, // MaxInstances
                        1024, // OutBufferSize
                        1024, // InBuffersize
                        2000, // TimeOut
                        NULL); // Security
if (hPipe == INVALID_HANDLE_VALUE)
{
    Globals::WriteLog("Could not create the pipe",1);
    exit(1);
}

Globals::WriteLog("connect...",1);
ConnectNamedPipe(hPipe, NULL);
Globals::WriteLog("...connected",1);

swprintf(buf, connectionString->GetBuffer());
len = wcslen(buf);

if (!WriteFile(hPipe, buf, len*sizeof(TCHAR), &dwBytesRead, NULL))
    Globals::WriteLog("WriteFile failed",1);
else
    wprintf(L"written %d bytes\n",dwBytesRead);

DisconnectNamedPipe(hPipe);

CloseHandle(hPipe);

And client:

    CString finalResult = _T("");

HANDLE      hOut = INVALID_HANDLE_VALUE;
TCHAR       buf[1024];
DWORD       len;
DWORD       dwWritten;

Global::WriteLog("pwrite: waiting for the pipe...",1);
if (WaitNamedPipe(PIPE_NAME, NMPWAIT_WAIT_FOREVER) == 0)
{
    Global::WriteLog("WaitNamedPipe failed. error=%d",1,GetLastError());
    goto cleanup;
}
Global::WriteLog("the pipe is ready",1);

hOut = CreateFile(PIPE_NAME,
    GENERIC_READ,
    0,
    NULL, OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    NULL);
if (hOut == INVALID_HANDLE_VALUE)
{
    Global::WriteLog("CreateFile failed with error %d",1,GetLastError());
    goto cleanup;
}
Global::WriteLog("Opened the pipe",1);

for (;;)
{
    if (!ReadFile(hOut, buf, sizeof(buf), &dwWritten, NULL))
    {
        Global::WriteLog("ReadFile failed -- probably EOF. Read %d bytes.",1,dwWritten);
        goto cleanup;
    }
    else
        break;
}

finalResult = CString(buf);
Global::WriteLog("String from pipe:%S",1,buf);
cleanup:
if(hOut != INVALID_HANDLE_VALUE)
    CloseHandle(hOut);

Server’s code runs in a thread if that changes anything (I’ve tested it with this thread version in sample program and there was no problem with this).

Why does it not work?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:29:40+00:00Added an answer on June 13, 2026 at 9:29 am

    Okay, it seems I figured it out. It seems I didn’t understood documentation properly.

    At server’s side WriteFile function doesn’t block until the string is read. My program simply wrote data and then closed handle – pipe. Client didn’t catch the message and threw error stating that there is no process on the other side of pipe.

    Also from client I removed for(;;) loop.

    To wait for read operation on client side to complete I added

    FlushFileBuffers(hPipe);
    

    after successful write operation.

    Hope that help somebody

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a duplex named pipe using the windows API CreateNamedPipe to
I'm having problems with low performance using a Windows named pipe. The throughput drops
I have created a program that write video stream to a named pipe on
I have a named pipe server similar to the MSDN sample at http://msdn.microsoft.com/en-us/library/windows/desktop/aa365588(v=vs.85).aspx and
I remember using Named Pipes for communicating between 2 machines (back in Windows NT).
Lately I've been favoring using named pipes (option --enable-named-pipes) in MySQL running on windows,
I have an issue trying to perform bulk load using named pipe on SybaseIQ
I am using a named pipe for communications between two processes and want to
I am currently learning about named pipes in Windows using ASP.NET 3.5 and C#.
I have a SQL Server 2005 named instance using Windows Authentication with domain groups

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.