I am stumped so far by this one. Any MFC experts out there?
I had a working C++ MFC application. It's supposed to just bring up a dialog, then do other things.
I can run the EXE
but I have a problem when I run it under the debugger...
My application has a bitmap (in "logo.bmp") that it displays in its dialog. I wanted to update what it shows, so, with the IDE not running, I renamed the existing file to "old-logo.bmp", copied a new file in that "res" folder with the name "new-logo.bmp", and made a copy of the new image and called it "logo.bmp".
I was not very careful to make sure that the DPI, width and height were the same as the original file; in retrospect, I observe that the bit depth was the same but the dimensions were different (old: 445x106, new: 445x123).
I brought up the IDE (Visual Studio 2022 Community, version 17.5) and the application compiled without any errors and without any new warnings.
I thought I was OK. I started it up in the debugger and immediately got an exception:
Exception thrown at 0x727C8B96 (comctl32.dll) in mywindow.exe: 0xC0000005: Access violation writing location 0x00BA4114.
I found that the call stack was something like this:
CMyWindowApp::InitInstance() ->
CMyDialog::DoModal() ->
// ... windows stuff ...
CMyDialog::OnInitDialog() -> CPropertySheet::OnInitDialog()
In that last call I get the exception.
Here's something strange: if I hit continue, then the application starts up normally - except it does not show any bitmap at all in the expected region of the dialog.
I tried restoring the "res" folder to its prior set of files: I still get the same exception.
I created a new workspace from prior files and I still get the same error!
I rolled back VS2022 to a prior version (I had the latest which I think was 17.5.5 - I rolled it back to 17.5.0) - still the same error.
I don't get it. The application doesn't even load the image until they call its OnPaint() or ResizeSheet() member functions (neither of which is getting called yet - I've got breakpoints on them).
I'm wondering whether there's some cache for VS2022 that is stored centrally, that I messed up by switching the .bmp file manually (I will never, never do that again!), that I might be able to clobber so it gets rebuilt.
I'm stumped. Any ideas, mates?
Relevant Code
in MyWindow.cpp:
// MyWindow.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "afxvisualmanager.h" // to clean up instance allocated by others
#include "MyWindow.h"
#include "MyDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
const COleDateTime CExporterApp::m_StarterCard(2037, 12, 31, 0, 0, 0);
// CMyWindowApp
BEGIN_MESSAGE_MAP(CMyWindowApp, CWinApp)
// ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CMyWindowApp construction
CMyWindowApp::CMyWindowApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
CMyWindowApp::~CMyWindowApp()
{
// To make sure base class destructor is getting called.
}
// The one and only CMyWindowApp object
CMyWindowApp theApp;
BOOL CMyWindowApp::InitInstance()
{
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
CMyDialog sht;
INT_PTR nResponse = sht.DoModal();
// stuff we never get to...
}
in MyDialog.cpp:
// MyDialog.cpp : implementation file
//
#include "stdafx.h"
#include "MyWindow.h"
#include "MyDialog.h"
#include "bitmap.h"
// ... some other application-specific includes ...
// CMyDialog
const COLORREF CMyDialog::m_dwBkColor = RGB(246, 243, 234);
IMPLEMENT_DYNAMIC(CMyDialog, CPropertySheet)
CMyDialog::CMyDialog()
:CPropertySheet()
{
EnableStackedTabs(FALSE);
m_wndbkBrush.CreateSolidBrush(m_dwBkColor); // background brush.
m_Page1.SetBackgroundColor(m_dwBkColor);
AddPage(&m_Page1);
}
CMyDialog::CMyDialog(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
}
CMyDialog::CMyDialog(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
}
CMyDialog::~CMyDialog()
{
m_wndbkBrush.DeleteObject(); // Unload background brush.
}
void CMyDialog::OnDestroy()
{
CPropertySheet::OnDestroy();
m_TabCtrl.UnsubclassWindow();
}
BEGIN_MESSAGE_MAP(CMyDialog, CPropertySheet)
//{{AFX_MSG_MAP(CMyDialog)
//}}AFX_MSG_MAP
//ON_COMMAND(ID_APPLY_NOW, OnApplyNow)
ON_WM_PAINT()
ON_WM_CTLCOLOR()
ON_WM_ERASEBKGND()
ON_BN_CLICKED(IDOK, OnOK)
ON_BN_CLICKED(IDCANCEL, OnCancel)
ON_WM_DESTROY()
ON_MESSAGE(WM_DEVICECHANGE, OnDeviceChange)
ON_MESSAGE(WM_SETACTIVEPAGE, OnSetActivePage)
ON_WM_SYSCOMMAND()
END_MESSAGE_MAP()
// CMyDialog message handlers
BOOL CMyDialog::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();
// other stuff we don't reach - we hit the exception in the call above...
)
// other stuff