show Image with CImage - Debug assertion failed

Hi,

I tried to show a png Image using CImage ( Visual Studio 2008 prof )

It works pretty good, but only  in Release Mode. If I run it in Debug Mode 
there is a Message:

"Debug Assertion Failed!
Program:  ....[..]\application.exe
File: g:[...]\atlimage.h
Line: 503

Expression: m_hbitmap == 0
[..]


if I ignore the message the picture is schown. How can I avoid this Failure

My Code:

BOOL OK;
	LPCTSTR lpBitSource=_T("D:\\Daten\\Visual Studio 
2008\\Projects\\LitLaunchTestbox\\LitLaunch\\brett1.png");
	CRect rect;
	GetClientRect(&rect);

	CWindowDC pDC(this);
	CDC dc;
	OK=m_Image.Load(lpBitSource);
	dc.CreateCompatibleDC(&pDC);

                 m_Image.Draw(pDC.m_hDC,CRect(&rect));

Thanks for answers.

Manu


 

0
Manuel
2/16/2010 5:33:49 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
11987 Views

Similar Articles

[PageSpeed] 1

It asserts because  "m_Image"  already has some value from the last
call.
Try calling "m_Image.Destroy()" after you are done with your drawing
or just before calling "m_Image.Load()" in your code above.

-Seetharam



2
Seetharam
2/16/2010 9:20:42 PM
To add to the other posts...

You will want to support any images that you create with the CImage class 
(or any other GDI+ functions) otherwise you will get resource leaks.

Tom

"Manuel Hoeger" <Manuel.Hoeger@physik.stud.uni-erlangen.de> wrote in message 
news:7u037sFup1U1@mid.dfncis.de...
> Hi,
>
> I tried to show a png Image using CImage ( Visual Studio 2008 prof )
>
> It works pretty good, but only  in Release Mode. If I run it in Debug Mode 
> there is a Message:
>
> "Debug Assertion Failed!
> Program:  ....[..]\application.exe
> File: g:[...]\atlimage.h
> Line: 503
>
> Expression: m_hbitmap == 0
> [..]
>
>
> if I ignore the message the picture is schown. How can I avoid this 
> Failure
>
> My Code:
>
> BOOL OK;
> LPCTSTR lpBitSource=_T("D:\\Daten\\Visual Studio 
> 2008\\Projects\\LitLaunchTestbox\\LitLaunch\\brett1.png");
> CRect rect;
> GetClientRect(&rect);
>
> CWindowDC pDC(this);
> CDC dc;
> OK=m_Image.Load(lpBitSource);
> dc.CreateCompatibleDC(&pDC);
>
>                 m_Image.Draw(pDC.m_hDC,CRect(&rect));
>
> Thanks for answers.
>
> Manu
>
>
>
> 


0
Tom
2/17/2010 3:57:37 AM
See below...
On Tue, 16 Feb 2010 18:33:49 +0100, "Manuel Hoeger"
<Manuel.Hoeger@physik.stud.uni-erlangen.de> wrote:

>Hi,
>
>I tried to show a png Image using CImage ( Visual Studio 2008 prof )
>
>It works pretty good, but only  in Release Mode. If I run it in Debug Mode 
>there is a Message:
>
>"Debug Assertion Failed!
>Program:  ....[..]\application.exe
>File: g:[...]\atlimage.h
>Line: 503
>
>Expression: m_hbitmap == 0
>[..]
****
It is pretty clear what this means.  It means that the m_hBitmap member of the class MUST
be NULL, and it ISN'T NULL.  Why not?  Because you already have an image attached to it!

Nowhere did I see where m_Image is freeing the image.

Which leads to the question of why, in your OnDraw/OnPaint handler, you are storing the
image which you are just loading into a class member, instead of a local variable.
****
>
>
>if I ignore the message the picture is schown. How can I avoid this Failure
>
>My Code:
>
>BOOL OK;
>	LPCTSTR lpBitSource=_T("D:\\Daten\\Visual Studio 
>2008\\Projects\\LitLaunchTestbox\\LitLaunch\\brett1.png");
****
I presume the goal here is that this program will run correctly only today, on your
machine, and you never expect it to run anywhere else.  Otherwise, hardwiring a path like
this in represents a serious problem.
****
>	CRect rect;
>	GetClientRect(&rect);
>
>	CWindowDC pDC(this);
****
Do you really want a window DC?  Why?  Wouldn't CClientDC dc(this) be more appropriate?
****
>	CDC dc;
>	OK=m_Image.Load(lpBitSource);
****
Once it is loaded, it is loaded forever, and any attempt to load it again generates the
error you see.  You must explicitly delete this image with CImage::Destroy, e.g., after
you draw it, you must do
	m_Image.Destroy();

but why does m_Image exist at all?  A local variable would be perfect for this!
****
>	dc.CreateCompatibleDC(&pDC);
>
>                 m_Image.Draw(pDC.m_hDC,CRect(&rect));
****
I am presuming this is in your OnDraw/OnPaint handler.  If it isn't, all of the above code
is incorrect.  It would be correct only if it were in the OnDraw/OnPaint handler.
				joe
****
>
>Thanks for answers.
>
>Manu
>
>
> 
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-1
Joseph
2/20/2010 6:24:18 AM
Reply:

Similar Artilces:

analytical accounting lookups should only show valid codes
When entering AA transaction distributions, the code lookup window should only show valid code combinations. It's not intuitive for the user to have to select a code and get an error message to discover which codes are valid. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the mess...

Outlook shows offline during dial up
Having a problem with outlook 2002. Over the WAN everything works fine. Dial up and connect to the network (VPN) internet work fine. Outlook will sync up however, a red x shows up in the bottom right hand corner. Outlook shows offline, I can send and receive but must hit send and receive. I have reloaded the computer from scratch and still have the same problem. Could it be a Excange setting? Any Ideas? Thanks for the help, If you hit File | Connect to Exchange Server what happens? -- Aloha, -Ben- Ben M. Schorr, OneNote-MVP http://home.hawaii.rr.com/schorr **I apologize ...

Login failed for user '(null)'
I have an extended web application to MS CRM 3.0 that is simply trying to populate some values from the filtered views. I receive an SQL Exception Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection when accessing from client machines. I do have "Integrated Security=sspi" in the connection string. It works fine from the MS CRM Server. It works from my desktop only when I have remote desktop connection to the MS CRM server and opened the extended application from there. Does anyone have a solution to this? Thanks ...

reminder still shows up
when I run Outlook.exe /cleanreminders it simply opens Outlook, I am running Vista "Toppro" <Toppro@discussions.microsoft.com> wrote in message news:7AE8DBF7-6BE3-454A-82F9-5A040566026C@microsoft.com... > when I run Outlook.exe /cleanreminders it simply opens Outlook, I am > running > Vista Outlook version? The Windows version isn't as important and that of Outlook. -- Brian Tillman [MVP-Outlook] ...

MSPS2007: Can you save PivotChart as Image?
We have never been able to save a PivotChart or PivotTable as in image from our installation of MSPS2007. After putting in the location and clicking OK, a blank alertbox with an exclamation point appears, no text. The only thing you can do is click the OK button on the blank alertbox and return to Data Analysis. Anyone else have this problem? Any ideas on how to enable the functionality so that we can export Data Analysis views as an image? I suspect this must be some level of permissions within the browser, though I wouldn't like to guess where.... -- Thanks, Ben. ...

Show Window
I am currently developing a MFC SDI application. I want to integrate a tray icon with it. When the application is minimized it hides by ShowWindow(SW_HIDE) and then when double clicked on tray icon shown by ShowWindow(SW_SHOWNORMAL). But the problem is if some other application is activated after my application is minimized, ShowWindow shows it but it's behind some screen. I have tried with SetFocus didn't work. Please help me to solve this problem. Thank you. Varuna Try BringWindowToTop. ---- Ajay Kalra ajaykalra@yahoo.com In addition to Ajay's idea you can also use SetFor...

Information Stores show dismounted yet mail is still flowing...
Background: Windows AD Mixed moded. Exchange 2003 installed on to a 2 node Microsoft cluster. 1 Front End server...connecting to the primary cluster node. Windows 2003 Standard on, FE Windows 2003 Enterprise Server on BEs (<---cluster) no service packs on either. Exchange has SP1 installed on both nodes and the FE. There are still Exchange 5.5 servers in the environment although they are not being used. The Issue: .....the information stores and public folders all show that they are dismounted...yet email is still flowing into and out of the server without any issues. I just...

Show a blank result in a cell when there is no value in the "Lookup" cell
I apologize if this question has been asked, but I have been unable to find an answer searching the topics. I'm using the following formula in cell C3: =INDEX(LastName,MATCH(A3,EmpID,0)) When I type in an employee ID in A3, his/her last name shows in C3. However, when there is no value in A3, C3 shows error "#N/A". Is there a way to show a blank cell in C3 until a value is entered into A3? Thanks in advance! Mike On Aug 5, 10:45 am, "Michael Slater" <mslater...@comcast.net> wrote: > I'm using the following formula in cell C3: > =INDEX(LastNam...

Using ajax call to fetch multiple results from multiple queries and showing them 1 by 1 as the results comes.
Hello, I've 20 labels in a 2x10 table on a page. for each label, data comes by individual queries. (total 20 queries for the page.) and it takes about 30-40 seconds for the page to load, and it's not comfortable for the user to see blank page. I want that each cell will show loading.gif images. As and when data comes from query, the images should go visible=false, and the label should display the values one by one. How do I do this task using ajax? Some ASP.NET code example will be helpful for me, as I'm a kind of beginner. Thanks ...

Results show as a minus. WHY?
I have an application that was developed by another developer using VB.net which reside in a SQL table. I need to use some of the data from this table, however the data shows as -0.5 or - 0.99 or -1.70 etc in my Access tables. How can I get those numbers to show as a percentage with only one decimal point to the left? Example: 3.6% or 31.4 %. Any help would be greatly appreciated. No matter what I do it shows that dang "-" at the beginning. You can use the Abs function to strip off the negative Abs([YourTable].[YourField]) And you can format that as percentage either using th...

Laptop Client Synchronisation
Hi, Hoping somebody can shed some light on this. When I click the Go Offline button on my laptop to synchronise the CRM data it's get's to the following: Synchronising 56 Letters to offline database and shows the following error: Failed move data for entity 'Letter' during action saDelete, countRows=56. Contact your system blah blah blah. I have deleted the campaign the letters were part of (this is a relatively new installation that I'm now starting to use) and all traces of the letters that I can see, but no joy. I even deactivated any entries with the 'Letter...

show comments when cell is highlighted Vs when cursor runs over? #2
How do you make the comments appear when the cell is highlighted opposed to when the mouse cursor runs over the cell? You can press Shift/F2, or Insert/Edit Comment. If you wanted to see it "automatically", when you select the cell, you'd need a macro, but I don't think this is what you're asking. Bob Umlas Excel MVP "Don" wrote: > How do you make the comments appear when the cell is highlighted opposed to > when the mouse cursor runs over the cell? To at least Excel 2000, if you have the Tools, Options, Comment Indicator Only you will see the co...

failed to restore full backup using ntbackup
hi everybody I tryed on my lab inviroment backup my xp (C:) partitian using ntbackup, then I changed ntldr file, the restore didn't work here is the report restore Status Operation: Restore Backup of "C:", Restored to"C: " Backup set #1 on media #1 Backup description: "Set created 12/7/2009 at 1:13 PM" Restore started on 12/7/2009 at 1:34 PM. Warning: File AUTOEXEC.BAT was skipped Warning: File boot.ini was skipped Warning: File CONFIG.SYS was skipped Warning: File IO.SYS was skipped Warning: File MSDOS.SYS was skipped Warning: File nag...

how to show numbers that begin with 0 in excel
I need to type numbers into an excel spreadsheet some of them begin with a zero some do not. How can I have excel show the 0 in the numbers that begin with 0. If I type 0236547 the number shows as 236547. I don't want all the numbers I type to begin with zero. I am using Excel 2003. Thanks very much for your help. Best regards, Dee use a custom format with how ever many digits you need, 000000 -- Gary Keramidas Excel 2003 "Dee" <Dee@discussions.microsoft.com> wrote in message news:EA60FC8A-C7CB-432A-B2B2-EEEBF86D2646@microsoft.com... >...

Comments not showing
When a SharePoint workflow is edited and a comment is added. The comment does not display in the workflow status screen under workflow history. It shows as follows: Task assigned to Andre Wessels was completed by System Account. Comments: Instead of: Task assigned to Andre Wessels was completed by System Account. Comments: Please update to the new company logo. This happens for all standard SharePoint workflows (Approval, Collect Feedback). Any custom workflows does show the comment. The comment field is update in the task item. It just does not show. There is no error in t...

Report Server shows 'Service Unavailable'
Hi, before install, the SRS setup, send me a warning, some like "the Windows Sharepoint Services are install and not permit initialize a Reportserver component" i skip wiht the installation, so.. I can't run http://<localhost>/Reports and http://<localhost>ReportServer show a message "Service Unavailabe", but the ReportServer service is running How initialize that or what do i do? ------=_NextPart_0001_09E699C9 Content-Type: text/plain Content-Transfer-Encoding: 7bit <Miguel@discussions.microsoft.com> wrote: > before install, the SRS set...

Show more time in weekly view?
Outlook 2007 On default the weekly view is only showing until 4 PM without scrolling down. I know there is a way to let you see into the evening hours also without scrolling. Help please. Thanks... Bob ...

TransparentBlt doesn't show the bitmap in ME?
The following doesn't print the bitmap on ME while it works on 2k/xp, can someone help me? Though the status returns TRUE. Thanks. Jiac. CDC *hdc, bghdc; CBitmap bgBitmap; BITMAP bmpInfo; //loads bitmap into memory bgBitmap.LoadBitmap(IDB_BITMAP5); // this bitmap has no needles // get bitmap info bgBitmap.GetBitmap(&bmpInfo); hdc = m_obj->GetDC(); bghdc.CreateCompatibleDC(hdc); bghdc.SelectObject(&bgBitmap); BOOL status = hdc->TransparentBlt(0, 0, 80, 80, &bghdc, 0, 0, 80, 80, TRANSPARENT_KEY_COLOR); //TRANSPARENT_KEY_COLOR if (st...

Showing a Null result
I have a parent table linked to several child tables via a unique text string The report shows reults from the main table, and has subreports for the child tables. Some records in the parent table have no equivalents in the child tables. Can I insert some code to produce the subreports with a "None" or "NA" text string, without populating the child tables with these terms? My problem is that, I need to run "counting" queries on the child tables, but the "N/A" records skew the numbers by adding records where there should be none. I'm not su...

mail box rights it only shows "SELF"
Once the user has been created, checking the Email address tab show nothing (empty), I pointing rus to the right DC, this solve that problem, but i have still have the next problem: under the mail box rights it only shows "SELF" where as all the other account show 8 or more system users? exchange 2003 Gr, Marco On Tue, 21 Feb 2006 13:10:27 -0800, "Marco" <Marco@discussions.microsoft.com> wrote: >Once the user has been created, checking the Email address tab show nothing >(empty), I pointing rus to the right DC, this solve that problem, but i have >...

Clear Data>Security Resource Description table not showing in list
GPv10 Logged in as sa. Go to Maint. >Clear Data>System and in the Tables list the Security Resource Description table is not there. Is there something I need to do to get access to that table? Thanks. Gi Never mind....I figured it out. You have to change the Display to Physical....Duh!! ...

Show Data Field After Hiding
I found a note from someone with the same question regarding reshowing data that was hidden after it was deselected from the drop-down list. And yes, it is easy enough to drag it back on from the field list, but if it involves anything more than just a sum or count, then you have to recreate it. For instance, my rows are years. One of my data fields I would like in the table twice - once as a sum and then again as % difference from previous year. The reason for wanting to hide one or the other, is I'm plotting this over time and would like to use the same chart. Since the scales are ob...

gp 10 -how to show a list of sop documents for a specific customer?
Hello, What is the best way to return all SOP documents for a specific customer using GP10 list? (not smartlist) This is our problem: -we go to the Customers list. -select a customer and goto > "view transactions" our problem is that any sop transaction that we click on that is moved to history, opens the AR transaction instead of the SOP document. Context? a customer calls and wants to know if something they bought is under warranty but they have no clue when they bought it. So we will not know what date is was bought. We are just using SOP, not service management. -- J...

Missing images (only boxes with red x)
Hi All, I hope someone can help. The problem (openning mail items with boxes instead of images) occurs on one of my computers, but not the other. They are both running XP Pro and Office 2003 and openning the same email file. I'm not sure where to look and hope someone can provide me with a hint. It was working, but a few weeks, something changed and I don't know what. I don't recall making any significant changes or installing any programs. Thanks, Michele ...

Failed to duplicatehandle
when I use MFC to create a Win32 application which call CreateProcess to call service procedurces which are created from MinGW. I want use pipe to draw the information generated in service produrces, there is a strange thing happened. When the MFC Application runs called by VC++'s GO command, all the service procedures work correctly. But when I double chick the MFC Application to run, these service procedures occur error, and summit the MFC Application a error message "Duplicatehandle error xxxx.exe can not duplicate handle". How strange it is! I why to know why this happe...