Solved

CImage ReleaseDC Exception Mystery

Posted on 2008-10-22
1
1,283 Views
Last Modified: 2013-12-14
I have been applying the CImage class within a Visual C++/MFC DLL.  I am experiencing a mysterious exception in atlimage.h line 1217 when I call CImage::GetPixel(0,0).  The offending statement is:

hBitmap = HBITMAP( ::SelectObject( m_hDC, m_hOldBitmap ) );
ATLASSERT( hBitmap == m_hBitmap );

I have successfully loaded an 8x13 jpg 24 bpp image from disk and the pixel value is successfully read, yet the m_hOldBitmap member is null and thus SelectObject returns null.  The m_hBitmap member is valid and thus does not match hBitmap.

Has anyone experienced this error and found a solution?

Thanks!
0
Comment
Question by:fredsmullin
1 Comment
 

Accepted Solution

by:
fredsmullin earned 0 total points
ID: 22783196
Please disregard the question.  I found that it was operator error with CImage use.

If you use the CImage assignment operator, CImage a = CImage b, it merely copies the HBITMAP value from b to a.  But when b is destroyed, it destroys the HBITMAP as well.  But, a has no idea this has occurred and any subsequent operations will result in exceptions being generated.

The proper way to assign from one CImage to another is to use CImage::Attach and CImage::Detach functions.  This only moves the HBITMAP from one class to the next, but prevents it from being shared between two classes.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
move a line in eclipse 3 101
post4 challenge 28 100
canBalance challenge 34 81
Making an alias 7 94
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question