Link to home
Start Free TrialLog in
Avatar of deatc
deatc

asked on

CreateFile() Call Fails for Named Pipe

Hi. I have a server application that creates a named pipe using the following call:
    CreateNamedPipe( "\\\\.\\pipe\\MyPipe"                           ,
                     (PIPE_ACCESS_DUPLEX | WRITE_DAC)                ,
                     (PIPE_TYPE_BYTE | PIPE_READMODE_BYTE PIPE_WAIT) ,
                     10                                              ,
                     1024                                            ,
                     1024                                            ,
                     0                                               ,
                     0                                               );

Open in new window

and a client application that does the following twice:
    WaitNamedPipe( "\\\\.\\pipe\\MyPipe" ,
                     NMPWAIT_WAIT_FOREVER );
    hOut = CreateFile( "\\\\.\\pipe\\MyPipe" ,
                       GENERIC_WRITE         ,
                       0                     ,
                       NULL                  ,
                       OPEN_EXISTING         ,
                       FILE_ATTRIBUTE_NORMAL ,
                       NULL                  );
    WriteFile(  hOut           ,
                "Hello"        ,
                5              ,
               &dwBytesWritten ,
                NULL           ) );
    CloseHandle(hOut);

Open in new window

Everything works great the first time, but the second time, the CreateFile() client call never returns.  Do you have any idea what the problem could be?  Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deatc
deatc

ASKER

Thank you, Zoppo and Sara!