如题。
1. 如果dll是动态加载的,在加载之前exe已经AfxInitOle()或者CoInitialize()了。那么dll中如果要用到COM调用的话,还需要AfxInitOle()或者CoInitialize()吗?2. 如果dll是静态加载的,那么exe和dll的实现代码需要一份AfxInitOle()调用还是各自需要调用一次呢?谢谢!

解决方案 »

  1.   

    1.不需要,AfxInitOle似乎是线程相关的。
    2.同1。
      

  2.   

    是AfxOleInit吧If AfxOleInit is called from an MFC DLL, the call will fail. The failure occurs because the function assumes that, if it is called from a DLL, the OLE system was previously initialized by the calling application.http://msdn.microsoft.com/zh-cn/library/e91aseaz
      

  3.   

    不需要的,在主线程中主需要一次CoInitialize,如果DLL中再次CoInitialize,则此处会返回error,也许你会判断那里出错,但此时却没有错误。
      

  4.   

    不需要的,在主线程中只需要一次CoInitialize,如果DLL中再次CoInitialize,则此处会返回error,也许你会判断那里出错,但此时却没有错误。
      

  5.   

      _AFX_THREAD_STATE* pState = AfxGetThreadState();
      if(!pState->m_bNeedTerm)
        AfxOleInit();