CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Printing Error

  1. #1
    Join Date
    Mar 2004
    Posts
    22

    Printing Error

    Hi,
    I get "memory couldnot be read" error at StartDoc().
    Here is my code, can anyone tell me why this error occurs.

    Thank you and regards,
    Salil.

    void CAprsView::Onfileprint()
    {
    // TODO: Add your command handler code here
    CPrintDialog dlg(FALSE);
    if(dlg.DoModal()) {
    BOOL b = InitBmpData(); // combines 5 bitmaps and creates one large bitmap.
    dlg.GetDefaults();
    HDC hdcPrinter = dlg.GetPrinterDC();
    if(hdcPrinter == NULL) {
    MessageBox(_T("Printer Not Found"));
    }
    else {
    CDC dcPrinter;
    dcPrinter.Attach(hdcPrinter);
    ////////////////////////////////////////////
    CDC dcMem;
    dcMem.CreateCompatibleDC(&dcPrinter);
    CBitmap* pOldBmp = dcMem.SelectObject(&m_BmpLarge);// holds the large bmp
    ////////////////////////////////////////////
    DOCINFO docinfo;
    memset(&docinfo,0,sizeof(&docinfo));
    docinfo.cbSize = sizeof(docinfo);
    docinfo.lpszDocName = _T("Bitmap");

    if(dcPrinter.StartDoc(&docinfo) < 0) { // error at this step, memeory cannot be read.
    MessageBox(_T("Printer did not initialize"));
    } else {
    if(dcPrinter.StartPage() < 0) {
    MessageBox(_T("Could not start page"));
    dcPrinter.AbortDoc();
    } else {
    dcPrinter.BitBlt(0,0,len_in_pix,ht_in_pix, &dcMem,0,0,SRCCOPY);
    }
    }
    dcPrinter.EndPage();
    dcPrinter.EndDoc();
    ////////////////////////////////////////////
    dcMem.SelectObject(pOldBmp);
    ////////////////////////////////////////////
    }
    }

    }

  2. #2
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939
    Are you getting a valid HDC returned from GetPrinterDC()?
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  3. #3
    Join Date
    Mar 2004
    Posts
    22

    Printing errors

    Hi,

    GetPrinterDc() returns the following 0x262103b5. which i guess is a valid handle.

    Thanks and regards,
    Salil.

  4. #4
    Join Date
    Sep 1999
    Location
    Germany, Hessen
    Posts
    226
    The only thing I can see in your code is

    if(dlg.DoModal()) {


    ... I think it should be:

    if(dlg.DoModal() == IDOK ) {

    what happens when you try

    if ( ::StartDoc( hdcPrinter, &docinfo ) <= 0 ) {
    int err = GetLastError();
    }

    ??????

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured