?
Solved

CDC invalid handle  0xC0000008

Posted on 2007-04-04
10
Medium Priority
?
586 Views
Last Modified: 2009-07-29
Hi Experts,
I just added some new code to a program that I've been using a CDC object with for printing... I didn't modify any code that modifies the CDC object but when printing I'm now getting a "first-chance exception in MyProgram.exe (NTDLL.DLL):  0xC0000008: Invalid Handle."    This happens inside a CDC.DrawText call... The internal m_hDC looks like it's pointing at a valid location...  I'm not sure how to find the source of this bug...

Any comments are very appreciated - I'm quite stuck...

Thank you!
Mike
0
Comment
Question by:thready
[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
10 Comments
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 18853727
Can you show the snippet?
0
 
LVL 1

Author Comment

by:thready
ID: 18853799
Hi DeepuAbrahamK - thanks for helping - please note that I think this is probably a stray pointer - I haven't touched any of my printing code in over a year!!  (the code is literally not touched)..  I think I'd be wasting your time by showing you code that has worked.. I just don't know how to find out which handle is invalid... Since the call stack ends up somewhere in NTDLL before it reports the error, I really have no idea exactly what is invalid... It must be something in the CDC object....  Do you still think code will help?   (it's a big momma mammoth class)....

Thanks,
Mike
0
 
LVL 11

Expert Comment

by:cup
ID: 18853888
The last time I got something like that it was to do with Fonts.  Are some of the fonts set to "MS Shell Dlg"?  This is one of those locale dependent fonts that lives in the registry.  If it doesn't exist, it will cause one of these invalid handle things.  This happens on the later versions of visual studio.  Didn't happen on Visual 6.  That is just a guess: it may or may not be the reason for your first chance exception.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:thready
ID: 18853933
Funny thing is I was thinking it does have something to do with fonts.... I will attach the fonts first....  I'll let you know - and thanks!

Mike
0
 
LVL 1

Author Comment

by:thready
ID: 18853935
i meant attack - not attach.....

:-P
0
 
LVL 1

Author Comment

by:thready
ID: 18854209
Nope - doesn't look like it's the fonts... It's now also happening before I even try to use the dc... Here's a snippet:

      CDC dc;
      CPrintDialog printDlg(FALSE);
      if(printDlg.DoModal() == IDCANCEL)
            return FALSE;
      dc.Attach(printDlg.GetPrinterDC());
      dc.m_bPrinting = TRUE;

the dc that I attach to is the one I use later..  But this is failing in ***DoModal*** (intermittently) now....
0
 
LVL 1

Author Comment

by:thready
ID: 18854427
ok this is weird - it **IS** font related (I'm using vis studio 6)... I changed all myfonts to Arial and it works...  Here's a code snippet:

m_FieldInfoFont.CreateFont(FIELD_INFO_SIZE*nMapFactor, 0, 0, 0, FW_BOLD, FALSE, bUnderLineFieldInfo, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial");  //"Times New Roman");

In the snippet above, the font was "Times New Roman"... changing it to Arial gets rid of the invalid handle when I do a DrawText....   Any ideas?

Thanks again!
Mike
0
 
LVL 1

Author Comment

by:thready
ID: 18854434
Again - the above snippet is using Times new roman in the version of the exe that I haven't changed for a long time.... this is only happening in an updated version of the program which made me thing this was a stray pointer in new code....  Do you think it's a stray pointer?  Could it be something else font-related??
0
 
LVL 11

Accepted Solution

by:
DeepuAbrahamK earned 2000 total points
ID: 18855757
Can you try this?
void CMyView::OnDraw(CDC* pDC)
{
    CFont font;

    font.CreateFont(46, 28, 215, 0,
                 FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
              OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
              DEFAULT_PITCH | FF_ROMAN, "Times New Roman");

    CFont *pFont = pDC->SelectObject(&font);
    pDC->TextOut(20, 128, "This is a test", 12);

    pDC->SelectObject(pFont);
    font.DeleteObject();
}

Hope you are doing delete aswell. Can you try this and let us know whats the behaviour?

Best Regards,
DeepuAbrahamK
0
 
LVL 4

Expert Comment

by:MacroLand
ID: 18856182
Hi,

This page may give you an idea... http://www.codeproject.com/printing/QPrint.asp

http://www.codeproject.com/printing/ contains lots of example codes of how to use MFC for printing.

Regards,
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

770 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