I was a little worried that actually working with COM (as opposed to the browsing I was doing yesterday) would be hard, but it was surprisingly easy. Here's the code I used to get a COM driver for iTunes on Windows:
getITunesCOMDriver
"Get a driver for dealing with iTunes"
| ref guid driver descs ifc |
ref := COMRegistryInterface extTypeLibraryIDMap
detect: [:each | 'iTunes *Type Library' match: each name]
ifNone: [nil].
ref ifNil: [^nil].
descs := ref containedTypeDescriptions.
ifc := descs
detect: [:each | 'iTunesApp' match: each name]
ifNone: [nil].
ifc ifNil: [^nil].
guid := ifc guid.
driver := AdvancedDispatchDriver
on:
(IClassFactory createInstance: guid iid: External.COMConstants.IID_IDispatch context:
External.COMConstants.CLSCTX_SERVER).
^driver
That retrieves a driver that can receive the same kinds of messages as the iTunes AppleScript library can. In particular, this is how I then toss a Bf subscription over to iTunes (assuming it's a podcast):
doWindowsITunesSubscribeFor: aFeed
"use COM to subscribe in iTunes"
| driver |
driver := self getITunesCOMDriver.
driver ifNil: [^self].
driver SubscribeToPodcast: aFeed url.
I could use the entire available driver API with that object, but for now, all I really care about is the subscription option. All in all, it was pretty straightforward.
Technorati Tags:
smalltalk, iTunes, COM