談談EVC工程移植

本文是針對作者本人的一個具體的移植項目,將碰到的所有問題列出來,並給出具體的解決方法。由於是一個具體的項目,因此不能把所有的EVC工程移植問題囊括進來。所以,在移植項目前,建議還是看看以下的文章:
循序漸進:將 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 Files/Microsoft Visual Studio 8/VC/ce/atlmfc/include/afxver_.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 void OnHotLinkExplain();  --- 〉
afx_msg LRESULT OnHotLinkExplain(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 Files/Microsoft Visual Studio 8/VC/ce/atlmfc/include/afxext.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。

      這樣,程序基本移植完成,但是還要把所有的功能過一遍,有可能還會碰到,諸如對話框出現亂碼、菜單不對等問題。

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