Re: Porting MIDI plug-in from CW to Xcode
Re: Porting MIDI plug-in from CW to Xcode
- Subject: Re: Porting MIDI plug-in from CW to Xcode
- From: Pete Gontier <email@hidden>
- Date: Wed, 10 Aug 2005 16:28:27 -0700
Title: Re: Porting MIDI plug-in from CW to Xcode
Under the assumption no joy would be forthcoming on the tools compatibility front, I bit the bullet and did a bunch of COM monkey-work which no one should ever have to do. I think I got it working, but now I have a question.
In the course of re-learning all this COM stuff, I noticed my plug-in was not calling CFPlugInRemoveInstanceForFactory. This would seem to be a leak of some sort and magnitude, so I added a call to CFPlugInRemoveInstanceForFactory in what I thought was an appropriate place. This caused my Start routine to be passed garbage. This might seem impossible, but I think have half an explanation.
I’ve noticed that most MIDI drivers, the standard sample included, merge the plug-in COM interface with the MIDI driver COM interface. This was actually a big source of confusion for me a few years back and things started to make a lot more sense after I stopped doing that in my code. My driver is now structured to create two separate COM objects, one for the plug-in, which I understand to be a driver factory, and one for the driver whenever someone requests an instance from the driver factory.
The problem seems to result from the lifetimes of the objects. The MIDI server creates a driver factory, then uses the driver factory to create a driver object, then releases the driver factory. That makes sense and is basically what I would expect. The trouble is that in my code there’s only one reference to the driver factory, which means that it is destroyed when it is released, and its destructor seems to be the right place to call CFPlugInRemoveInstanceForFactory, just like its constructor seemed the right place to call CFPlugInAddInstanceForFactory.
If I had the two objects merged into one, there’d be at least one reference to the single plug-in/driver object at all times, and the destructor would not get called until after the driver object had been released, which presumably would avoid garbage being passed to Start or any other driver function. (I’d also be sorely confused and forever suspicious of the code because it makes no sense to me to merge the implementations of two semantically distinct objects.)
I am not by any means the world’s foremost expert on COM or CFPlugIn, but right now I don’t have a good place to call CFPlugInRemoveInstanceForFactory, and I’m not in a position right now to merge the objects. I have an idea of what to do about this which involves a fair amount of code, but can anyone provide a hint at a simple solution?
— Pete Gontier <http://www.m-audio.com/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden