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.