10.9.08

CoInitialize/CoUninitialize: Rules to live by

After reading Ben Kuhn's post on the subject, I realized how poorly this is being managed in the code of my current project. The rules are basically:
  1. Every CoInitialize that succeeds needs a CoUninitialize otherwise the reference counting gets off and all heck breaks loose
  2. Every CoInitialize that fails should NOT call CoUninitialize otherwise the reference counting gets off and all heck breaks loose
  3. Use an HRESULT variable and capture the result of the CoInitialize. Use the SUCCEEDED macro to determine, drumroll please, if the CoInitialize succeeded.
  4. There are a couple other, more remote, cases, read about them in the link above.

0 comments:

Post a Comment