您的位置:首页 > 其它

升级基于ATL3.0的项目到ATL7.0(VC6.0 to VS2008)[移植变更点]

2012-03-16 09:44 465 查看
ATL3.0与7.0在实现细节方面改变比较多,其中对原来的模版类进行了拆分,实现更为细致。同时,从VC6移过来的程序,为了保证其后的兼容性,如果不是Unicode,最好在本次升级中一步到位。
具体变更:

MyCom程序

ATL 3.0(VC6.0 / ANSI)

ATL 7.0 (Unicode)

主线程文件: class CMyComApp

MyCom.cpp中实现:

在dllmian.cpp中实现;

涉及到主线程相关的函数都在此实现;

Dll注册函数:

DllRegisterServer

DllGetClassObject

MyCom.cpp中实现:

MyCom.cpp中实现;(该文件中只剩下注册相关的操作)

CComModule

ATL 3.0 提供了 CComModule 类。

CComModule _module;

在 ATL 7.0 中,以前由 CComModule 提供的功能由若干新类处理:

关于句柄相关:

使用CAtlBaseModulet替换:

关于DLL注册相关:

使用CMyComModule:继承自CAtlDllModuleT

获取句柄

_Module.GetModuleInstance()

_AtlBaseModule.GetModuleInstance() (引用:在altcore.h:extern CAtlBaseModule _AtlBaseModule;

LPCSTR-》CString

直接赋值

LPCSTR str;

CString s = CString(str);

字符串CString赋值

CString section = "IBECOM";

CString section = _T("IBECOM");

字符串、函数在unicode下的改变:

Char drive[_MAX_DRIVE];

_splitpath( strFileName, drive, dir, fname, ext );

使用unicode,则相应的字符串变量申明都改为宽字符:

wchar_t drive[_MAX_DRIVE];

同样,使用对应的宽字符函数:

_wsplitpath(strFileName, drive, dir, fname, ext );

字符串转换:

CString->LPSTR

Cstring str; // ansi环境string

LPSTR ls = str;

CString str;// unicode环境string

LPSTR ls = new char[str.GetLength()+1];

USES_CONVERSION;

lps = W2A(str);

当然,如果在源头都改为char_t更好,也就避免了这样的转换。

更多细节请参考:http://msdn.microsoft.com/zh-cn/library/w1sc4t4k.aspx

OVER

转自:http://blog.donews.com/me1105/archive/2010/11/26/49.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: