Sometimes you have a library running outside of your traditional debug mode, but would like to call into it with a debugger. I specifically ran into this with a custom installer dll called by a custom action in my MSI. The following code will allow the process itself to request debugging. Then you can specify your favorite debugger, and you’re on your way.
(The #if DEBUG / #endif, tells this only to be apart of the debug builds.)