[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

StartDoc() returns negative, but no error.

Posted on 1997-08-04
1
Medium Priority
?
733 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
marvinm earned 400 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

656 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