vc6.0工程移植vs2010

最近移植了工程,總結一下遇到的一些修改:
1、error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended.

在StdAfx.h 文件中
改:#define _WIN32_WINNT 0x0501 //0x0400

2、error C2065: ‘i’ : undeclared identifiere

VC編譯器允許出現
for(int i = 0; ; i++)
{
}
i = 0; //此處在vs2010會報錯誤
解決辦法:
int i;在此處定義變量,如此作用域便於原先的一致,
for(i = 0; ; i++)
{
}
i = 0;
注意的是有的會在結尾用來判斷
例如:
for(int i = 0; i < count ; i++){
}
if(i == count){
}

3、if (!CMiniFrameWnd::CreateEx(dwExStyle, NULL, &afxChNil, dwStyle, rectDefault, pParent))
Error 2 error C2065: ‘afxChNil’ : undeclared identifiere
afxChNil 在新的MFC不兼容,網上的解決方案是 改爲NULL

4、error C2664: ‘MultiByteToWideChar’ : cannot convert parameter 5 from ‘WORD [260]’ to ‘LPWSTR’
1)加強制轉換(LPWSTR), LPWSTR 是 wchar_t, WORD 是 unsigned short
2)根據編譯器有個開關 trait wchar_t as build-in type, 打開的話 unsigned short 和 wchar_t 不一樣的類型,wchar_t變成了內建類型,關掉開關解決;2)wchar_t 這裏是16位的,即使在某些平臺變成32位,16位擴到32位並不會有損失,於是可以不關開關,將unsigned short強制轉爲wchar_t也可以;
在這裏插入圖片描述
5、error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
VC6.0支持未定義類型的默認爲 int型,vs2010不支持, 加上類型即可,最好是默認的int 型,當然要根據代碼邏輯修改

6、error C2668: ‘pow’ : ambiguous call to overloaded function
pow函數在新版本中有不同的參數類型,根據函數原型加上強制類型轉換即可;

7、error C2440: ‘static_cast’ : cannot convert from ‘UINT (__thiscall CSizingControlBar:: * )(CPoint)’ to ‘LRESULT (__thiscall CWnd:: * )(CPoint)’
定位:ON_WM_NCHITTEST()
UINT CCoolBar::OnNcHitTest(CPoint point)
改爲:LRESULT CCoolBar::OnNcHitTest(CPoint point)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章