[pywin32-bugs] [ pywin32-Feature Requests-1567449 ] Dynamic Cast of COM Pointers
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2006-11-18 16:56:11
|
Feature Requests item #1567449, was opened at 2006-09-28 22:29 Message generated for change (Comment added) made by rupole You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551957&aid=1567449&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: com Group: Next Release (example) >Status: Closed >Resolution: Out of Date Priority: 5 Private: No Submitted By: Jeffrey C. Jacobs (timehorse) Assigned to: Nobody/Anonymous (nobody) Summary: Dynamic Cast of COM Pointers Initial Comment: I don't know how many other COM libraries do this, but specifically with iTunes, the Interfaces defined for tracks form a hierarchy (in python-speak): class Track(Item): pass class FileOrCDTrack(Track): pass class URLTrack(Track): pass The problem is, a number of interfaces are defined to return a pointer to a Track interface when in fact one can test the object and safely refer to it via a derived interface. For instance, iTunesApp.CurrentTrack returns a Track interface pointer, even if it is a FileOrCDTrack. In fact, all but 1 interface prevents the user from accessing the derived class properties (which include a lot of new features that are part of the base class in AppleScript). Direct Indexing by name, ID or playlist order all return a pointer to the base interface. Thus, none of these allow access to the derived attributes in FileOrCDTrack even if the track is indeed a File or CD based track. So the ONLY way to retrieve the derived interface is to use the Enum method of the LibraryPlaylist object and iterate through ALL the tracks known, which in a large library can take an astronomical amount of time. The Enum method does however properly return FileOrCDTrack interfaces when appropriate. The idea of the Dynamic Cast would therefore be to allow the user to perform a C++ style dynamic_cast on an interface to convert it to a different interface. In this example, one would take a track instance, call it's 'kind' property to verify that it was a FileOrCDTrack and then cast the interface pointer from a Track interface to a FileOrCDTrack. ---------------------------------------------------------------------- >Comment By: Roger Upole (rupole) Date: 2006-11-18 11:56 Message: Logged In: YES user_id=771074 Originator: NO Since there are already two different ways to accomplish this, closing as out of date. Roger ---------------------------------------------------------------------- Comment By: Stefan Schukat (sschukat) Date: 2006-10-04 09:12 Message: Logged In: YES user_id=977439 Try from win32com.client import CastTo FileTrack = CastTo(iTunesApp.CurrentTrack, "FileOrCDTrack") this should help. ---------------------------------------------------------------------- Comment By: Roger Upole (rupole) Date: 2006-09-28 23:16 Message: Logged In: YES user_id=771074 You should be able to do this using QueryInterface. The attached code takes an IITTrack object and gets an IITFileOrCDTrack interface from it. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551957&aid=1567449&group_id=78018 |