Solved

CImage ReleaseDC Exception Mystery

Posted on 2008-10-22
1
1,368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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.

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

627 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