My application will pop up the warning dialog with description below when running on Windows 7 Japan Version in debug mode using Visual Studio 2010:
"Windows has triggered a breakpoint in myprogram.exe.
This may be due to a corruption of the heap, which indicates a bug in myprogram.exe or any of the DLLs it has loaded.
This may also due to the user pressing F12 while myprogram.exe has focus.
The output windows may have more diagnostic information."
However, this error will not happen if I run my application on Windows 7 English Edition. It is running fine.
When I drill down to have a look, I think the DoModal() function is causing the problem.
Snippet of my code program:
Code:
CMyDIalog dlg;
dlg.DoModal(); //after executing this, the error happen.
The breakpoint happen at code below for dlgcore.cpp:
Code:
// create modeless dialog
AfxHookWindowCreate(this);//i think after calling this, the error happen
hWnd = ::CreateDialogIndirect(hInst, lpDialogTemplate,
pParentWnd->GetSafeHwnd(), AfxDlgProc);
This make me wonder why this issue only happen on Windows 7 OS Japan version but not the English version. I did not press F12 while running my program also.
Any idea how to debug this problem further?
Attached files Break01.png and Break02.png are the screenshot of my errors.
Last edited by PHChang; May 14th, 2016 at 08:54 AM.
Reason: Uploaded clearer screenshot in zip file
...
This make me wonder why this issue only happen on Windows 7 OS Japan version but not the English version. I did not press F12 while running my program also.
Any idea how to debug this problem further?
Attached files ... are the screenshot of my errors.
Well, your "screenshots" are too small to be understandable.
What is the return value of CreateDialogIndirect?
If it is NULL, then what does the GetLastError return?
Sorry for the blur sceenshots, anyway I already attached in the break.zip earlier.
What is the return value of CreateDialogIndirect?
I am not too sure what is the value actually because after executing line 2 (I actually set a breakpoint at line 2) the warning dialog "Windows has triggered a breakpoint in myprogram.exe....." prompt out.
Code:
// create modeless dialog
AfxHookWindowCreate(this); //line 1
hWnd = ::CreateDialogIndirect(hInst, lpDialogTemplate, pParentWnd->GetSafeHwnd(), AfxDlgProc); //line 2, the warning dialog prompt out after executing this line
#ifdef _DEBUG
dwError = ::GetLastError(); //line 3
After that, I click the "Break" button from the dialog.
The values became as follow at watch window:
Name Value
hWnd 0x001103c8{unused=76}
dwError 0
GetLastError return 0 in this case.
Attached is the screenshot of the values.
I tried step to the code line by line on my dialog OnInitDialog, it looks fine to me and it didn't trigger the breakpoint.
Code:
BOOL CMyDialog::OnInitDialog()
{
........
}
//dlgcore.cpp
Code:
INT_PTR CALLBACK AfxDlgProc(HWND hWnd, UINT message, WPARAM, LPARAM)
{
if (message == WM_INITDIALOG)
{
// special case for WM_INITDIALOG
CDialog* pDlg = DYNAMIC_DOWNCAST(CDialog, CWnd::FromHandlePermanent(hWnd));
if (pDlg != NULL)
return pDlg->OnInitDialog();
else
return 1;
}
return 0;
}
pDlg->OnInitDialog() return value is 0
The breakpoint only get triggered after executing the CreateDialogIndirect(...) line at dlgcore.cpp
So I still don't understand why the breakpoint get trigger here.
I tried step to the code line by line on my dialog OnInitDialog, it looks fine to me and it didn't trigger the breakpoint.
...
//dlgcore.cpp
Code:
INT_PTR CALLBACK AfxDlgProc(HWND hWnd, UINT message, WPARAM, LPARAM)
{
if (message == WM_INITDIALOG)
{
// special case for WM_INITDIALOG
CDialog* pDlg = DYNAMIC_DOWNCAST(CDialog, CWnd::FromHandlePermanent(hWnd));
if (pDlg != NULL)
return pDlg->OnInitDialog();
else
return 1;
}
return 0;
}
(b)
Originally Posted by PHChang
...
pDlg->OnInitDialog() return value is 0
Well, (a) contradicts (b). Isn't it?
Originally Posted by PHChang
...
The breakpoint only get triggered after executing the CreateDialogIndirect(...) line at dlgcore.cpp
So I still don't understand why the breakpoint get trigger here.
How did you start the executing: with the debugger (F5) or not?
Sorry, I don't get what you said it contradict each other.
Because when I saw at the Autos watch window,the value are as follow:
Name | Value
CMyDialog::OnInitDialog return | 0
So if my understanding is correct pDlg->OnInitDialog() return value is 0 based on the watch window. Do correct me if I am wrong.
I have attached the screenshot in zip file. (My image always get resize after uploaded and become blur so I zip the image inside instead)
How did you start the executing: with the debugger (F5) or not?
Yes, I started the executing by pressing F5 debugger.
When I say "The breakpoint only get triggered" , I actually meant the warning dialog "The breakpoint only get triggered" prompt out.
So if my understanding is correct pDlg->OnInitDialog() return value is 0 based on the watch window. Do correct me if I am wrong.
I have attached the screenshot in zip file. (My image always get resize after uploaded and become blur so I zip the image inside instead)
Yes, I started the executing by pressing F5 debugger.
When I say "The breakpoint only get triggered" , I actually meant the warning dialog "The breakpoint only get triggered" prompt out.
But, being on the line
Code:
return pDlg->OnInitDialog();
did you try to press F11 to step in the code of CMyDialog::OnInitDialog (or CDialog::OnInitDialog)?
did you try to press F11 to step in the code of CMyDialog::OnInitDialog (or CDialog::OnInitDialog)?
Yes, I did step through the code but it did not trigger the warning dialog "Breakpoint was trigger".
Code:
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog(); //already step through this line and no warning dialog prompt out
//my code
........
//my code end
return FALSE;
}
I am still cannot find the abnormalities that cause this.
The heap may be corrupted, this is what the message box tells you. So you'd better start looking in your code for wild pointers, stack corruption, buffer overruns and other nice things like that. Try to disable some code fragments and see if that helps your dialog box to show up.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.