Hi All,
I am new to this forum and also to C++ program. I tried a program to send the jobs to the printer and to delete the jobs from the printer. For this I have used win32 API. But it doesn't work. I did this with the help of Borland builder. I have attached part of the code which would help you to find the solution. I need the solution soon since am in urgent.. Please help me with this concept.
Code:long bufsize=0x100; char *prnname = "Canon MF4320-4350"; char buf[ 300]; int temp = GetLastError(); char szData[512]; GetProfileStringA("Windows", "Device", ",,,", prnname, bufsize); HANDLE hPrinter; if ( OpenPrinter("Canon MF4320-4350", &hPrinter, NULL) == 0 ) { free(prnname); ShowMessage("OpenPrinter call failed"); return 0; } DWORD dwBufsize=0; DWORD dwBytesWritten=0; DOC_INFO_1 DocInfo; DocInfo.pDocName = "realfile.txt"; DocInfo.pOutputFile = NULL; DocInfo.pDatatype = _T("RAW"); StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo); StartPagePrinter(hPrinter); WritePrinter(hPrinter, (void*)szData, strlen(szData) , &dwBytesWritten); GetPrinter(hPrinter, 2, NULL, 0, &dwBufsize); PRINTER_INFO_2* pinfo = (PRINTER_INFO_2*)malloc(dwBufsize); long result = GetPrinter(hPrinter, 2, (LPBYTE)pinfo, dwBufsize, &dwBufsize); if ( pinfo->cJobs == 0 ) { ShowMessage("No printer jobs found."); sprintf( buf, "%d", temp); Form1->RichEdit1->Lines->Add( buf); } else { if ( SetPrinter(hPrinter, 0, 0, PRINTER_CONTROL_PURGE) == 0 ) { ShowMessage("SetPrinter call failed"); sprintf( buf, "%d", temp); Form1->RichEdit1->Lines->Add( buf); } else { ShowMessage("Number of printer jobs deleted"); sprintf( buf,"%d", pinfo->cJobs); Form1->RichEdit1->Lines->Add( buf); free(pinfo); free(prnname); } } ClosePrinter( hPrinter ); free(pinfo); free(prnname); return 0; }



LinkBack URL
About LinkBacks


