Static instance of class in C++. Problem solved.
["Hey, let's do complicated stuff in DLL_PROCESS_ATTACH. What could possibly go wrong?" -Raymond]
In case you might doubt what Raymond is saying here, I just spent months trying to get a third-party component supplier to fix an intermittent hang that happened only on the machines at one customer site. It happened because a static initializer called a function that led through a chain of 5 dlls and 20 calls, including several system calls, and then it caused the load of another dll, and bang, deadlock, because the loader lock is already held. This was NOT FUN.