views:

97

answers:

0

I have a problem with printing in C++. As far as I know, this code used to work on my previous printer, but ever since I got another one (an HP C7280) it started giving problems. Whenever I try to print anything, even an empty page, the page JAMS the printer. I have to manualy remove the page from the printer. I have no clue why this is happening. Am I doing something wrong, is it a driver problem, are there better ways to print in C++? I am using Windows 7 64 bit, but this problem also presented itself when I was using Windows Vista 64 bit. I use the following code:

PRINTDLG pd;
ZeroMemory(&pd, sizeof(pd));
pd.lStructSize = sizeof(pd);
pd.hwndOwner   = mainWindow;
pd.hDevMode    = NULL;
pd.hDevNames   = NULL;     
pd.Flags       = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
pd.nCopies     = 1;
pd.nMinPage    = 1;
pd.nMaxPage    = 0xFFFF;

if (PrintDlg(&pd)==TRUE) 
{
    DOCINFO di;

    di.cbSize       = sizeof(DOCINFO);
    di.lpszDocName  = "Rumitec en Roblaco Print";
    di.lpszOutput   = (LPTSTR)NULL;
    di.fwType       = 0;

     // Start printing
    StartDoc(pd.hDC, &di);
    StartPage(pd.hDC);
    initPrinter(pd.hDC);

    // ...
    // Do some drawing
    // ...

    // End printing
    EndPage(pd.hDC);
    EndDoc(pd.hDC);
    DeleteDC(pd.hDC);
}

Am I doing something wrong? Alternatively, is there a better, easier, more modern way to do it?

EDIT: I can print from ANY other application without paper jams. Notepad, Word, etc, every other application can print just fine.