Mike Krell schrieb: > I'm running 0.6.0 under Python 2.6. Source code: > > *********************************************************************** > > from comtypes import * > from comtypes.client import * > import comtypes.gen.iTunesLib > > itunes = CreateObject("iTunes.Application") > librarySource = itunes.LibrarySource > playListCollection = librarySource.Playlists > userPlayList = playListCollection.ItemByName("My Test PlayList") > > if userPlayList is None: > userPlayList = itunes.CreatePlaylist("My Test PlayList") > > print userPlayList > > u2 = cast(userPlayList, POINTER(comtypes.gen.iTunesLib.IITUserPlaylist)) > > print u2 > > u2.Reveal() > > *********************************************************************** > > This fails with the following output: > > <POINTER(IITPlaylist) ptr=0x2a5a24 at 1ee1940> > <POINTER(IITUserPlaylist) ptr=0x2a5a24 at 1ee18a0> > --------------------------------------------------------------------------- > WindowsError Traceback (most recent call last) > > e:\projects\Python\FetchAudio\aftp.py in <module>() > 49 print u2 > 50 > ---> 51 u2.Reveal() > 52 > > WindowsError: exception: access violation reading 0x00000000 > > > *********************************************************************** > > > I'm trying to do something equivalent the following, which works using > win32com.client: > u2 = win32com.client.CastTo(userPlayList, 'IITUserPlaylist') > > It's as if the downcast is failing. Please advise.
You should not use ctypes.cast with COM pointers. Use QueryInterface(interface) instead: > print userPlayList > > u2 = userPlayList.QueryInterface(comtypes.gen.iTunesLib.IITUserPlaylist) > > print u2 > > u2.Reveal() It is a bit unfortunate that win32com uses the name CastTo() for the same thing. -- Thanks, Thomas ------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users