-
March 22nd, 2014, 01:31 PM
#1
[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.
-
March 22nd, 2014, 03:50 PM
#2
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
-
March 23rd, 2014, 05:48 AM
#3
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.
-
March 23rd, 2014, 06:49 AM
#4
Re: Debug Assertion Failed with MessageBox
Originally Posted by Zulfi Khan2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|