|
-
April 15th, 2004, 04:02 AM
#1
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);
////////////////////////////////////////////
}
}
}
-
April 15th, 2004, 05:50 AM
#2
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.
-
April 15th, 2004, 06:16 AM
#3
Printing errors
Hi,
GetPrinterDc() returns the following 0x262103b5. which i guess is a valid handle.
Thanks and regards,
Salil.
-
April 15th, 2004, 09:52 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|