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 1053617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:16:49+00:00 2026-05-16T17:16:49+00:00

This post is related to my Previous Post . There I was creating the

  • 0

This post is related to my Previous Post. There I was creating the PipeServer and Client as two separate programme and was trying to write to the server and getting a response back.And the programme was going to an infinite loop.

So for the sake of simplicity I combined both the Client and Server into a Single programme and run. Now I am getting System Error Code 997 i.e: Overlapped I/O operation is in progress. Tried out different parameter options , unable to figure out the main reason. Any Idea how to go with this Error Code.

The Code snippet is below:

#include "stdafx.h"
//#include "WindowService.h"
#include "iostream"
#include "fstream"
using namespace std;

#define BUFSIZE 512

SERVICE_STATUS m_ServiceStatus;
SERVICE_STATUS_HANDLE m_ServiceStatusHandle;
BOOL bRunning=true;

void WINAPI ServiceMain(DWORD argc, LPTSTR *argv);
void WINAPI ServiceCtrlHandler(DWORD Opcode);

BOOL InstallService();
BOOL DeleteService();

cWindowsService m_WindowsService;

int main()
{

    HANDLE hPipe;
    LPTSTR lpszPipename;

        LPTSTR lpszWrite = TEXT("Default message from client"); 

            TCHAR chReadBuf[BUFSIZE]; 


     lpszPipename = TEXT("\\\\.\\pipe\\1stPipe"); 

     BOOL fSuccess;
     DWORD cbRead, dwMode; 

     OVERLAPPED m_OverLaped;
     HANDLE hEvent;
     HANDLE hPipeC;
     //HANDLE hPipe;

     hPipe=CreateNamedPipe(
                            lpszPipename,PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
                                         PIPE_TYPE_MESSAGE     | PIPE_READMODE_MESSAGE | PIPE_NOWAIT,
                                         PIPE_UNLIMITED_INSTANCES,BUFSIZE,
                                         BUFSIZE,0,NULL
                         );


    //hEvent=CreateEvent(NULL,TRUE,TRUE,NULL);

    m_OverLaped.hEvent=CreateEvent(NULL,TRUE,TRUE,NULL);
    m_OverLaped.Internal=0;
    m_OverLaped.InternalHigh=0;
    m_OverLaped.Offset=0;
    m_OverLaped.OffsetHigh=0;


    if (hPipe != INVALID_HANDLE_VALUE) 

      if (GetLastError() != ERROR_PIPE_BUSY) 
      {
          if(GetLastError()==0)
          {
              printf("Successfully Created  %s\n",lpszPipename);
          }
          else
         printf( TEXT("Can not Create NamedPipe\n[GLE=%d]\n"), GetLastError() ); 
         //return -1;
      }



      ConnectNamedPipe(hPipe,&m_OverLaped);

        hPipeC=CreateFile(
                                         lpszPipename,             //Gets the Pipename
                                         GENERIC_READ | GENERIC_WRITE,           //Client only writes to this pipe.
                                         0,                       //Do not share this pipe with others.
                                         NULL,                    //Do not inherit security.
                                         OPEN_EXISTING,           //Pipe must exist.
                                         FILE_ATTRIBUTE_NORMAL,   //I have no special requirements on 
                                                                  //file attributes
                                         NULL
                                         ); 


        dwMode = PIPE_READMODE_MESSAGE; 

       fSuccess = SetNamedPipeHandleState( 
                                          hPipe,    // pipe handle 
                                          &dwMode,  // new pipe mode 
                                          NULL,     // don't set maximum bytes 
                                          NULL
                                         );    // don't set maximum time 




        fSuccess = TransactNamedPipe( 
                                              hPipe,                  // pipe handle 
                                              lpszWrite,              // message to server
                                              (lstrlen(lpszWrite)+1)*sizeof(TCHAR), // message length 
                                              chReadBuf,              // buffer to receive reply
                                              BUFSIZE*sizeof(TCHAR),  // size of read buffer
                                              &cbRead,                // bytes read
                                              &m_OverLaped
                                          );   

         printf("GLE=%d.\n",GetLastError()); 

     if (!fSuccess && (GetLastError() != ERROR_MORE_DATA)) 
       {
          printf("TransactNamedPipe failed with GLE=%d.\n",GetLastError()); 
          return 0;
       }


     while(1)
       { 
          printf(TEXT("%s\n"), chReadBuf);

          // Break if TransactNamedPipe or ReadFile is successful
          if(fSuccess)
             break;

          DWORD nBytesTransfered=1000;
          DWORD *lpBytesTransfered;
          lpBytesTransfered=&nBytesTransfered;

          WaitForSingleObject( m_OverLaped.hEvent,15000);
          GetOverlappedResult(hPipe,&m_OverLaped,lpBytesTransfered,true);
          // Read from the pipe if there is more data in the message.
          fSuccess = ReadFile( 
             hPipe,      // pipe handle 
             chReadBuf,  // buffer to receive reply 
             BUFSIZE*sizeof(TCHAR),  // size of buffer 
             &cbRead,  // number of bytes read 
             &m_OverLaped);    // not overlapped 

          // Exit if an error other than ERROR_MORE_DATA occurs.
          if( !fSuccess && (GetLastError() != ERROR_MORE_DATA)) 
             break;
          else printf( TEXT("%s\n"), chReadBuf); 
       }



}
  • 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-05-16T17:16:50+00:00Added an answer on May 16, 2026 at 5:16 pm

    MSDN has an example that does just what you’re trying to do, I suggest you check it out: Named Pipe Server and Named Pipe Client (added from comment).

    Another suggestion is that you try first without using overlapped IO as it complicates matters a bit and then once you get it working without overlapped IO you can introduce it again.

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

Sidebar

Related Questions

This is beyond both making sense and my control. That being said here is
There doesn't seem to be any tried and true set of best practices to
I have found this example on StackOverflow: var people = new List<Person> { new
I want to use a temp directory that will be unique to this build.
I'm trying to build a C++ extension for python using swig. I've followed the
I have a new web app that is packaged as a WAR as part
(please excuse that I didn't use aliases). I would like my query output to
Let say I have the following desire, to simplify the IConvertible's to allow me
I have a login.jsp page which contains a login form. Once logged in the
I need to develop a file indexing application in python and wanted to know

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.