Solved

StartDoc() returns negative, but no error.

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

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