
422
|
Chapter 11, Native Integration and Packaging
#83 Control iTunes Under Windows
HACK
Working with COM
The Component Object Model (COM) is a standard way for Windows com-
ponents to expose functionality that other programs can call at runtime.
com4j (https://com4j.dev.java.net/) is an open source library that creates
connections from Java programs to COM objects. com4j has two parts: a
command-line program to create the Java interfaces that your program will
call, and a native library that binds your program to the COM object at run-
time.
com4j uses class annotations to do its magic, so you can only
use it with Java 5.0 or greater.
To get started, download the com4j package at https://com4j.dev.java.net/
servlets/ProjectDocumentList. With the com4j stubber and the iTunes exe-
cutable in your current directory, you can generate the interfaces like this:
java -jar tlbimp.jar -o jtunes -p test.jtunes iTunes.exe
This command will load the iTunes executable and look for COM defini-
tions. Once they are located,
tlbimp will generate a bunch of Java interfaces
in the
test.jtunes package and put the .java files into the jtunes directory. If
you look at the generated Java interfaces, you will see a whole slew of meth-
ods and objects for playing, querying tracks, and dealing with virtually every
other feature of iTunes. com4j will also pull out any embedded documenta-
tion and insert the documentation as JavaDoc ...