• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1420
  • Last Modified:

Unhandled exception when adding edit box

Hi expert

Once again, I got a problem

My program working properly before I add an edit box on my dialog. I have 3 edit boxes and its running successfully. But when I try to add another edit box, I got this error when running the program

"Unhandled exception at 0x57a9dd8b (mfc90d.dll) in ReTIME.exe: 0xC0000005: Access violation reading location 0x68f8260f."

Then the Visual Studio 2008 workspace show a code with yellow arrow.
Here, part of the code (where yellow arrow was pointing) in altsimpstr.h

      ATL_NOINLINE void Fork( _In_ int nLength )
      {
            CStringData* pOldData = GetData();
            int nOldLength = pOldData->nDataLength;
            CStringData* pNewData = pOldData->pStringMgr->Clone()->Allocate( nLength, sizeof( XCHAR ) );
            if( pNewData == NULL )
            {
                  ThrowMemoryException();
            }
            int nCharsToCopy = ((nOldLength < nLength) ? nOldLength : nLength)+1;  // Copy '\0'
            CopyChars( PXSTR( pNewData->data() ), nCharsToCopy,
                  PCXSTR( pOldData->data() ), nCharsToCopy );
            pNewData->nDataLength = nOldLength;
            pOldData->Release();
            Attach( pNewData );
      }


How to fix it

Thank and Regard
0
khairulzams
Asked:
khairulzams
  • 9
  • 8
  • 3
  • +1
1 Solution
 
AndyAinscowCommented:
Please show your code.




Is the resource ID of the edit box correct?

eg.
if you have only one edit box with the ID IDC_EDIT1 on one dialog but use the following

CString s;
GetDlgItemText(IDC_EDIT2, s);

If IDC_EDIT2 is used on another dialog then there will be no compile time error but there will be a runtime error.
0
 
khairulzamsAuthor Commented:
1. The problem is when I create an edit box with ID name ID_MYLSE_DIMENSION

2. For edit box with ID name IDC_LSEFONAME_MyLSE, it no problem, can running successfully.

Here the code  in source file (FOMyLSE.cpp)

CFOMyLSE::CFOMyLSE()
      : CPropertyPage(CFOMyLSE::IDD)
{
      m_fnamelseMyLSE = _T("");
      m_mylseDimensi = _T("");
      
}

CFOMyLSE::~CFOMyLSE()
{
}

void CFOMyLSE::DoDataExchange(CDataExchange* pDX)
{
      CPropertyPage::DoDataExchange(pDX);
      DDX_Text(pDX, IDC_LSEFONAME_MyLSE, m_fnamelseMyLSE);
      DDX_Text(pDX, IDC_MyLSE_DIMENSION, m_mylseDimensi);
      /
}

and in header file (FOMyLSE.h)
#pragma once
#include "SingleRTSView.h"

// CFOMyLSE dialog

class CFOMyLSE : public CPropertyPage
{
      DECLARE_DYNAMIC(CFOMyLSE)

public:
      CFOMyLSE();
      virtual ~CFOMyLSE();

// Dialog Data
      enum { IDD = IDD_FO_MyLSE };
      CString m_fnamelseMyLSE;
      CString m_mylseDimensi;
      //CString m_MyLSEDimensi;
      //int m_MyLSE1D;
      //int m_MyLSE2D;
      //int m_MyLSE3D;

protected:
      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

      DECLARE_MESSAGE_MAP()
public:
      afx_msg void OnBnClickedRadio1();
      afx_msg void OnBnClickedMylse2d();
      afx_msg void OnBnClickedMylse3d();
};

0
 
AndyAinscowCommented:
1. The problem is when I create an edit box with ID name ID_MYLSE_DIMENSION

DDX_Text(pDX, IDC_MyLSE_DIMENSION, m_mylseDimensi);

is that a typo ?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
khairulzamsAuthor Commented:
no ..i was fix it with all upper case..but still have a same problem
0
 
khairulzamsAuthor Commented:
I also used a default ID name..create a new one with IDC_EDIT2 ...still have that runtime error
0
 
AndyAinscowCommented:
Can you please run the code.  When it crashes show your code which is causing the crash.


I suspect you are attempting to use this editbox before the dialog containing it is created.  
0
 
khairulzamsAuthor Commented:
when it crashed,  
Unhandle.jpg
0
 
AndyAinscowCommented:
That isn't your code - that is from microsoft.


(Odd looks like it is a problem with the string, not the edit box component).


Look at the call stack (bottom right).
Move down there until you find where the code is that you have written.
0
 
khairulzamsAuthor Commented:
sorry andy,..still not get what you want..I am a newbie .. :)

this is all from call stack (bottom right)

>	mfc90d.dll!ATL::CSimpleStringT<char,1>::Fork(int nLength=4355132)  Line 775 + 0xc bytes	C++
 	mfc90d.dll!ATL::CSimpleStringT<char,1>::PrepareWrite2(int nLength=4355132)  Line 812 + 0xc bytes	C++
 	mfc90d.dll!ATL::CSimpleStringT<char,1>::PrepareWrite(int nLength=3)  Line 801	C++
 	mfc90d.dll!ATL::CSimpleStringT<char,1>::Preallocate(int nLength=3)  Line 570	C++
 	mfc90d.dll!ATL::CSimpleStringT<char,1>::GetBufferSetLength(int nLength=3)  Line 527 + 0xc bytes	C++
 	mfc90d.dll!DDX_Text(CDataExchange * pDX=0x0012db68, int nIDC=1092, ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > > & value="$@")  Line 210 + 0x13 bytes	C++
 	ReTIME.exe!CFOMyLSE::DoDataExchange(CDataExchange * pDX=0x0012db68)  Line 29	C++
 	mfc90d.dll!CWnd::UpdateData(int bSaveAndValidate=1)  Line 4018	C++
 	mfc90d.dll!CPropertyPage::OnKillActive()  Line 373 + 0xa bytes	C++
 	mfc90d.dll!CPropertyPage::OnNotify(unsigned int wParam=0, long lParam=1236996, long * pResult=0x0012dcfc)  Line 486 + 0x10 bytes	C++
 	mfc90d.dll!CWnd::OnWndMsg(unsigned int message=78, unsigned int wParam=0, long lParam=1236996, long * pResult=0x0012dd34)  Line 1781 + 0x2a bytes	C++
 	mfc90d.dll!CWnd::WindowProc(unsigned int message=78, unsigned int wParam=0, long lParam=1236996)  Line 1755 + 0x20 bytes	C++
 	mfc90d.dll!AfxCallWndProc(CWnd * pWnd=0x0012f348, HWND__ * hWnd=0x001e072c, unsigned int nMsg=78, unsigned int wParam=0, long lParam=1236996)  Line 240 + 0x1c bytes	C++
 	mfc90d.dll!AfxWndProc(HWND__ * hWnd=0x001e072c, unsigned int nMsg=78, unsigned int wParam=0, long lParam=1236996)  Line 403	C++
 	mfc90d.dll!AfxWndProcBase(HWND__ * hWnd=0x001e072c, unsigned int nMsg=78, unsigned int wParam=0, long lParam=1236996)  Line 441 + 0x15 bytes	C++
 	user32.dll!761bfd72() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]	
 	user32.dll!761bfe4a() 	
 	user32.dll!761bfdf3() 	
 	user32.dll!761c0943() 	
 	user32.dll!761c0b36() 	
 	comctl32.dll!73cf1734() 	
 	comctl32.dll!73cf7b7d() 	
 	comctl32.dll!73d03b80() 	
 	comctl32.dll!73d03c28() 	
 	comctl32.dll!73d05aaf() 	
 	comctl32.dll!73d07a3d() 	
 	user32.dll!761bfd72() 	
 	user32.dll!761b49a9() 	
 	user32.dll!761b495f() 	
 	user32.dll!761b481f() 	
 	user32.dll!761c26da() 	
 	user32.dll!761bfd72() 	
 	user32.dll!761bfe4a() 	
 	user32.dll!761bfdf3() 	
 	user32.dll!761c09d3() 	
 	user32.dll!761cb759() 	
 	mfc90d.dll!CWnd::DefWindowProcA(unsigned int nMsg=1125, unsigned int wParam=2, long lParam=0)  Line 1043 + 0x20 bytes	C++
 	mfc90d.dll!CWnd::WindowProc(unsigned int message=1125, unsigned int wParam=2, long lParam=0)  Line 1756 + 0x1c bytes	C++
 	mfc90d.dll!AfxCallWndProc(CWnd * pWnd=0x0012f1f8, HWND__ * hWnd=0x000c107c, unsigned int nMsg=1125, unsigned int wParam=2, long lParam=0)  Line 240 + 0x1c bytes	C++
 	mfc90d.dll!AfxWndProc(HWND__ * hWnd=0x000c107c, unsigned int nMsg=1125, unsigned int wParam=2, long lParam=0)  Line 403	C++
 	mfc90d.dll!AfxWndProcBase(HWND__ * hWnd=0x000c107c, unsigned int nMsg=1125, unsigned int wParam=2, long lParam=0)  Line 441 + 0x15 bytes	C++
 	user32.dll!761bfd72() 	
 	user32.dll!761bfe4a() 	
 	user32.dll!761bfdf3() 	
 	user32.dll!761bfdf3() 	
 	user32.dll!761c0943() 	
 	user32.dll!761af99f() 	
 	mfc90d.dll!CWnd::SendMessageA(unsigned int message=1125, unsigned int wParam=2, long lParam=0)  Line 42 + 0x44 bytes	C++
 	mfc90d.dll!CPropertySheet::SetActivePage(int nPage=2)  Line 1177	C++
 	ReTIME.exe!EkPositionEmbeddedPropertySheet(CWnd * pParent=0x0012f184, CPropertySheet * pPSheet=0x0012f1f8, CRect rcNewPosition={...})  Line 118	C++
 	ReTIME.exe!EkPositionEmbeddedPropertySheet(CWnd * pParent=0x0012f184, CPropertySheet * pPSheet=0x0012f1f8, unsigned int nIDPSheetArea=1088)  Line 143 + 0x29 bytes	C++
 	ReTIME.exe!CLSEFOOption::OnInitDialog()  Line 154 + 0x15 bytes	C++
 	mfc90d.dll!AfxDlgProc(HWND__ * hWnd=0x0032071c, unsigned int message=272, unsigned int __formal=2230056, unsigned int __formal=2230056)  Line 28 + 0x10 bytes	C++
 	user32.dll!761bfd72() 	
 	user32.dll!761b4ae0() 	
 	user32.dll!761b495f() 	
 	user32.dll!761b481f() 	
 	user32.dll!761c26da() 	
 	user32.dll!761bfd72() 	
 	user32.dll!761bfe4a() 	
 	user32.dll!761bfdf3() 	
 	user32.dll!761c09d3() 	
 	user32.dll!761cb759() 	
 	mfc90d.dll!CWnd::DefWindowProcA(unsigned int nMsg=272, unsigned int wParam=2230056, long lParam=0)  Line 1043 + 0x20 bytes	C++
 	mfc90d.dll!CWnd::Default()  Line 274	C++
 	mfc90d.dll!CDialog::HandleInitDialog(unsigned int __formal=2230056, unsigned int __formal=2230056)  Line 673 + 0x8 bytes	C++
 	mfc90d.dll!CWnd::OnWndMsg(unsigned int message=272, unsigned int wParam=2230056, long lParam=0, long * pResult=0x0012ecac)  Line 2018 + 0x11 bytes	C++
 	mfc90d.dll!CWnd::WindowProc(unsigned int message=272, unsigned int wParam=2230056, long lParam=0)  Line 1755 + 0x20 bytes	C++
 	mfc90d.dll!AfxCallWndProc(CWnd * pWnd=0x0012f184, HWND__ * hWnd=0x0032071c, unsigned int nMsg=272, unsigned int wParam=2230056, long lParam=0)  Line 240 + 0x1c bytes	C++
 	mfc90d.dll!AfxWndProc(HWND__ * hWnd=0x0032071c, unsigned int nMsg=272, unsigned int wParam=2230056, long lParam=0)  Line 403	C++
 	mfc90d.dll!AfxWndProcBase(HWND__ * hWnd=0x0032071c, unsigned int nMsg=272, unsigned int wParam=2230056, long lParam=0)  Line 441 + 0x15 bytes	C++
 	user32.dll!761bfd72() 	
 	user32.dll!761bfe4a() 	
 	user32.dll!761bfdf3() 	
 	user32.dll!761c0943() 	
 	user32.dll!761ab19f() 	
 	user32.dll!761a7299() 	
 	user32.dll!761c270c() 	
 	mfc90d.dll!CWnd::CreateDlgIndirect(const DLGTEMPLATE * lpDialogTemplate=0x005228c4, CWnd * pParentWnd=0x01cf6cc8, HINSTANCE__ * hInst=0x00400000)  Line 312 + 0x2a bytes	C++
 	mfc90d.dll!CDialog::DoModal()  Line 576 + 0x20 bytes	C++
 	ReTIME.exe!CSingleRTSView::OnMenuLSEOption()  Line 872 + 0xb bytes	C++
 	mfc90d.dll!_AfxDispatchCmdMsg(CCmdTarget * pTarget=0x01cf9f80, unsigned int nID=32805, int nCode=0, void (void)* pfn=0x0040d650, void * pExtra=0x00000000, unsigned int nSig=57, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000)  Line 82	C++
 	mfc90d.dll!CCmdTarget::OnCmdMsg(unsigned int nID=32805, int nCode=0, void * pExtra=0x00000000, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000)  Line 381 + 0x27 bytes	C++
 	mfc90d.dll!CView::OnCmdMsg(unsigned int nID=32805, int nCode=0, void * pExtra=0x00000000, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000)  Line 162 + 0x18 bytes	C++
 	mfc90d.dll!CFrameWnd::OnCmdMsg(unsigned int nID=32805, int nCode=0, void * pExtra=0x00000000, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000)  Line 942 + 0x23 bytes	C++
 	mfc90d.dll!CWnd::OnCommand(unsigned int wParam=32805, long lParam=0)  Line 2364	C++
 	mfc90d.dll!CFrameWnd::OnCommand(unsigned int wParam=32805, long lParam=0)  Line 366	C++
 	mfc90d.dll!CWnd::OnWndMsg(unsigned int message=273, unsigned int wParam=32805, long lParam=0, long * pResult=0x0012fa34)  Line 1769 + 0x1e bytes	C++
 	mfc90d.dll!CWnd::WindowProc(unsigned int message=273, unsigned int wParam=32805, long lParam=0)  Line 1755 + 0x20 bytes	C++
 	mfc90d.dll!AfxCallWndProc(CWnd * pWnd=0x01cf9990, HWND__ * hWnd=0x000f0c36, unsigned int nMsg=273, unsigned int wParam=32805, long lParam=0)  Line 240 + 0x1c bytes	C++
 	mfc90d.dll!CMDIFrameWnd::OnCommand(unsigned int wParam=32805, long lParam=0)  Line 48 + 0x23 bytes	C++
 	mfc90d.dll!CWnd::OnWndMsg(unsigned int message=273, unsigned int wParam=32805, long lParam=0, long * pResult=0x0012fc48)  Line 1769 + 0x1e bytes	C++
 	mfc90d.dll!CWnd::WindowProc(unsigned int message=273, unsigned int wParam=32805, long lParam=0)  Line 1755 + 0x20 bytes	C++
 	mfc90d.dll!AfxCallWndProc(CWnd * pWnd=0x01cf6cc8, HWND__ * hWnd=0x002c0c98, unsigned int nMsg=273, unsigned int wParam=32805, long lParam=0)  Line 240 + 0x1c bytes	C++
 	mfc90d.dll!AfxWndProc(HWND__ * hWnd=0x002c0c98, unsigned int nMsg=273, unsigned int wParam=32805, long lParam=0)  Line 403	C++
 	mfc90d.dll!AfxWndProcBase(HWND__ * hWnd=0x002c0c98, unsigned int nMsg=273, unsigned int wParam=32805, long lParam=0)  Line 441 + 0x15 bytes	C++
 	user32.dll!761bfd72() 	
 	user32.dll!761bfe4a() 	
 	user32.dll!761bfdf3() 	
 	user32.dll!761c018d() 	
 	user32.dll!761b8b7c() 	
 	mfc90d.dll!AfxInternalPumpMessage()  Line 183	C++
 	mfc90d.dll!CWinThread::PumpMessage()  Line 900	C++
 	mfc90d.dll!CWinThread::Run()  Line 629 + 0xd bytes	C++
 	mfc90d.dll!CWinApp::Run()  Line 865	C++
 	mfc90d.dll!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x001e3e57, int nCmdShow=1)  Line 47 + 0xd bytes	C++
 	ReTIME.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x001e3e57, int nCmdShow=1)  Line 30	C++
 	ReTIME.exe!__tmainCRTStartup()  Line 574 + 0x35 bytes	C
 	ReTIME.exe!WinMainCRTStartup()  Line 399	C
 	kernel32.dll!7610d0e9() 	
 	ntdll.dll!779319bb() 	
 	ntdll.dll!7793198e() 	
 	ReTIME.exe!C_Recordset::GetRecordCount()  Line 167 + 0x21 bytes	C++
 	4fc7027d()

