It seems that Microsoft has had this bug too.
http://support.microsoft.com/kb/962924[
^].
"You can work around this build issue by adding a call to AFX_MANAGE_STATE(AfxGetStaticModuleState()) as the first line in either InitInstance() or ExitInstance().".
Also, besides 2 results of you asking this question, that page was the top result in
google[
^].