Is it bad idea to have static CComPtr member variables in an application. Since we cannt control destruction of static variable and it can happen after CoUninitialze .
+2
A:
Provided you take the appropriate precautions, then using a CComPtr
as a static member is not inherently evil.
By "appropriate precautions", I mean you should consider:
- Mutexing access to it;
- Ensuring that it has been initialised before usage;
- Maintining a mutexed, static instance count for your own class;
- Ensuring that
CComPtr::Release
is called in your class' ownFinalRelease
method when the instance count reaches zero.
Phil Booth
2010-06-15 10:49:54