Open in new window

0
 
AndyAinscowCommented:
Line 2 - PrepareWrite2 - nLength = 4355132

That looks like it might be your problem, there seems to be something wrong with the value you are assigning to the string (which goes into the edit box).  That says you have a >4MB long string you are putting into the CString variable !

Do you assign a value to m_mylseDimensi anywhere in your code?  If yes then please post the code in the function that is doing that.   (I guess it is one of your OnBtn... handlers based on your previous question).
0
 
ZoppoCommented:
Hm - this is strange, I'm not sure if you can trust the values shown by the debugger. If you take a look at the involved function 'PrepareWrite' the argument passed to it (here '3') should be passed to 'PrepareWrite2' unchanged, but debugger shows it as '4355132'

Are you sure you have added the control in the correct dialog resource and use the same resource ID in the call to 'DDX_Text'? Do you maybe use multiple resources for different languages and forgot to add the control to one of these?

ZOPPO
0
 
DanRollinsCommented:
The only thing that could change nLength there is something that corrputs the stack in the PrepareWrite function. That fn is below.
The most likely candidate is the GetData() function.
The observed behavior could be a result of the DDX target variable not being a valid CString reference.

0
 
DanRollinsCommented:
Supporting evidence is its value, which is shown as:
   " &@"
which seems like an unlikely thing to type into an edit box.
0
 
