views:

35

answers:

2

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' own FinalRelease method when the instance count reaches zero.
Phil Booth
A: 

it is a bad idea anyway

Andrey