Click here to Skip to main content
15,889,216 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Delete documents from Printer Pin
Ananth3046-Jul-10 1:45
Ananth3046-Jul-10 1:45 
GeneralRe: Delete documents from Printer Pin
Ananth3046-Jul-10 2:01
Ananth3046-Jul-10 2:01 
GeneralRe: Delete documents from Printer Pin
Iain Clarke, Warrior Programmer6-Jul-10 2:15
Iain Clarke, Warrior Programmer6-Jul-10 2:15 
GeneralRe: Delete documents from Printer Pin
Ananth3046-Jul-10 2:23
Ananth3046-Jul-10 2:23 
GeneralRe: Delete documents from Printer Pin
Ananth3046-Jul-10 2:41
Ananth3046-Jul-10 2:41 
GeneralRe: Delete documents from Printer Pin
Ananth3046-Jul-10 2:42
Ananth3046-Jul-10 2:42 
GeneralRe: Delete documents from Printer Pin
«_Superman_»6-Jul-10 19:27
professional«_Superman_»6-Jul-10 19:27 
GeneralRe: Delete documents from Printer Pin
Ananth30413-Jul-10 0:54
Ananth30413-Jul-10 0:54 
Hi Superman,

When you asked me to change some part in the code it gave lot of runtime exception. And I couldn't solve it, so without any option I changed my code. This code is not giving any kind of exception when I tried to compile and it is printing fine. But if I try to delete the job its not doing that. To find that I tried to trace out the error using GetLastError(). It is giving 6. If am not wrong that means handler is invalid or might have closed. But till my knowledge is concerned am doing all the operations before I close the handler. And I don't think it is invalid since I used the same handler to print the job and it is working fine. So thats why I attached entire code here so that you can find the things easily. Speaking about the program, I used Borland C++ builder to build the project where I have used two Buttons in the GUI part. One to print and other is to delete the job. Sorry for taking much of your time but I need this program badly. Please help me........
//---------------------------------------------------------------------------

#include <windows.h>
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>

#include <winspool.h>
#include <vcl.h>
#pragma hdrstop

#include "reset.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void prinfun(bool val)
{
HANDLE hPrinter = 0;
DWORD dwBytesWritten=0;
string strDocName;
DWORD dwFileLength = 0;
char szData[512];


DWORD dwBufsize=0;
//int temp = GetLastError();
//char buf[300];

//strcpy(szData,"TEST TEST TEST TEST TEST");
strcpy(szData,"reafile.txt");

//if (OpenPrinter(szPrinterName, &hPrinter, NULL)) {
//if (OpenPrinter("Canon MF4320-4350", &hPrinter, NULL)) {

OpenPrinter("Canon MF4320-4350", &hPrinter, NULL);
DOC_INFO_1 DocInfo;

DocInfo.pDocName = "reafile.txt";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = _T("RAW");

//if (StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo)) {
//if (StartPagePrinter(hPrinter)) {
StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo);
StartPagePrinter(hPrinter);
 if(val == 0)
{
//BOOL bRet = WritePrinter(hPrinter, (void*)szData, strlen(szData) , &dwBytesWritten);
WritePrinter(hPrinter, (void*)szData, strlen(szData) , &dwBytesWritten);

}
else if(val == 1)
{
GetPrinter(hPrinter, 2, NULL, 0, &dwBufsize);
 SetPrinter(hPrinter, 0, NULL, PRINTER_CONTROL_PURGE);



}
free(hPrinter);
//bRet = SetPrinter(hPrinter,0,0,PRINTER_CONTROL_PURGE);
//sprintf(buf,"%d",temp);
//Form1->RichEdit1->Lines->Add(buf);
EndPagePrinter(hPrinter);
//}
EndDocPrinter(hPrinter);
//}
ClosePrinter(hPrinter);
//}

}