khairulzamsAuthor Commented:
thank guys..


actually, all the edit boxed located in property sheet. I have three property pages with edit boxes

For first property pages I have two edit boxes and for 2nd and 3rd property sheet I have one edit box each property page. All this edit boxes created in same time and working properly.

But after several days, I try to create new edit box in each property pages, it was successfully only in 1st property page. When I try to add another edit box in 2nd even 3rd property pages, I got this kind of error.

Every edit box, it was set as string
1st Property Page (CFO3DCDS) - two edit boxes created same time with 2nd(CFOMyLSE) and 3rd CFOSTAR)

In 1st property page (CFO3DCDS)
        DDX_Text(pDX, IDC_COORFILE_3DCDS, m_CoorF3DCDS);
      DDX_Text(pDX, IDC_OBS_3DCDS, m_ObsF3DCDS);
      DDX_Text(pDX, IDC_SELECT_DIMENSI, m_SelectDimensi);
 set as CString
      m_CoorF3DCDS = _T("");
      m_ObsF3DCDS = _T("");
      m_SelectDimensi = _T("");

In 2nd property page (CFOMyLSE)
      DDX_Text(pDX, IDC_LSEFONAME_MyLSE, m_fnamelseMyLSE);
 set as CString
      m_fnamelseMyLSE = _T("");

