[RESOLVED] Debug Assertion Failed with MessageBox
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Debug Assertion Failed with MessageBox

  1. #1
    Join Date
    Jun 1999
    Posts
    488

    [RESOLVED] Debug Assertion Failed with MessageBox

    Hi,
    I am trying to use MessageBox in OnInitialUpdate function but its giving me "Debug Assertion Failed Message"
    File: f:\dd\vctools\crt_bld\self_x86\crt\src\vsprintf.c
    Line:244
    I am using the following code:
    Code:
    void CRotateImageView::OnInitialUpdate()
    {
    	int k;char str[2];
    	CView::OnInitialUpdate();
    	
    	CString szStr,szstr1;
    	szStr= "D:\\image\\after_cut2.jpeg";
    	k=img.Load(szStr);
            sprintf_s(str,2, "%d",k);
    	szstr1=(CString)str;
    	MessageBox(szstr1);
    	
    }
    However when i am using the same code in OnDraw its working.


    Code:
    
    void Csprintf_sEGView::OnDraw(CDC* /*pDC*/)
    {
    	Csprintf_sEGDoc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    	if (!pDoc)
    		return;
    
    	int k;char str[2];
    	
    	CString szStr,szstr1;
    	
    	
        sprintf_s(str,2, "%d",1);
    	szstr1=(CString)str;
    	MessageBox(szstr1);
    
    	// TODO: add draw code for native data here
    }
    Somebody plz help me with this problem.

    Zulfi.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,277

    Re: Debug Assertion Failed with MessageBox

    1.
    File: f:\dd\vctools\crt_bld\self_x86\crt\src\vsprintf.c
    Line:244
    And what is this "Line:244" in vsprintf.c?


    Do NOT use sprintf/sprintf_s with CString. Use CString::Format instead.
    Do NOT place more than one statement in a line!
    Use AfxMessageBox in an MFC applications.
    Use _T() macro to make your code both UNICODE and ANSI aware
    Code:
    	CView::OnInitialUpdate();
    	
    	CString szStr(_T("D:\\image\\after_cut2.jpeg"));
    	HRESULT k = img.Load(szStr);
            CString str;
            str.Format(_T("HRESULT is %d"), k);
    	AfxMessageBox(str);
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 1999
    Posts
    488

    Re: Debug Assertion Failed with MessageBox

    Hi,
    It says:
    Expression"Buffer too small", 0)
    But its working now. Thanks for your guidance. If you have some time plz tell me:
    i) Is it VC restriction for not putting 2 statements in a single line?
    ii) Is MessageBox ( ...) not good?

    Zulfi.
    Last edited by Zulfi Khan2; March 23rd, 2014 at 09:11 AM.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,277

    Re: Debug Assertion Failed with MessageBox

    Quote Originally Posted by Zulfi Khan2 View Post
    i) Is it VC restriction for not putting 2 statements in a single line?
    ii) Is MessageBox ( ...) not good?
    1. No, it is just a good programming style. Besides, it makes code much more readable and understandable.

    2. Read MSDN about using message boxes in MFC applications:
    http://msdn.microsoft.com/en-us/library/0eebkf6f.aspx
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center