Solved

CDC invalid handle  0xC0000008

Posted on 2007-04-04
10
574 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now