I'm using VC++ 2008 with Window XP Professional.
I'm trying to make a custom assert function, which presents a dialog box asking what the user wants to do about the assert.
When I call DialogBox, it shows my dialog properly, but every subsequent call to that function appears to do nothing, as in, the dialog doesn't show up, without any warnings or errors(that i know of).
dictionary_t is my implementation of std::map.
IDL_FILE is the label which indicates the file in which the assert is
IDL_LINE is the label indicating the line of the assert
IDL_ASSERT is the expression which failed, causing the assert
This is my code:
char *assert_file, *assert_line, *assert_exp;
bool assert_ignoreall = false;
bool assert_break = false;
dictionary_t<char*, bool> assert_ignorefiles;
dictionary_t<char*, int> assert_ignoretimes;
dictionary_t<char*, bool> assert_ignorethisassert;
dictionary_t<char*, bool> assert_alwaysignore;
BOOL CALLBACK AssertDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
{
SetDlgItemText(hwnd, IDL_FILE, assert_file);
SetDlgItemText(hwnd, IDL_LINE, assert_line);
SetDlgItemText(hwnd, IDL_ASSERT, assert_exp);
for(dictionary_t<char*,int>::iterator it = assert_ignoretimes.begin();
it != assert_ignoretimes.end(); it++)
{
if(!Q_strcmp(it->key, assert_exp))
{
if(it->value > 0)
{
it->value -= 1;
PostQuitMessage(0);
return TRUE;
}
}
}
for(dictionary_t<char*, bool>::iterator it = assert_alwaysignore.begin();
it != assert_alwaysignore.end(); it++)
{
if(!Q_strcmp(it->key, assert_exp))
{
if(it->value)
{
PostQuitMessage(0);
return TRUE;
}
}
}
for(dictionary_t<char*, bool>::iterator it = assert_alwaysignore.begin();
it != assert_alwaysignore.end(); it++)
{
if(!Q_strcmp(it->key, assert_file))
{
PostQuitMessage(0);
return TRUE;
}
}
}
return FALSE;
case WM_CLOSE:
DestroyWindow(hwnd);
return TRUE;
case WM_DESTROY:
PostQuitMessage(0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDB_BREAKINDEBUGGER:
assert_break = true;
PostQuitMessage(0);
return TRUE;
case IDB_IGNORETHISASSERT:
{
int res;
int val = GetDlgItemInt(hwnd, IDT_TIMES, &res, true);
if(!res)
{
PostQuitMessage(0);
return TRUE;
}
assert_ignoretimes[assert_exp] = val;
}
PostQuitMessage(0);
return TRUE;
case IDB_ALWAYSIGNORE:
assert_alwaysignore[assert_exp] = true;
PostQuitMessage(0);
return TRUE;
case IDB_IGNOREASSERTSINFILE:
assert_ignorefiles[assert_file] = true;
PostQuitMessage(0);
return TRUE;
case IDB_IGNOREALLASSERTS:
assert_ignoreall = true;
PostQuitMessage(0);
return TRUE;
}
return FALSE;
default:
return FALSE;
}
return FALSE;
}
void _Assert(const char *file, int line, const char *expression)
{
char tempbuf[1024];
_itoa_s(line, tempbuf, 1024, 10);
assert_file = (char*)file;
assert_line = tempbuf;
assert_exp = (char*)expression;
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ASSERT), NULL, AssertDlgProc);
if(assert_break)
{
DebugBreak();
assert_break = false;
}
}