Solved

StartDoc() returns negative, but no error.

Posted on 1997-08-04
1
725 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

829 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