ConsoleApplication with Message Queue?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ConsoleApplication with Message Queue?

Carsten Haerle
Do console applications have a windows message queue and if why? I have two
problems with a console application:

1) I created a console application which starts a separate program X with
CreateProcess and waits on the termination of with WaitForMultipleObjects.
This application now hangs and I suppose that it is the problem which I
already had with a GUI application which was blocking in a windows call,
namely that the application X as a side effekt is broadcasting windows
message sends to all applications with a message queue, which will block if
an application is not processing messages.

2) This console application is started by another application Y which
normally starts X directly. When I replace X with the Dolphin programm (to
wrap it) a command line (or console) window is opened during the execution
of the the Dolphin application. It looks like the the effect when opening a
console from a Dolphin GUI program.Why does this happen?

Regards

Carsten Härle


Reply | Threaded
Open this post in threaded view
|

Re: ConsoleApplication with Message Queue?

Blair McGlashan
"Carsten Haerle" <[hidden email]> wrote in message
news:c325op$o8q$07$[hidden email]...
> Do console applications have a windows message queue and if why?

Yes they do. It is needed for some types of inter-thread communication
between the image and VM, is needed for COM support (when used), and to
implement deferred actions ([blah blah] postToInputQueue). In fact
SessionManager>>main is invoked as a deferred action.

>...I have two
> problems with a console application:
>
> 1) I created a console application which starts a separate program X with
> CreateProcess and waits on the termination of with WaitForMultipleObjects.
> This application now hangs and I suppose that it is the problem which I
> already had with a GUI application which was blocking in a windows call,
> namely that the application X as a side effekt is broadcasting windows
> message sends to all applications with a message queue, which will block
if
> an application is not processing messages.

For long-running console applications I suggest forking off the main
operation from #main. This will allow the main message loop to operate. It
is necessary to override #keepAlive to suppress the immediate application
terminate that will otherwise occur, and then explicitly #exit the session
when appropriate.

However, to do what you want to do you have a slightly more tricky problem
because the call to WaitForMultipleObjects will block the main Dolphin
thread, thus pausing all the Dolphin Processes. You could try forking off
the CreateProcess operation (remembering to override #keepAlive to do
nothing) and overlapping the WaitForMultipleObjects call. I don't know
whether this will work or not, but it would be the simplest thing to try.

Another approach would be to make your own subclass of InputState that can
wait on additional Win32 synchronisation objects when it makes its call to
MsgWaitForMultipleObjectsEx. You'll need to hold some kind of map between
from the Win32 synchronisation object to a corresponding Dolphin Semaphore.
Then when the MsgWaitForMultiplesObjects(Ex) call returns it should signal
the Semaphore that corresponds to the Win32 sync. object that caused
MsgWaitForMultipleObjects(Ex) to return (the API call returns the index of
the object that woke it up, and some other special values, see the API docs
on MSDN). After the forked operation has called CreateProcess it should then
"register" the new process handle and a corresponding Semaphore with your
new input state, and then wait on the Semaphore. This is a bit specialised,
so if you want any further help with it I think you will have to purchase a
support incident or two.

>
> 2) This console application is started by another application Y which
> normally starts X directly. When I replace X with the Dolphin programm (to
> wrap it) a command line (or console) window is opened during the execution
> of the the Dolphin application. It looks like the the effect when opening
a
> console from a Dolphin GUI program.Why does this happen?

I'm afraid I don't know the answer to that off the top of my head.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: ConsoleApplication with Message Queue?

Chris Uppal-3
In reply to this post by Carsten Haerle
Carsten Haerle wrote:

> 2) This console application is started by another application Y which
> normally starts X directly. When I replace X with the Dolphin programm (to
> wrap it) a command line (or console) window is opened during the execution
> of the the Dolphin application. It looks like the the effect when opening
> a console from a Dolphin GUI program.Why does this happen?

I think it may be happening because you are building your Dolphin version of X
as a console application.  As I understand it (which may be completely wrong)
the only really significant difference between a Dolphin "console" application
and a Dolphin "GUI" application is that Dolphin sets up the console streams
for you -- and it is this that is causing the console windows to appear.

I suspect that if you make your application's session manager a subclass of
GUISessionManager rather than ConsoleSessionManager but without actually
opening any windows (and overriding #keepAlive as Blair has already described),
then it may work as you are expecting.

    -- chris