我的DLL里有几个界面的类如:CxxButton,它继承自CButton,但静态连接编译的时候会得到警告:warning C4275: non dll-interface class 'CButton' used as base for dll-interface class 'CxxButton'
静态连接(测试程序和DLL都使用Use MFC in a static library)时能成功编译,但在测试程序里我输出的类CxxButton没有作用,没能重画Button(在测试程序里的头文件里我申明了button为CxxButton的实例的),放在对话框上的Button控件仍然是它的本来面目。
在使用动态连接(测试程序和DLL都使用Use MFC in a Share DLL)时既能成功编译,也不提示有警告错误,还能正确的显示(能重画button).大家帮帮忙,弄了很久都不能解决。弄得郁闷了。

解决方案 »

  1.   

    下面是在MSDN上找到的,也许没有用。PSS ID Number: Q134980Article Last Modified on 05-6-2001
    --------------------------------------------------------------------------------
    The information in this article applies to: The Microsoft Foundation Classes (MFC)
    Microsoft Visual C++, 32-bit Editions 2.0, 2.1, 2.2--------------------------------------------------------------------------------
    Symptoms
    The Compiler issues the following warning for a class derived from one of the MFC classes: warning C4275: non dll-interface class <XXX> used as base for dll-interface class <YYY> 
    A related warning is issued when an object of some MFC class is embedded as a data member of a user-defined class: 
    warning C4251: <identifier> : class <XXX> needs to have dll-interface to be used by clients of class <YYY> 
    See the "Sample Code" section of this article an example of a class declaration that generates these warnings.This problem no longer occurs in vc 4.0 or later. Cause
    The DLL version of MFC does not export its classes by declaring them with "class __declspec(dllexport)." Instead, it exports its classes through entries in the EXPORTS section of its module definition (.def) file.Because the compiler has only the header files to work with, it cannot determine whether the MFC classes were actually exported, and therefore it issues the warning. Resolution
    Because the MFC classes are in fact exported, these warnings can be safely ignored. As shown in the DLLHUSK sample, you can disable these warnings by using the following pragma statements:   #pragma warning(disable: 4275)/********************************/
      #pragma warning(disable: 4251)/********************************/ 
    On the other hand, if the warnings refer to some user-defined class rather an MFC class, you should ensure that the class is exported before disabling these warnings. Status
    This behavior is by design. More InformationSample Code to Reproduce Behavior
    /* Compile options needed: None
    */ // The following class declaration causes a C4275 warning
    // because the CObject class is not also declared with
    // __declspec(dllexport).
    class __declspec(dllexport) CMyClass : public CObject
    {
      ...
      // The following data member causes a C4251 warning,
      // because the CString class is not declared with
      // __declspec(dllexport).
      CString m_strName;
      ...
    }; References
    For more information, please see MFC TechNote 33 for a discussion of the reasons behind the decision to export MFC's classes in the module definition file rather than in the class declaration. Additional query words: 2.00 2.10 2.20 3.00 3.10 3.20 Keywords: kberrmsg kbnokeyword kbDLL kbMFC kbVC200 kbVC220 kbGrpDSMFCATL 
    Issue Type: kbprb 
    Technology: kbAudDeveloper kbMFC 
      

  2.   

    继承的类没有定义输出:参考帖子:http://search.csdn.net/Expert/topic/207/207377.xml?temp=.5513269
    http://search.csdn.net/Expert/topic/1294/1294550.xml?temp=.4942133
      

  3.   

    我是这样声明的:
    #ifdef XXLIB_IMPL
        #define XXLIB_EXT_CLASS _declspec( dllexport )
        #define XXLIB_EXT_API _declspec( dllexport )
    #else
        #define XXLIB_EXT_CLASS _declspec( dllimport )
        #define XXLIB_EXT_API _declspec( dllimport )
    #endifclass XXLIB_EXT_CLASS CxxButton : public CButton
    为是什么还是不行呢?