Hi there,

I read this in MSDN:

Fetching a global variable:
When creating a local copy of an interface pointer from an existing copy of the pointer in a global variable, you must call AddRef on the local copy because another function might destroy the copy in the global variable while the local copy is still valid.
When recreating the problem on purpose this is what seemed to be what it was. I had a global class declared which contained COM pointers, and then I made a pointer which held the class's address. I then cast this to the interface pointer class type. All of this was in a separate function that did not belong to the class.

I did not call AddRef() on anything anywhere though. I'm still not totally sure but I suspect the DLL destroyed the global declared class inside itself but the interface pointer was still valid. Thus when the interface pointer itself was destroyed in the application it caused a knock on effect that led to an attempt to call Release() on a pointer to a COM object when the object no longer existed. Presumably the COM object deleted itself when the DLL was unloaded.

I'm still not totally sure about this but I suspect calling AddRef() somewhere (or anything else that causes AddRef() to be called?) increased the COM object's reference count, and thus kept it alive long enough to receive the final Release() call on it. Which thus removed the error I was previously getting on shutdown.

The way I've done it now seems just to consider only one pointer to the COM object to be valid, and thus there are no extra Release() calls that shouldn't be there.

It would be good though if someone can confirm if there's any credibility in this theory though.

Thanks