I'm using Component Manager in a Mac app to get the list of installed components (my app is a video player, and I want to get at the list of of installed QuickTime codecs).
I have code like this:
- (void) findComponents
{
ComponentDescription desc;
desc.componentType = 0;
desc.componentSubType = 0;
desc.componentManufacturer = 0;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
long numComps = CountComponents( &desc );
NSLog( @"found %ld components", numComps );
Component aComponent = 0;
while( (aComponent = FindNextComponent( aComponent, &desc) ) ) {
// Do stuff with this component.
}
}
When I compile my app 32-bit, it works as I'd expect (927 components come back from CountComponents). However, when compiled 64-bit, CountComponents returns only 85 components (none of which are the QuickTime codecs I'm looking for).
The Component Manager docs don't say anything about 64-bit issues with CountComponents/FindNextComponent. It's worth noting that the (admittedly ancient) Apple DTS sample code upon which this code is based has the same issue when compiled 64-bit.
Any ideas what I'm doing wrong? I don't want to have to resort to manually finding components and parsing 'thng' resources.
EDIT: is it possible that in a 64-bit app, Component Manager is only listing the 64-bit components? In which case, perhaps this functionality could be built into a 32-bit shared library, and called from my 64-bit app?
However, when compiled 64-bit, CountComponents returns only 85 components (none of which are the QuickTime codecs I'm looking for).
QuickTime codecs that use the QuickTime C API are 32-bit only, and Apple have not ported that API to 64-bit. Note that, application-wise, you can use QTKit, the new Objective-C API. QTKit tries to use QuickTime X to play a movie; if it can’t because there’s no suitable QuickTime X codec available, it falls back to QuickTime 7, which in turn is able to use old QuickTime components. This is transparent for developers that use QTKit.
Is it possible that in a 64-bit app, Component Manager is only listing the 64-bit components?
Yes, that’s correct. Note that it is not possible to mix 32-bit and 64-bit code in the same process, so it makes sense that Component Manager would limit queries to the components that could be loaded onto the process: 32-bit components for a 32-bit process, 64-bit components for a 64-bit process.
In which case, perhaps this functionality could be built into a 32-bit shared library, and called from my 64-bit app?
As described above, you won’t be able to load a 32-bit dynamic library onto a 64-bit process. What you can do is to create a separate 32-bit helper executable and use it to obtain a list of 32-bit components. You can share the source code that list components amongst your main application and the helper executable, but they must be separate executables.
In fact, you can see this in action if you use QuickTime X to play a movie that requires a 32-bit QuickTime component: a 32-bit QTKitServer process is spawned in order to decode the movie using a QuickTime component and send the results back to 64-bit QuickTime X. John Siracusa describes this in his Snow Leopard Review. You may also want to take a look at the Adopting QuickTime X for Playback section in QTKit Application Programming Guide.