大家知道MOBIL5.0開始,EVC4開發的工程就無法進行DEBUG了,而必須使用VS.NET2005中的VC++來實現。但是以前我們費了很大心力做成的項目,也不能重新來寫。今天通過一上午的研究,將轉化方法貼出來和大家共勉。 這裡我們以DIALOG BASED工程為例。首先用EVC4建立一個DIALOG BASED的POCKET PC 2003工程。此工程名我們暫訂為TXDEMO。我們也可以在對話方塊放置一個BUTTON,在單擊事件裡,添加AfxMessageBox(L”Test”); 以便升級到VS.NET 2005後,測試資源對應情況。 此時,儲存TXDEMO工程,並關閉掉EVC4開發工具。此時用VS.NET 2005開啟TXDEMO.VCW工程,並接受轉換請求。此時並將編譯環境切換到Windows Mobile 5.0 pocket pc sdk。編譯工程,此時會提示如下錯誤: 1>C: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)”。即可解決此問題。 接著編譯工程,此時會提示如下錯誤:1>.TXDEMO.rc(170) : fatal error RC1015: cannot open include file 'wceres.rc'. 這裡我們需要在TXDEMO.RC檔案裡,將#include "wceres.rc"注釋掉。//#include "wceres.rc" // WCE-specific components 接著編譯工程,此時會提示如下錯誤:1>corelibc.lib(wwinmain.obj) : error LNK2019: unresolved external symbol wWinMain referenced in function wWinMainCRTStartup1>Windows Mobile 5.0 Pocket PC SDK (ARMV4I)Debug/TXDEMO.exe : fatal error LNK1120: 1 unresolved externals此時,我們依舊開啟project properties對話方塊,切換到Linker->Advanced頁,將Entry Point由wWinMainCRTStartup改成WinMainCRTStartup。 此時再次編譯,系統不在提示錯誤,但是編譯好的程式,還不能在模擬器或者MOBILE5.0 POCKET PC的機器上運行。 我們接著設定項目屬性,在Configuration Properties->Gengeral頁將Use of MFC ,改成靜態串連。 此時我們運行程式 ,您會發現程式啟動後,就立刻退去。經過我的研究,發現是載入對話方塊資源失敗,在此我們再此開啟TXDEMO.RC源檔案,找到IDD_TXDEMO_DIALOG DIALOG DISCARDABLE 0, 0, 130, 90語句,將下面的表單內容改成如下,即可。WS_POPUP | WS_VISIBLE | WS_CAPTION此時,再次編譯工程,你可以進行DEBUG並可以運行程式。這是我對EVC4升級到VS.NET 2005一點總結,其中參考了MSDN中一些文檔,但是MSDN說的還不夠詳細,通過我自己的研究,總結出一點經驗,希望能給大家帶來方便,謝謝。另外。。。。。。。。也談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 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 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 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。
這樣,程式基本移植完成,但是還要把所有的功能過一遍,有可能還會碰到,諸如對話方塊出現亂碼、菜單不對等問題。