Solved

StartDoc() returns negative, but no error.

Posted on 1997-08-04
1
719 Views
Last Modified: 2013-12-03
I am new to windows printing, so I may be missing something
simple here.  I have a several printers set up, and am able
to print from other apps. A reasonable copy of what I'm
trying to do is below. Thank You.

void PrintOut(HWND hWnd)
{
      PRINTDLG pd;
      DOCINFO       di;
      char *title = "My Title";
      int NumCopies;
 
      memset(&pd,0,sizeof(PRINTDLG));
      pd.lStructSize      = sizeof(PRINTDLG);
      pd.hwndOwner      = hWnd;
      pd.Flags      = PD_RETURNDC | PD_NOPAGENUMS |
                       PD_NOSELECTION | PD_HIDEPRINTTOFILE;
      pd.nCopies            = 1;

      if (PrintDlg(&pd)) {
            di.cbSize = sizeof(DOCINFO);
            di.lpszDocName = title;
            di.lpszDatatype = NULL;
            di.fwType = 0;
/**
 *  StartDoc returns < 0, but an immediate call to
 *  GetLastError() ruturns error #0
 */
            if (StartDoc(pd.hDC,&di) > 0) {
                  for (NumCopies = 0;
                               NumCopies < pd.nCopies;
                                              NumCopies++) {
                        StartPage(pd.hDC);

/** My printing here **/
                        EndPage(pd.hDC);
                  } // for print each page
                  EndDoc(pd.hDC);
            }  // if was able to start the print job
            DeleteDC(pd.hDC);
      } // If print out for real
} // PrintOut
0
Comment
Question by:PhilC
1 Comment
 
LVL 1

Accepted Solution

by:
marvinm earned 100 total points
ID: 1402923
I notice you didn't zero out the DOCINFO structure.

try memset(&di,0,sizeof(DOCINFO));

before setting any of its members.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

759 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

22 Experts available now in Live!

Get 1:1 Help Now