[python-win32] Casting to IRTDUpdateEvent object

Christopher Nilsson chris at slort.org
Sat Apr 7 16:22:06 CEST 2012


I sent a reply privately, but for the list's benefit, I'll send a copy here
too.  With luck, everything I say is wrong and somebody will have a
solution. :)

I fear that things with IRTDUpdateEvent have changed with recent versions
of excel (since Excel 2007? I guess that's not so 'recent' anymore...).

While hunting around for news of interface changes, I came across this
thread in a java forum:


The part that worries me is this comment:

"Apparently in Excel 12 (Excel 2007) the RTD callback object that
implements dual IRTDUpdateEvent interface throws exception (generic COM
exception 0x80020009) when is called via IDispatch. If you use v-table
binding the call to UpdateNotify succeeds. I don't really know whether it
is a bug in Excel 12 or a feature."

So far I haven't been able to confirm this against the MSDN information...
But if this is true, it does explain the problem being seen.  Many older
examples on the web, and pywin32+makepy treat this interface as IDispatch,
and wrap it accordingly.

I don't think we can fix this with pywin32 as it is right now. My
understanding is that it relies on IDispatch support. May need to look at
comtypes (http://starship.python.net/crew/theller/comtypes/) to wrap the
(new?) IRTDUpdateEvent objects, or maybe a C extension. :(

It's a pity, since everything else appears to still work.  Just the
callback object Excel supplies no longer seems to support all the
interfaces it advertises (I'm betting makepy wouldn't even try to build the
IDispatch wrapper if QueryInterface said it wasn't supported).

I don't currently have a copy of Office, with my daily job being in linux
land these days, so even though I'd like to, I doubt I'll be much help
fixing this.


On 7 April 2012 13:19, John S <js.20120405 at gmail.com> wrote:

> I'm trying to implement excelRTDserver.py (
> http://www.math.uiuc.edu/~gfrancis/illimath/windows/aszgard_mini/movpy-2.0.0-py2.4.4/movpy/lib/win32com/demos/excelRTDServer.py).
> I'm running Excel 2010 (32bit) so I change the EXCEL_TLB_MINOR value to 7.
> The add-in is visible in the Excel add-ins list and if I enter
> =RTD("Python.RTD.TimeServer","","seconds","5") into a cell, I get the
> current time. But it never updates. If I change the "5" to another number,
> I get an update but after the initial change it never updates.
> I've isolated the problem to an exception raised when the callback object
> returned by Excel is attempted to be cast into a IRTDUpdateEvent object.
> This was discussed on this list previously (
> http://mail.python.org/pipermail/python-win32/2011-March/011324.html) but
> no solution. I tried the suggested solution of using CastTo, but when
> EnsureDispatch is called within gencache.py it raises the exception at the
> first line within the try statement (ti = disp._oleobj_.GetTypeInfo()).
> So my question is how do I get the callback object to work? Any help would
> be greatly appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20120408/e53564b7/attachment.html>

More information about the python-win32 mailing list