• 全部
  • VC综合技术
  • 互联网技术
  • MFC AppLauncher
  • .NET 技术
  • 界面
  • 进程
  • 算法
  • 硬件/系统
  • 数据库
  • VC++技术资源

为什么有这样的警告?

uk 2001-07-24 05:30:43
我的MFC应用程序在用(use mfc in statics)静态连接编译的时候有大量的类似以下的警告:
class 'CString' needs to have dll-interface to be used by clients of class 'CWdsInfo'
为什么?是我的编译选项有问题吗?
...全文
69 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ShyWJB 2001-07-25
你一定是在DLL中定义的类中定义了CString变量,CString类并没有定义过输出,因此会出现上述警告,详情可查看相应文章
PRB: C4251 & C4275 Compiler Warnings While Compiling an AFXDLL
Last reviewed: July 31, 1997
Article ID: Q134980
2.00 2.10 2.20 WINDOWS NT kbprg kberrmsg kbprb
The information in this article applies to:

The Microsoft Foundation Classes (MFC) included with: Microsoft Visual C++, 32-bit Edition, versions 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 INFORMATION


Sample 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.


回复
widewave 2001-07-25
CString类只能动态连接!
回复
wjyasd 2001-07-24
???

选择的什么工作空间?或者在其它的方式下正常吗?
回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2001-07-24 05:30
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……