In 3rd property page (CFOSTAR)
      DDX_Text(pDX, IDX_LSEFONAME_STAR, m_fnamelseSTAR);
 set as CString
      m_fnamelseSTAR = _T("");

I have tried to add new edit box in 2nd property page but failed even in 3r property page.

But when I chance m_mylsedimensi (new variable, not assign in other code) from CString to int, it working but in IDC_MyLSE_DIMENSION edit box show 4355092 .
0
 
AndyAinscowCommented:
I think you are trying to use a window before it is created - so bad pointers are in use.
I keep asking for you to post your code.  Without it we are very limted in being able to help you.


eg.
Do you assign a value to m_mylseDimensi anywhere in your code?  If yes then please post the code in the function that is doing that.   (I guess it is one of your OnBtn... handlers based on your previous question).
0
 
khairulzamsAuthor Commented:
No Andy... I not assign m_mylseDimensi anywhere in my code. exclusive assign to this edit box. confirm
0
 
AndyAinscowCommented:
Is it possible for you to upload the project as a zip file?
0
 
khairulzamsAuthor Commented:
andy..you mean all of the code?..or just the exe file?
0
 
AndyAinscowCommented:
the code - so we can see things.
0
 
DanRollinsCommented:
>>But when I chance m_mylsedimensi (new variable, not assign in other code) from CString to int, it working but in IDC_MyLSE_DIMENSION edit box show 4355092 .

Please explain in more detail what you mean by that.
The difference between a CString and an int is critical and I'm nearly certain that this is related to the problem.
0
 
khairulzamsAuthor Commented:
finally solved

maybe It like Andy said : "I think you are trying to use a window before it is created - so bad pointers are in use."

after I re-developed the property page, no error any more when I added a new edit box.

Thank to other experts  
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 9
  • 8
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now