Original Post
Some of the code we write relies on third-party software that has pretty tight license restrictions. To be able to use their API, code must call Initialize from their Singleton Object (it's a COM class) once at application startup to checkout the correct license, and then call Shutdown once at application end (this should be the last thing called). Code looks like this usually: Note that you don't have to retain a pointer to the Initializer instance since every time you instantiate one you get the same one back (it's a Singleton behind the scenes). I want to be able to provide a wrapper that guarantees that Shutdown gets called once at the end of the program. As it currently is, if you don't call it, the license never gets checked back in. I suspect this could be made pretty generic and useful since lots of C libraries have init and shutdown calls that must be made once at startup, and once at shutdown. For example, DevIL has iluInit/iluShutdown() and ilutInit/ilutShutdown() calls that must be paired, similar to my situation above. A simple RAII wrapper might work, but what are some of the caveats? Should it be non-copyable so init/shutdown don't get called multiple times? Is this a valid case for a Singleton? What would your fail-safe, "users can't possibly get this wrong", solution be?
// Sometime after ::CoInitialize, but before we start using their API
IInitializerPtr init(CLSID_Initializer);
init->Initialize(requested_license);
... // application stuff
init->Shutdown();
// ::CoUninitialize called sometime later