[Python-au] Q: win32pipe.SetNamedPipeHandleState() throws ERROR_INVALID_PARAMETER!?!

replytodirk at web.de replytodirk at web.de
Thu May 12 22:35:19 CEST 2005


Hi all.

I want to setup a message-mode named pipe between two processes. Following
the examples from the Win32 SDK I use the following code:


SERVER

----schnipp-----
from win32pipe import *
from win32file import *
from win32event import *
import pywintypes

PipeHandle = CreateNamedPipe("\\\\.\\pipe\\foobar",
    PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
    PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
    PIPE_UNLIMITED_INSTANCES, 2048, 2048, 5000, None)
Overlapped = pywintypes.OVERLAPPED()
Overlapped.hEvent = CreateEvent(None, 1, 0, None)
ConnectNamedPipe(PipeHandle, Overlapped)
WaitForSingleObject(Overlapped.hEvent, 600000)
Sleep(5000)
----schnapp----
The server will wait 10 minutes for the client to connect.


CLIENT

----schnipp-----
from win32pipe import *
from win32file import *
from win32event import *
import pywintypes

PipeHandle = CreateFile("\\\\.\\pipe\\foobar",
                    GENERIC_READ | GENERIC_WRITE,
                    0, None, OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 0)
SetNamedPipeHandleState(PipeHandle, PIPE_READMODE_MESSAGE, 0, 0)
----schnapp----
The client connects with CreateFile() just fine but then always throws:
> Traceback (most recent call last):
>   File "<pyshell#9>", line 1, in -toplevel-
>     SetNamedPipeHandleState(PipeHandle, PIPE_READMODE_BYTE, 0, 0)
> error: (87, 'SetNamedPipeHandleState', 'The parameter is incorrect.')

What gives?

Does anybody know how to properly setup a message-mode pipe? What am I doing
wrong? I already tried hard to get this running but it seems that I'm stuck
now :-(

Thank you very much for your time!
Dirk




More information about the python-au mailing list