Re: Is this OK?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"William DePalo [MVP VC++]" <willd.no.spam@xxxxxxxx> wrote in message
news:%23d3bw3lHHHA.816@xxxxxxxxxxxxxxxxxxxxxxx
"Vincent Fatica" <abuse@xxxxxxxxxxxxx> wrote in message
news:457f5f41$1@xxxxxxxxxxxxxxxxxxxx
The CreateNamedPipe() is outside the wnd-enum proc ... called before
EnumWindows() so the enum-proc can re-use the pipe for each window it
wants to
get info from. It all works fine when the window proc is in another
process.
When the window proc is in the same (single-threaded) process, the
querying side
(enum-proc) never gets past ConnectNamedPipe(), while the responding side
gets
to WriteFile() (which blocks). Reading the docs, I figured the
responding
side's CreateFile() would satisfy the ConnectNamedPipe() (regardless of
which
happens first).

Sorry, I'm running a bit slow today - this is the second time I failed to
grok what a poster was doing.

And jeez, I do hope I don't go for #3 but now I _think_ I understand.

You read the pipe on your application's main thread, is that it? If so,
that's the same thread on which your window procedure runs. And therein
lies the rub - neither the read nor the write can complete because they
both run on the same thread and each requires the other's completion.
Hello deadlock.

If that's it, you _might_ be able to cook up something with asynchronous
operations on the pipe but in short the problem may be that you are
breaking Windows first commandment - Thou shalt pump messages. It's almost
never a good idea to do anything in the UI thread which has a chance to be
a long running operation.

Just use ReadFileEx and WriteFileEx and continuations (then make your main
thread loop use MsgWaitForMultipleObjects with the alertable flag). No
blocking.


Again, off the top of my head, I think if you put the pipe creation and
connection logic in a secondary thread the intra and inter process cases
should behave the same.

Regards,
Will



.



Relevant Pages

  • Re: Is this OK?
    ... EnumWindows() so the enum-proc can re-use the pipe for each window it ... When the window proc is in the same process, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: fileevent
    ... Turns out to have been a typo on my part,. ... that the pipe is ready to read when there is no data to read (the file ... I have a script that reads a tailed file via a pipe, ... it and puts up the info in a HLIST window. ...
    (comp.lang.perl.tk)
  • Re: Is this OK?
    ... EnumWindows() so the enum-proc can re-use the pipe for each window it ... When the window proc is in the same process, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Key-press detection
    ... to develop a simple computer game. ... detect which key the user is pressing, eg, if the user is pressing ... pipe =!GetConsoleMode; ... should be displayed inside the window. ...
    (comp.programming)
  • Re: Key-press detection
    ... to develop a simple computer game. ... detect which key the user is pressing, eg, if the user is pressing 'a', ... pipe =!GetConsoleMode; ... be displayed inside the window. ...
    (comp.programming)