Solved

CDC invalid handle  0xC0000008

Posted on 2007-04-04
10
580 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

856 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