解决不能从 WTL::CString 转换为 ATL::CSimpleString & 的问题

xingyun86 2017-8-1 1887

WTL提供的CString类在ATL中也提供了相同的类后变得有点鸡肋,并且使用WTL::CString类后,经常会出现标题所示的编译错误。

实际上ATL不仅在<atlstr.h>中提供了CString类,还在<atltypes.h>中提供了CPoint、CSize和CRect类,因此,WTL中提供的同名类变得可有可无。

我认为还是用ATL中的类会好一些,毕竟WTL没有文档嘛。

因此,应该在工程头文件中包含任何WTL头文件前定义以下两行(这两句是关键):

#define _WTL_NO_CSTRING
#define _WTL_NO_WTYPES

典型的声明顺序应该这样:

#include <atlbase.h>
#include <atlapp.h>

extern CAppModule _Module;

#include <atlwin.h>
#include <atlcrack.h>
#include <atlsplit.h>
#include <atlframe.h>
#include <atlgdi.h>
#include <atlctrls.h>
#include <atlctrlx.h>

#include <atlstr.h>
#include <atltypes.h>

#include <atlmisc.h>

以后再也不用担心声明顺序的问题了


×
打赏作者
最新回复 (0)
只看楼主
全部楼主
返回