[python-win32] Implementing IID_IMAPIAdviseSink

Mark Hammond skippy.hammond at gmail.com
Wed Aug 26 02:20:21 CEST 2009


On 26/08/2009 8:21 AM, Arn Vollebregt wrote:
> Hi,
>
> I am trying to hook an advise sink into Outlook to receive new email
> notifications, but I cannot find any examples on this. I've scraped together
> the code below, but that yields an error. Can anybody point me to a working
> sample, or provide a quick sample of how to imlement this? I've been banging
> my head on this for some days now, I am not making any progres...
>
> <code>
> class Sink():
> 	_com_interfaces_ = [mapi.IID_IMAPIAdviseSink]
> 	_reg_progid_ = 'IMAPIAdviseSinkTest'
> 	_reg_clsid_ = str(mapi.IID_IMAPIAdviseSink)
> 	#_reg_clsid_ = str(pythoncom.CreateGuid())
> 	_public_methods_ = ['OnNotify']
>
> 	def OnNotify(self, foo, bar):
> 		print "DEBUG: received an OnNotify()"
>
> def main():
> 	sink = pythoncom.CoCreateInstance(Sink._reg_clsid_, None,
> pythoncom.CLSCTX_ALL, mapi.IID_IMAPIAdviseSink)
>
> if __name__ == '__main__':
> 	main()
> </code>
>
> <error>
> sink = pythoncom.CoCreateInstance(Sink._reg_clsid_, None,
> pythoncom.CLSCTX_ALL, mapi.IID_IMAPIAdviseSink)
> pywintypes.com_error: (-2147221164, 'Class not registered', None, None)
> </error>

You don't need to CoCreateInstance, and don't need the _reg_* 
attributes.  Something like:

from win32com.server.util import wrap
site = wrap(Sink())

should allow you to pass the 'site' object to a function which expects 
an IMAPIAdviceSink interface.

Cheers,

Mark


More information about the python-win32 mailing list