AfxGetThread returning NULL in Debug Mode and causing crash

  • Thread starter Thread starter Atul
  • Start date Start date
A

Atul

I have a .Net Managed C++ wrapper control for a MFC control. When using the
..Net control in a Visual Studio 2005 Beta 2 C# project and running in Debug
mode, I get a crash saying something like "First Chance Exception : memory
cannot be read". I found that this was becuase a call to AfxGetThread() was
returning NULL. I tried using AFX_MANAGE_STATE(AfxGetStaticModuleState());
but it did not solve the problem.

Furthermore, this crash only occurs in Debug Mode and not in Release Mode.
Also, this occurs only in VS.Net 2005 Beta 2 and not in VS.Net 2003 ( either
release or debug)

How can this be resolved?
 
Back
Top