// commented this function

 /*void prindel()
{
HANDLE hPrinter;
char name[300] = "Canon MF4320-4350";
char szData[512];
int temp = GetLastError();
char buf[300];
DWORD dwBufsize=0;
OpenPrinter("Canon MF4320-4350", &hPrinter, NULL);
   GetPrinter(hPrinter, 2, NULL, 0, &dwBufsize);


BOOL bRetc = SetPrinter(hPrinter,0,0,PRINTER_CONTROL_PURGE);
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",temp);
Form1->RichEdit1->Lines->Add(buf);

ClosePrinter(hPrinter);


}*/







void __fastcall TForm1::printButton1Click(TObject *Sender)
{
int temp = GetLastError();
char buf[300];
prinfun(0);
ShowMessage("Everything is done successfully");
            sprintf(buf,"%d",temp);
           Form1->RichEdit1->Lines->Add(buf);
//exit(0);
/*HANDLE hPrinter;
char name[256]="Canon MF4320-4350";
int temp = GetLastError();
char buf[300];
OpenPrinter(name, &hPrinter,0);
sprintf(buf,"%d",temp);
Form1->RichEdit1->Lines->Add(buf);
SetPrinter(hPrinter,0,NULL,PRINTER_CONTROL_PURGE);
ShowMessage("Reset is done");
ClosePrinter( hPrinter );
return; */

}
//---------------------------------------------------------------------------
void __fastcall TForm1::deleteButton2Click(TObject *Sender)
{
int temp = GetLastError();
char buf[300];
prinfun(1);
ShowMessage(" printer jobs deleted");
            sprintf(buf,"%d",temp);
           Form1->RichEdit1->Lines->Add(buf);

}
//---------------------------------------------------------------------------

GeneralRe: Delete documents from Printer Pin
Ananth30414-Jul-10 1:57
Ananth30414-Jul-10 1:57 
GeneralRe: Delete documents from Printer Pin
David Crow6-Jul-10 4:29
David Crow6-Jul-10 4:29 
GeneralRe: Delete documents from Printer Pin
Ananth30413-Jul-10 18:53
Ananth30413-Jul-10 18:53 
GeneralRe: Delete documents from Printer Pin
David Crow19-Jul-10 2:46
David Crow19-Jul-10 2:46 
GeneralRe: Delete documents from Printer Pin
KarstenK6-Jul-10 3:02
mveKarstenK6-Jul-10 3:02 
QuestionHandling sysmenu new item event Pin
eyalle5-Jul-10 20:53
eyalle5-Jul-10 20:53 
AnswerRe: Handling sysmenu new item event Pin
«_Superman_»5-Jul-10 21:04
professional«_Superman_»5-Jul-10 21:04 
GeneralRe: Handling sysmenu new item event Pin
eyalle5-Jul-10 21:06
eyalle5-Jul-10 21:06 
GeneralRe: Handling sysmenu new item event Pin
«_Superman_»5-Jul-10 21:16
professional«_Superman_»5-Jul-10 21:16 
GeneralRe: Handling sysmenu new item event Pin
eyalle5-Jul-10 21:36
eyalle5-Jul-10 21:36 
GeneralRe: Handling sysmenu new item event Pin
«_Superman_»5-Jul-10 21:49
professional«_Superman_»5-Jul-10 21:49 
GeneralRe: Handling sysmenu new item event Pin
eyalle5-Jul-10 21:52
eyalle5-Jul-10 21:52 
GeneralRe: Handling sysmenu new item event Pin
«_Superman_»5-Jul-10 21:54
professional«_Superman_»5-Jul-10 21:54 
GeneralRe: Handling sysmenu new item event Pin
eyalle5-Jul-10 21:57
eyalle5-Jul-10 21:57 
GeneralRe: Handling sysmenu new item event Pin
«_Superman_»5-Jul-10 22:32
professional«_Superman_»5-Jul-10 22:32 
GeneralRe: Handling sysmenu new item event Pin
eyalle5-Jul-10 22:40
eyalle5-Jul-10 22:40 
QuestionSubclass list control with another controls inside Pin
Pavel Sokolov5-Jul-10 12:25
Pavel Sokolov5-Jul-10 12:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.