Mike...
First of all, sorry but I don't have a linux box right now (bad HDD) so this is the best I can do.
My code below will cause an AddRef only on the first ITypeInfo pointer created (for each ITypeInfo), and a release on the last ITypeInfo pointer released. For each typeinfo struct in the typelib, you will get one reference if a client has any references to that object. As soon as all client references to ITypeInfo's supported by the typeinfo in the library are released, the refcount of the library will go to zero. Of course, you should not addref the library (directly) in GetTypeInfoOfGuid or any other place that doesn't return a ITypeLib pointer.
Here's some source (with changes inline) from the typelib.c in 5/8/2003 source on source.winehq.com
3795 /* ITypeInfo::AddRef 3796 */ 3797 static ULONG WINAPI ITypeInfo_fnAddRef( ITypeInfo2 *iface) 3798 { 3799 ICOM_THIS( ITypeInfoImpl, iface); 3800
here, I'd recommend inserting: if(This->ref == 0) ITypeLib2_AddRef((ITypeLib2 *)This->pTypeLib);
3801 ++(This->ref); 3802 3803 TRACE("(%p)->ref is %u\n",This, This->ref); 3804 return This->ref; 3805 } 3806 3807 /* ITypeInfo::Release 3808 */ 3809 static ULONG WINAPI ITypeInfo_fnRelease( ITypeInfo2 *iface) 3810 { 3811 ICOM_THIS( ITypeInfoImpl, iface); 3812 3813 --(This->ref);
and here, I'd recommend inserting if(This->ref == 0) ITypeLib2_Release((ITypeLib2 *)This->pTypeLib);
3814 3815 TRACE("(%p)->(%u)\n",This, This->ref); 3816 3817 if (!This->ref) 3818 { 3819 FIXME("destroy child objects\n"); 3820 3821 TRACE("destroying ITypeInfo(%p)\n",This); 3822 if (This->Name) 3823 { 3824 SysFreeString(This->Name); 3825 This->Name = 0; 3826 } 3827 3828 if (This->DocString) 3829 { 3830 SysFreeString(This->DocString); 3831 This->DocString = 0; 3832 } 3833 3834 if (This->next) 3835 { 3836 ITypeInfo_Release((ITypeInfo*)This->next); 3837 } 3838 3839 HeapFree(GetProcessHeap(),0,This); 3840 return 0; 3841 } 3842 return This->ref; 3843 }