0

I am trying to porting an old project from VS2008 to VS2015. This project use MFC and I have a compiling version but it's throwing an exception during InitInstance method, more precisly when there is the call to UpdateWindow. The exception is of read access violation type. Here in details (comments are in italian):

BOOL CMyAppApp::InitInstance()
{
    // InitCommonControlsEx() è necessario in Windows XP se nel manifesto
    // di un'applicazione è specificato l'utilizzo di ComCtl32.dll versione 6 o successiva per attivare
    // gli stili visuali. In caso contrario, non sarà possibile creare finestre.
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    // Effettuare questa impostazione in modo da includere tutte le classi di controlli comuni da utilizzare
    // nell'applicazione.
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);

    CWinAppEx::InitInstance();

    // Inizializzare le librerie OLE.
    if (!AfxOleInit())
    {
        AfxMessageBox(IDP_OLE_INIT_FAILED);
        return FALSE;
    }
    AfxEnableControlContainer();
    // Inizializzazione standard
    // Se non si utilizzano queste funzionalità e si desidera ridurre la dimensione
    // dell'eseguibile finale, è necessario rimuovere dal seguente codice
    // le specifiche routine di inizializzazione che non sono necessarie.
    // Modificare la chiave del Registro di sistema in cui sono memorizzate le impostazioni
    // TODO: è necessario modificare questa stringa in modo appropriato,
    // inserendo ad esempio il nome della società o dell'organizzazione.
    SetRegistryKey(_T("Applicazioni locali generate tramite la Creazione guidata applicazioni"));
    LoadStdProfileSettings(0);  // Caricare le opzioni del file INI standard (inclusa MRU).

    InitContextMenuManager();

    InitKeyboardManager();

    InitTooltipManager();
    CMFCToolTipInfo ttParams;
    ttParams.m_bVislManagerTheme = TRUE;
    theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
        RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);

    // Registrare i modelli di documenti dell'applicazione. I modelli di documenti
    //  funzionano da connessione tra documenti, finestre cornice e viste.
    CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
        IDR_MAINFRAME,
        RUNTIME_CLASS(CMyAppDoc),
        RUNTIME_CLASS(CMainFrame),       // finestra cornice SDI principale
        RUNTIME_CLASS(CMyAppView));
    if (!pDocTemplate)
        return FALSE;
    AddDocTemplate(pDocTemplate);
            
    // Analizzare la riga di comando per i comandi shell standard, DDE, apri file
    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo);      

    // Invia i comandi specificati nella riga di comando. Restituisce FALSE se
    // l'applicazione è stata avviata con l'opzione /RegServer, /Register, /Unregserver o /Unregister.
    if (!ProcessShellCommand(cmdInfo))
        return FALSE;
    
    // L'unica e sola finestra è stata inizializzata, quindi è possibile visualizzarla e aggiornarla.
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->SetWindowTextW(_T("MyApp"));
    m_pMainWnd->UpdateWindow();
    
    // richiamare DragAcceptFiles solo se è presente un suffisso.
    //  In un'applicazione SDI questo deve verificarsi dopo ProcessShellCommand.
    return TRUE;
}

The stack report the violation at mfc140ud.dll!CMFCToolBarImages::SmoothResize(double dblImageScale) with message: Exception thrown: read access violation. pRowSrc2 was 0x6439008.

I've start a new proj using MFC directly in VS2015 to see the difference and befor CCommandLineInfo cmdInfo; there is this:

// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
{
    delete pMainFrame;
    return FALSE;
}
m_pMainWnd = pMainFrame;

but even if I added this in MyApp it doesn't work.

If I comment m_pMainWnd->UpdateWindow() the same exception of type read access violation is throw. The stack is stopped at mfc140ud.dll!CMFCToolBarImages::SmoothResize(double dblImageScale)

I have tried in another two pc's. In one I'have the same problem and in he other one there is not problem so I thought it is a stuff about redistributable o something else similar. In the working machine the vc++'s version installed is 14.0.24215 while in my machine was 14.2930133 so I has removed It and I has installed vc++'s version 14.23026 but this doesn't resolved the problem.

I am new on MFCs and I have not found useful tips on web and I don't know how to intervene.

Thanks for all who spend time for me.

GiaMat45
  • 55
  • 7
  • 2
    The debugger will display the call stack at the point the exception is raised. That's vital information in diagnosing the issue. Either use it yourself, or post it in your question if you need someone else to have a look. – IInspectable Sep 15 '21 at 14:28
  • @IInspectable it is raised at mfc140ud.dll!CMFCToolBarImages::SmoothResize(double dblImageScale). If I try to doble click it vs tell me that afxtoolbarimages.cpp not found. The last call stack that I can see is mfc140ud.dll!CWnd::UpdateWindow() Line 106. The code at that line is this: '_AFXWIN_INLINE void CWnd::UpdateWindow() { ASSERT(::IsWindow(m_hWnd)); ::UpdateWindow(m_hWnd); }' – GiaMat45 Sep 15 '21 at 15:07
  • What happens if you comment out the call to `m_pMainWnd->UpdateWindow();`? – 500 - Internal Server Error Sep 15 '21 at 15:11
  • Another exception of type read access violation is throw. This time at this call stack: mfc140ud.dll!CDockSite::RepositionPanes(CRect & rectNewClientArea), the corrispondent code is `pNextRow->RepositionPanes(rectNewClientArea, WMSZ_RIGHT, nHorzOffset > 0, abs(nHorzOffset));` of course pNextRow is not null – GiaMat45 Sep 15 '21 at 15:21
  • @GiaMat45 please [edit] your question and put all relevant information _there_. – Jabberwocky Sep 17 '21 at 06:59
  • @Jabberwocky I've just done it. Thanks all of you for the help – GiaMat45 Sep 17 '21 at 08:49
  • I have news. I have tried in another two pc's. In one I'have the same problem and in he other one there is not problem so I thought it is a stuff about redistributable o something else similar. In the working machine the vc++'s version installed is 14.0.24215 while in my machine was 14.2930133 so I has removed It and I has installed vc++'s version 14.23026 but this doesn't resolved the problem. – GiaMat45 Sep 21 '21 at 09:09

0 Answers0