我的DLL中,有属性表和各属性页,是MFC扩展DLL。在一个ActiveX控件中调用它时,程序执行到:
  -->    HRSRC hResource = ::FindResource(psp.hInstance,
psp.pszTemplate, RT_DIALOG);
         HGLOBAL hTemplate = LoadResource(psp.hInstance,
hResource);
pTemplate = (LPCDLGTEMPLATE)LockResource(hTemplate);
时,hResource总是为空。所以我去看DLL,发现DllMain()函数中有这么一段注释:     // Extension DLL one-time initialization
     if (!AfxInitExtensionModule(MemlistDLL, hInstance))
                 return 0;     // Insert this DLL into the resource chain
     // NOTE: If this Extension DLL is being implicitly linked to by
     //  an MFC Regular DLL (such as an ActiveX Control)
     //  instead of an MFC application, then you will want to
     //  remove this line from DllMain and put it in a separate
     //  function exported from this Extension DLL.  The Regular DLL
     //  that uses this Extension DLL should then explicitly call that
     //  function to initialize this Extension DLL.  Otherwise,
     //  the CDynLinkLibrary object will not be attached to the
     //  Regular DLL's resource chain, and serious problems will
     //  result.     new CDynLinkLibrary(MemlistDLL);虽然每个英文字母、单词都认识,但还是不能领悟其意?故望各位朋友以慈悲为怀,怜悯苍生之不幸,救小生于水火之中,则吾定当感激涕零,双手奉上100分。(不够的话,可以再加。)

解决方案 »

  1.   

    它的意思是: 如果你的这个extention DLL被隐式地链接到一个MFC Regular DLL(比如你这里的activex控件),那么你就不能把new CDynLinkLibrary(MemlistDLL)放在DLLMain中调用,而应该把它单独放到一个导出函数中,在你的activex控件中显式地调用这个导出函数来创建CDynLinkLibrary对象。
      

  2.   

    设计到module切换的问题,你的dialog template资源是放在dll文件中的,但在缺省的情况下,是在调用线程的模块中(ActiveX的ocx/dll文件中)查找这个资源的,所以需要切换模块。怎么切换,请查阅msdn(用AFX_MAINTAIN_STATE宏)的TN058: MFC Module State Implementation。
      

  3.   

    可是这个DLL,我不仅在MFC应用中要调用到,而且在其他如ActiveX控件中也要应用到,并且有可能是显式链接也可能是隐式链接,有没有一个统一的办法可以解决?请赐教!
      

  4.   

    你应该注意资源的搜索顺序,从ActiveX到DLL的转变。
      

  5.   

    在msdn中找不到AFX_MAINTAIN_STATE宏的说明
      

  6.   

    我现在在做的一个是需要在dll中使用到cmscomm,而cmscomm控件需要有dialog才能生存。请问各位大虾有无这方面经验!
      

  7.   

    我到codeguru.com找到这样一个方法:在调用DLL资源时,先
    m_hInstOld = AfxGetResourceHandle();
    AfxSetResourceHandle(TagListDLL.hResource);
    在结束时,再
    AfxSetResourceHandle(m_hInstOld);
    这样,对于MFC应用是可以的。但这样在ActiveX控件中就是不能用,老在上面那地方出错。急死我了。
      

  8.   

    谢谢各位高手。我的问题解决了!我是这样解决的,在我OCX控件中调用有资源的MFC扩展DLL,要弹出对话框前使用下面的代码:
    //保存当前ACTIVEX控件资源,装载TagList.DLL资源
    HINSTANCE hOldInst = AfxGetResourceHandle();
    HINSTANCE hTagDll = ::LoadLibrary("TagList.dll");
    if(hTagDll)
    AfxSetResourceHandle( hTagDll );
    ..................
    ...................
    .................
    之后:
    //恢复保存的ACTIVEX控件资源,卸载TagList.DLL资源
    if(hTagDll)
    FreeLibrary(hTagDll);
    AfxSetResourceHandle( hOldInst );
    发现这样,竟然可以了。呵呵!不知这样有没有漏洞?请各位指正!