CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Posts
    29

    Unstable MFC printing to Acrobat. Can anyone help?

    I have an MDI MFC app-wizard generated application. Printing works fine EXCEPT when printing to acrobat 6 printer (ie distiller). I can compile and run the program in the debugger and it will print fine. I close my program, re-run it immediately, and when trying to print to acrobat, I get assertions in wingdi on seemingly random DC function calls (eg LineTo, Rectangle) because the m_hDC is NULL.
    I'm not doing anything 'fancy' - just drawing rectangles and text.

    My biggest problem is when I try to step through in the debugger, it always works fine (ie produces the pdf).

    Please let me know if you have had similar problems. Any suggestions on how to get to the root of the problem?

    Thank you
    Jon

  2. #2
    Join Date
    Feb 2003
    Location
    Greece-Athens
    Posts
    57
    Debug versions of the MFC provide a security layer for our programs. They protect applications from crashes in other words.

    We have to be very explicit when creating pointers and handles and when using them. All pointers and handles should be initialized before using them and checked for the integrity of their target.

    Your problem seems to me like a debug/release version difference issue. That means I advise you to make your code more safe. As it works in the debugger, the problem to be fixed is possibly requiring minor changes.

    you could post here some code snippets about the creation of the CDC object that occurs to have a NULL handle, or the exact lines of code. Someone could help you more specifically.
    Last edited by A_Stavros; July 13th, 2004 at 09:58 AM. Reason: add lines

  3. #3
    Join Date
    Jan 2004
    Posts
    29
    Thanks for your reply. I have just got to the bottom of the problem, and it was my own stupid fault!. I had nievely assumed that screen redraw could not be called whilst printing - of course it can. My plot object - all drawing is done in a separate class - was explicityly passed the CDC* which it held as a member variable, rather than being passed in the the plot class' Draw function. So part way through printing, the DC would change to do the screen redraw, resulting in the printer getting upset. It seems to be just coincidental that this ocurred while printing to acrobat.

    Case closed.

    Jon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured