Unhandled Exception
Hi, I have an MFC dialog based application which compiles without errors, but yields an unhandled exception, when I try to run it. On debugging it points to the following code in C:\...\MFC\SRC\WINCORE.CPP...at the line indicated below:
HWND hWnd = ::GetDlgItem(m_hWnd, nID);
if (hWnd != NULL)
{
int nLen = ::GetWindowTextLength(hWnd);
::GetWindowText(hWnd, rString.GetBufferSetLength(nLen), nLen+1);//exception here
rString.ReleaseBuffer();
}
What could be the cause of this, please? How do I correct this exception?
[576 byte] By [
aaadetos] at [2007-11-19 10:16:56]

# 1 Re: Unhandled Exception
Hi, I have an MFC dialog based application which compiles without errors, but yields an unhandled exception, when I try to run it. On debugging it points to the following code in C:\...\MFC\SRC\WINCORE.CPP...at the line indicated below:
HWND hWnd = ::GetDlgItem(m_hWnd, nID);
if (hWnd != NULL)
{
int nLen = ::GetWindowTextLength(hWnd);
::GetWindowText(hWnd, rString.GetBufferSetLength(nLen), nLen+1);//exception here
rString.ReleaseBuffer();
}
What could be the cause of this, please? How do I correct this exception?
does the hWnd exist? can you post the code that triggers this exception (your code)?
Alin at 2007-11-11 0:12:40 >

# 2 Re: Unhandled Exception
It would really depend on what is calling this core function. Chances are the string pointer is not valid or the window has too much text (probably not possible).
If you have no idea why this is happening, try putting a breakpoint before the suspect lines and step through it. If you are still lost, post your code here and we can take a look.
# 3 Re: Unhandled Exception
The exception almost certainly occurs within GetBufferSetLength (a member of CString). Can you verify this by stepping into it?
There is a method by which you can catch such an exception and print the line number and filename in which it occurred, but it's a little involved. If you get stuck I will explain it to you :-)
Markus
# 4 Re: Unhandled Exception
Hi, Y'all
Thanks for taking the time to look at the code. Its a lil math intense, but the math is ok; the dialog is the problem.
# 5 Re: Unhandled Exception
Hi, Y'all
Thanks for taking the time to look at the code. Its a lil math intense, but the math is ok; the dialog is the problem.
which dialog?
you HAVE to tell us the steps to reproduce the ASSERTION!
Alin at 2007-11-11 0:16:39 >

# 7 Re: Unhandled Exception
Try this:::GetWindowText(hWnd, rString.GetBufferSetLength(nLen+1), nLen+1);//exception here
# 8 Re: Unhandled Exception
your function should look like:
void td(double tD[], CTbshyDlg *pDlg) //returns tD/CD
using this prototype should eliminate those ASSERTS...
Alin at 2007-11-11 0:19:48 >

# 9 Re: Unhandled Exception
Click on 'Analyse'
as I said before, the hWnd is null...
if you would have debuged your code you would have known that this happens when you try to access a member of CTbshyDlg from outside, namely in your "td" function. Maybe there are more functions that access members of CTbshyDlg, this is where the ASSERT occured.
Alin at 2007-11-11 0:20:43 >
