Solved

StartDoc() returns negative, but no error.

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need more details 5 184
Using MS Code on my Mac 6 72
Why is "packages element is not declared"? 2 462
SSRS Deployment problem 5 97
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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