Re: timer queue
From: John B (B_at_discussions.microsoft.com)
Date: 02/26/05
- Next message: steven: "how to convert a object pointer to variant pointer"
- Previous message: Alexander Nickolov: "Re: Where and how to start learning ATL"
- In reply to: Alexander Nickolov: "Re: timer queue"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 25 Feb 2005 19:21:03 -0800
Thanks for the reply. I did end up creating a hidden window that works ok.
Incidently, calling QI for IUnknown doesn't work as a test for the existence
of the app. The call succeeds even after eg Word has been closed. I am
assuming that the proxi is doing some shortcutting on some calls. However
Invoke on a property does fail with "rpc not available" after the app is
closed.
"Alexander Nickolov" wrote:
> Most likely both components run in the same apartment, so the
> second holds a direct pointer to the first. Therefor e, COM is
> not in the loop to safeguard you against blunders and the call
> from 2 to 1 on the timer thread succeeds. Ordinarily you
> cannot make any COM calls from this timer thread since COM
> is not initialized on it.
>
> Assuming you have STA components, I suggest you create
> a hidden window and use SetTimer/KillTimer and handle
> WM_TIMER from that hidden window (don't use global
> timers since it's hard to get back into your object).
>
> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD
> email: agnickolov@mvps.org
> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================
>
> "John B" <John B@discussions.microsoft.com> wrote in message
> news:8FDBF2A1-22F9-429D-9799-129FC6784155@microsoft.com...
> >I am trying to use CreateTimerQueue in an ATL class and am having trouble
> > with some threading issues. I am using an inproc class to launch an App
> > eg
> > Word and then launching another class as an event sink for the app. These
> > two classes use custom interfaces to communicate. The structure is as
> > follows
> >
> > Class 1 coCreate app (eg Word) and uses type infor to look for events eg
> > Quit.
> > Class 1 coCreate class 2 and passes pUnk1 and pDispApp (Word) in an
> > interface method call. Class 2 calls pUnk1->QI to get custom interface to
> > callback to 1, p1. If app supports Quit, 2 uses pDispApp->QI connection
> > interfaces and calls Advise. This all works. 2 sinks the events and
> > calls 1
> > using interfacem p1. If the app does not support Quit, 2 calls
> > CreateTimerQueue, etc. The problem comes in the timer callback. I pass
> > 2's
> > "this" ptr as a parameter and static cast to p2 in the static timer
> > callback.
> > In the callback, p2-> member values are ok, p2->p1 works but p2->pDispApp
> > gets a "marshalled on wrong thread" error. I want to use the pDispApp to
> > take a quick peek, eg p2->pDispApp->QI( IUnknown) to see if the App is
> > still
> > alive. The pDispApp works in the (nonstatic) member methods of p2 without
> > a
> > problem. Why does p2->p1 work and p2->pDispApp not work in the timer
> > callback? If the callback is on a different thread, why does p2->p1 work
> > and
> > if the callback is on p2's thread, why doesn't p2->pDispApp not work?
> > Another question is whether there a better way to set up a timer that
> > would
> > avoid this problem?
>
>
>
- Next message: steven: "how to convert a object pointer to variant pointer"
- Previous message: Alexander Nickolov: "Re: Where and how to start learning ATL"
- In reply to: Alexander Nickolov: "Re: timer queue"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|