2014-04-18 49 views
0

我正在將一些Windows應用程序(遺留代碼)從VC 6升級到VS2010。大多數應用程序已編譯並在清除預期的轉換錯誤後運行,但我遇到了很多麻煩。這裏是LoadFrame()失敗並且應用程序退出的地方。返回這裏的錯誤是0窗口創建失敗 - LoadFrame(IDR_MAINFRAME)失敗C++

 CMainFrame* pMainFrame = new CMainFrame;// Create main MDI Frame window 
    if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) 
     DWORD err = GetLastError(); 
    return FALSE; 

這裏是從上面的LoadFrame()函數:(pParentWnd和pContext都空在進入功能和我不明白爲什麼?)

BOOL CMDIFrameWnd::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, 
CWnd* pParentWnd, CCreateContext* pContext) 
{ 
    if (!CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, 
     pParentWnd, pContext)) 
     return FALSE; 

    // save menu to use when no active MDI child window is present 
    ASSERT(m_hWnd != NULL); 
    m_hMenuDefault = ::GetMenu(m_hWnd); 
    return TRUE; 
} 

在遍歷LoadFrame並檢查創建方法後,我發現這是錯誤發生在這裏的地方:HWND hWnd = :: AfxCtxCreateWindowEx(..)我注意到cs.hwndParent和cs.hMenu都顯示這個錯誤「未使用= CXX0030:錯誤:無法評估表達式「。我知道這個錯誤可能意味着表達式指的是程序地址空間之外的內存,但我不認爲這是問題。我已經看到其他類似於此的問題,但沒有任何東西幫助我理解問題。

BOOL CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName, 
LPCTSTR lpszWindowName, DWORD dwStyle, 
int x, int y, int nWidth, int nHeight, 
HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam) 
{ 
    ASSERT(lpszClassName == NULL || AfxIsValidString(lpszClassName) || 
     AfxIsValidAtom(lpszClassName)); 
    ENSURE_ARG(lpszWindowName == NULL || AfxIsValidString(lpszWindowName)); 

    // allow modification of several common create parameters 
    CREATESTRUCT cs; 
    cs.dwExStyle = dwExStyle; 
    cs.lpszClass = lpszClassName; 
    cs.lpszName = lpszWindowName; 
    cs.style = dwStyle; 
    cs.x = x; 
    cs.y = y; 
    cs.cx = nWidth; 
    cs.cy = nHeight; 
    cs.hwndParent = hWndParent; 
    cs.hMenu = nIDorHMenu; 
    cs.hInstance = AfxGetInstanceHandle(); 
    cs.lpCreateParams = lpParam; 

    if (!PreCreateWindow(cs)) 
    { 
     PostNcDestroy(); 
     return FALSE; 
    } 

AfxHookWindowCreate(this); 
HWND hWnd = ::AfxCtxCreateWindowEx(cs.dwExStyle, cs.lpszClass, 
     cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy, 
     cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams); // RMC here's the error 

GetLastError()); 
DWORD err = GetLastError(); 

#ifdef _DEBUG 
if (hWnd == NULL) 
{ 
    TRACE(traceAppMsg, 0, "Warning: Window creation failed: GetLastError returns 0x%8.8X\n", 
     GetLastError()); 
} 

該問題源自父窗口和上下文爲空的LoadFrame()。爲什麼他們是「空/ ???」? (此應用程序在VC 6中運行良好,因此必須是升級的結果)如果有人看到此問題或有任何可能啓發我的信息,我將非常感激。提前致謝。

+0

如果我理解正確,那麼您是說這是內部MFC庫代碼失敗。這真的很奇怪。我的第一個想法是,你的環境存在嚴重問題。你可以創建並構建一個* new *應用程序,而無需遷移任何東西? –

+0

前段時間我有些類似的問題,當將應用程序從VC6升級到VS2010後,我的打印預覽不起作用,它會崩潰。我發現MFC打印預覽的內部已經改變,導致崩潰。我記得我不得不開動自己的打印預覽窗口來解決這個問題,我爲此感到非常自豪。所以我建議將VS2010的MFC框架功能與VC6的框架功能進行比較,並注意相應的改變和計劃。 – zar

+0

查看'CMainFrame :: OnCreate()'來查看是否有任何子組件無法創建並返回-1。 – user1793036

回答

0

事實證明,我的庫路徑(鏈接器 - >附加依賴關係)包含一個支持與MDI(多文檔界面)相對的SDI(單文檔界面)的庫。除此之外,用於MDI的庫是舊版本(VC6),它不支持在Visual Studio 2010中使用的新MDI方法。