evc4工程移植vs.net2005所碰到的问题积累
收集自網絡]
原文:http://hi.baidu.com/copperlee/blog/item/c5c7abdc2a5f9fa3cc116638.html
在移植項目前,建議還是看看以下的文章:
循序漸進:將 eMbedded Visual C++ 應用程序遷移到 Visual Studio 2005
eMbedded Visual C++ 到 Visual Studio 2005 升級向導(注意其最后一句話:默認情況下,Embedded Visual C++ 4.0 版會將 MFC Pocket PC 應用程序的對話框樣式(Border)設置為 DS_MODALFRAME。MFC 8.0 不支持此樣式。 —— 應改為Thin,如果不改的話,窗口就無法彈出。)
從 eVC 移植所帶來的已知問題
Migrating Microsoft eMbedded Visual C++ Projects to Visual Studio 2005
????????? 開發環境:Windows XP +SP2, Visual Studio 2005 professional, Windows Mobile 6.0 Professional SDK。
注:(1)對于Windows Mobile 5.0 SDK 開發的程序在Windows Mobile 6.0 下也能運行,而且不需要對程序進行任何的修改。
??????? (2)由于有些錯誤,是環境配置問題,所以在Debug/Resease模式下,都需要進行修改,以下錯誤中,如果是這類錯誤,都在標號后面寫著“Resealse 模式也需要改”,當天切換到別的SDK下,如Windows Mobile 5.0 SDK,也需要修改。
??????? 以下是針對Debug模式下的:
1、StdAfx.cpp (Resealse 模式也需要改)
編譯錯誤:D:Program FilesMicrosoft Visual Studio 8VCceatlmfcincludeafxver_.h(77) : fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds
解決方法:右擊工程名,打開Project properties對話框,切換到C/C++->Code generation頁,將Runtime Libarary 設置成“Multi-threaded DLL(/MD)”,即可解決此問題。
2、編譯錯誤:error C2065: 'i' : undeclared identifier
原因:是由于存在以下的代碼段:
for (int i = 0; i < MAX_LEN; i ++)
{
???? //……
}
for (i = 0; i < MAX_NUM; i ++)
{
????? //……
}
對于evc離開循環后,循環變量仍然有效,并且仍可以使用,但是在VS2005下是不行的,由此可見VS2005對變量的定義與審查更為嚴格,還有就是對數組越界問題也比EVC來的強。
解決方法:(不能完全相信編譯器,也不能把所有的語法檢查都丟給編譯器)
int i = 0;
for (i = 0; i < MAX_LEN; i ++)
{
????? //……
}
for (i = 0; i < MAX_NUM; i ++)
{
?????? //……
}
3、error C2664: '_wcsnicmp' : cannot convert parameter 2 from 'LPWORD' to 'const wchar_t *'
需要強制類型轉換。
4、error C2061: syntax error : identifier 'HELPINFO'
自己增加HELPINFO的類型,增加頭文件HelpInfo.h。
5、error C2146: syntax error : missing ';' before identifier 'm_wndCommandBar'
原因:在Windows Mobile 5.0/6.0 下CCeCommandBar類被CCommandBar替換
解決方法:
CCeCommandBar???? m_wndCommandBar; ---- 〉CCommandBar???? m_wndCommandBar;
6、error C2065: 'NUM_TOOL_TIPS' : undeclared identifier
解決:
//#if defined(_WIN32_WCE_PSPC) && (_WIN32_WCE >= 212)
#define NUM_TOOL_TIPS 8
//#endif
7、error C3861: 'ON_WM_HELPINFO': identifier not found
同 4
8、error C2440: 'static_cast' : cannot convert from 'void (__cdecl CMyAppView::* )(void)' to 'LRESULT (__cdecl CWnd::* )(WPARAM,LPARAM)'None of the functions with this name in scope match the target type
解決方法:
afx_msg voidonHotLinkExplain();??? --- 〉
afx_msg LRESULTonHotLinkExplain(WPARAM wParam,LPARAM lParam);
9、error C2664: 'CSize CDC::GetTextExtent(LPCTSTR,int) const' : cannot convert parameter 1 from 'WORD *' to 'LPCTSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast需要強制轉換
pDC->GetTextExtent(&i, 1).cx);???? ——>
pDC->GetTextExtent((LPCTSTR)&i, 1).cx;
10、error C2039: 'OnHelpInfo' : is not a member of 'CView'
error C2039: 'OnHelpInfo' : is not a member of 'CFrameWnd'
error C2039: 'OnHelpInfo' : is not a member of 'CDialog'
解決方法:用TRUE替換相應的類成員函數OnHelpInfo'
return CView::OnHelpInfo(pHelpInfo); ——> return TRUE;
11、error C2039: 'm_bShowSharedNewButton' : is not a member of 'CCommandBar'
D:Program FilesMicrosoft Visual Studio 8VCceatlmfcincludeafxext.h(557) : see declaration of 'CCommandBar'
解決方法:
直接注釋掉 m_wndCommandBar.m_bShowSharedNewButton = FALSE;
12、MyApp.rc(380) : fatal error RC1015: cannot open include file 'wceres.rc'.
解決方法:
直接注釋掉:#include "wceres.rc"?????????? // WCE-specific components
但是,這個錯誤很討厭,每次你修改資源文件后,都得修改該語句,不知道為什么。
13、Resease 模式下也要修改
error LNK2019: unresolved external symbol SHInitExtraControls referenced in function "protected: __cdecl CMyAppView::CMyAppView(void)" (?? 0CMyAppView@@IAA@XZ)
問題:程序中調用了SHInitExtraControls();
error LNK2019: unresolved external symbol SHSipPreference referenced in function "protected: void __cdecl CMyAppView::OnKillfocusWord(void)" ( OnKillfocusWord@CMyAppView@@IAAXXZ)
問題:程序中調用了SHSipPreference
以上兩個函數都在:Library: aygshell.lib里
解決方法:
工程-->屬性-->Linker -->input -- > Additional Denpendencies :aygshell.lib
14、Resease 模式下也要修改
orelibc.lib(wwinmain.obj) : error LNK2019: unresolved external symbol wWinMain referenced in function wWinMainCRTStartup
屬性—〉Linker—〉Anvanced—〉EntryPoint
將 wWinMainCRTStartup 更改為 WinMainCRTStartup
Entry Point是WinMainCRTStartup(ANSI)或wWinMainCRTStartup(UINCODE),即: ... WinMainCRTStartup 或wWinMainCRTStartup 會調用WinMain 或wWinMain。
15、??? error C3861: 'LoadStdProfileSettings': identifier not found
注釋掉函數 LoadStdProfileSettings;
該函數的具體功能,看MSDN。
???????? BTW:編譯的時候,有可能會出現一些由以上錯誤產生的連鎖錯誤,俗稱“蝴蝶效應”,如error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before ','
error C2143: syntax error : missing ';' before '{'
少了了'{'、'}'、';'等等,把以上的錯誤—主要矛盾解決了,這些錯誤—錯誤矛盾也就迎刃而解了。何況,這個工程是以前在EVC IDE下編譯通過,MS再怎么優化或改進編譯器,也總不可能發生自相矛盾的事情吧,總要考慮兼容性吧,要對自己或公司的前輩有信心!
??????? 到此,已經能夠編譯通過,但是運行的時候,又出現如下的問題:
16、Resease 模式下也要修改
按F5,出現如下的對話框:
解決方法:
右擊工程的屬性—〉General—〉Project Defaults –〉Use MFC :
Use MFC in a shared DLL ——> Use MFC in a static DLL
也正是因為這個,VS2005產生的EXE程序比EVC產生的要大200多k。
??????? 這樣,程序基本移植完成,但是還要把所有的功能過一遍,有可能還會碰到,諸如對話框出現亂碼、菜單不對等問題。
[收集FROM 藍天清水博客]
在將evc4的工程移植到.net2005時會碰到很多問題,以下只是其中我遇到的一些問題的摘錄以及相關的處理結果:
1.首先在將EVC4的工程轉化成.net2005時要將工程的屬性中的c/c++->代碼生成->運行時庫改為:多線程DLL(/MD)
2.在工程的屬性中的鏈接器->高級->入口點改為:WinMainCRTStartup
3.遇到stdafx.cpp
_CE_ACTIVEX was not defined because this Windows CE SDK does not have DCOM.
_CE_ACTIVEX could be caused to be defined by defining _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA, but it is recommended that this be doneonly for single-threaded apps.
_ATL_NO_HOSTING was defined because _CE_ACTIVEX was not defined.
的錯誤:在stdafx.h文件里加上#define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA可解決.
4.遇到StdAfx.cpp??
?????? WINVER????? not????? defined.????? Defaulting????? to????? 0x0501
在工程的屬性c/c++->預處理器->預處理器定義中加上_WIN32_WINNT=0x500試試
Other:
01.error C2061: syntax error : identifier 'CDumpContext'……
VS2005已經不支持CDumpContext。直接廢掉~
02.error C2660: 'CWnd::SetWindowRgn' : function does not take 3 arguments
VS2005下'CWnd::SetWindowRgn' 只有兩個參數
SetWindowRgn(this->m_hWnd,hRgn, TRUE); ----->? SetWindowRgn(hRgn, TRUE);
03.error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const CSection' (or there is no acceptable conversion)
?????????????????????? // C2679.cpp
?????????????????????? class C {
?????????????????????? public:
???????????????????????????????? C();?? // no constructor with an int argument
??????????????????????????????????? } c;
?????????????????????? class D {
?????????????????????? public:
?????????????????????????????????? D(int) {}
?????????????????????????????????? D(){}
?????????????????????????????????? } d;
????????????????????? int main() {
?????????????????????????? c = 10;?? // C2679
?????????????????????????? d = 10;?? // OK
???????????????????????????????????? }
?
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/williamvon/archive/2008/03/24/2212193.aspx
轉載于:https://www.cnblogs.com/lanru/archive/2010/10/27/1862070.html
總結
以上是生活随笔為你收集整理的evc4工程移植vs.net2005所碰到的问题积累的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: openquery基本运用实例
- 下一篇: 光脚丫学LINQ(005):数据表之间的