在做IMAPI的東西的時候,需要用到CoCOM的東西,
然後他又需要使用ATL....總之很麻煩0rz
好了,重點就是在trace bug的時候跑到atlcom.h這個檔案裡面的
class CComObjectCached : public Base
{
public:
 typedef Base _BaseClass;
 CComObjectCached(void* = NULL){}
 // Set refcount to -(LONG_MAX/2) to protect destruction and
 // also catch mismatched Release in debug builds
 // This will be made virtual again for Beta 2
 /*virtual*/ ~CComObjectCached()
 {
  m_dwRef = -(LONG_MAX/2);
  FinalRelease();
#ifdef _ATL_DEBUG_INTERFACES
  _AtlDebugInterfacesModule.DeleteNonAddRefThunk(_GetRawUnknown());
#endif
 }
 //If InternalAddRef or InternalRelease is undefined then your class
 //doesn't derive from CComObjectRoot
 STDMETHOD_(ULONG, AddRef)() throw()
 {
  ULONG l = InternalAddRef();
  if (l == 2)
   _pAtlModule->Lock();
  return l;
 }
沒錯,就是_pAtlModule->Lock();這邊,然後你發現他記憶體位址居然是0x000000
然後就crash了!
不要相信甚麼add ATL support to MFC 之類的鬼話(加了以後我不知道怎麼刪掉,只能重寫)
解決方法:
在你的主程式(.cpp)裡面,
#include .......
//在這邊新增
CComModule _Module;
extern __declspec(selectany) CAtlModule* _pAtlModule=&_Module;
//新增完成
主程式:建構子....
主程式.....
這樣就可以解決了
END