Newsgroup: it.comp.programmare.win32
Titolo: Eliminare la coda di stampa.

Vorrei poter eliminare la coda di stampa dall'interno di una .dll,
programmata in VC++, che non ha generato il documento da stampare:
come posso fare ?
Grazie 1000 per i consigli.

Lo ha scritto:
: Vorrei poter eliminare la coda di stampa dall'interno di una .dll,
: programmata in VC++, che non ha generato il documento da stampare:
: come posso fare ?
: Grazie 1000 per i consigli.
Prova a dare un'occhiata a questo frammento di codice con il quale avevo
affrontato il problema:
DWORD GetPrinterJobs(char* szPrinterName)
{
  HANDLE  hPrn;
  BOOL ret;
  DWORD pcbNeeded,pcReturned;
  DWORD dwRetVal;
  BYTE TempByte;
  PRINTER_DEFAULTS PrinterStruct;
  //JOB_INFO_1* pJobs;
  //dwApp = sizeof(JOB_INFO_1 );
  //dwApp = sizeof(JOB_INFO_2 );
  ZeroMemory(&PrinterStruct,sizeof(PrinterStruct));
  PrinterStruct.pDatatype = NULL;
  PrinterStruct.DesiredAccess = PRINTER_ACCESS_USE;
  //Get the printer Handle
  ret = OpenPrinter(szPrinterName, &hPrn, &PrinterStruct);
  //Get the Printer active jobs
  ret = EnumJobs(hPrn, 0, 127, 1, &TempByte, 1, &pcbNeeded, &pcReturned);
  if (pcbNeeded == 0 )
  {
    dwRetVal = 0;
  }
  else
  {
    BYTE* pByteBuffer;
    pByteBuffer = (BYTE*) HeapAlloc (GetProcessHeap(), HEAP_NO_SERIALIZE,
pcbNeeded);
    // 1 significa: dammi la struttura JOB_INFO_1
    ret = EnumJobs(hPrn, 0, 127, 1 , pByteBuffer, pcbNeeded, &pcbNeeded,
&pcReturned);
    HeapFree (GetProcessHeap(), 0, (LPVOID) pByteBuffer);
    dwRetVal = pcReturned;
  }
  //Close printer
  ret = CloseHandle(hPrn);
  return dwRetVal;
}
DWORD ViewPrinterJobs(char* szPrinterName)
{
  HANDLE  hPrn;
  BOOL ret;
  DWORD pcbNeeded,pcReturned;
  DWORD dwRetVal;
  BYTE TempByte;
  PRINTER_DEFAULTS PrinterStruct;
  JOB_INFO_1* pJobs;
  static DWORD dwStatus[1]={0};
  //dwApp = sizeof(JOB_INFO_1 );
  //dwApp = sizeof(JOB_INFO_2 );
  ZeroMemory(&PrinterStruct,sizeof(PrinterStruct));
  PrinterStruct.pDatatype = NULL;
  PrinterStruct.DesiredAccess = PRINTER_ACCESS_USE;
  //Get the printer Handle
  ret = OpenPrinter(szPrinterName, &hPrn, &PrinterStruct);
  //Get the Printer active jobs
  ret = EnumJobs(hPrn, 0, 1, 1, &TempByte, 1, &pcbNeeded, &pcReturned);
  if (pcbNeeded == 0 )
  {
    dwRetVal = 0;
    dwStatus[0] = 0;
    dwStatus[1] = 0;
  }
  else
  {
    BYTE* pByteBuffer;
    DWORD dwJobId;
    CHAR szApp[MAX_PATH];
    CHAR szStatus[30];
    pByteBuffer = (BYTE*) HeapAlloc (GetProcessHeap(), HEAP_NO_SERIALIZE,
pcbNeeded);
    // 1 significa: dammi la struttura JOB_INFO_1
    ret = EnumJobs(hPrn, 0, 1, 1 , pByteBuffer, pcbNeeded, &pcbNeeded,
&pcReturned);
    pJobs = (JOB_INFO_1*) pByteBuffer;
    dwJobId = pJobs->JobId;
    GetDescJobStatus(szStatus,pJobs->Status);
    wsprintf(szApp,"%02d - %s -
%s",pJobs->Position,pJobs->pDocument,szStatus);
    if ((pJobs->JobId!=dwStatus[0]) || (pJobs->Status!=dwStatus[1]))
    {
      ListBox_InsertString( hwndlstJobs, 0, szApp);
      dwStatus[0] = pJobs->JobId;
      dwStatus[1] = pJobs->Status;
    }
    if (Button_GetCheck(hwndchkKillJob))
    {
      //if (Button_GetCheck(hwndchkKillJobMode) || (pJobs->Status==))
      SetJob(hPrn,dwJobId,1,(LPBYTE)pJobs,JOB_CONTROL_CANCEL);
    }
    if (Button_GetCheck(hwndchkPausaJob))
    {
      SetJob(hPrn,dwJobId,1,(LPBYTE)pJobs,JOB_CONTROL_PAUSE);
    }
    HeapFree (GetProcessHeap(), 0, (LPVOID) pByteBuffer);
    dwRetVal = pcReturned;
  }
  //Close printer
  ret = CloseHandle(hPrn);
  return dwRetVal;
}
CHAR* GetPrnDefName(CHAR* sz)
{
    PRINTER_INFO_5 prninfo5[3];
    DWORD dwN,dwR;
    EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, (LPBYTE) prninfo5,
sizeof(prninfo5), &dwN, &dwR) ;
    lstrcpy(sz,prninfo5[0].pPrinterName);
    return sz;
}
CHAR* GetDescJobStatus(CHAR* desc, DWORD status)
{
  CHAR szApp[50];
  lstrcpy(szApp,"?");
  switch (status)
  {
    case JOB_STATUS_DELETING:
      lstrcpy(szApp,"Eliminata");
      break;
    case JOB_STATUS_ERROR:
      lstrcpy(szApp,"Errore");
      break;
    case JOB_STATUS_OFFLINE:
      lstrcpy(szApp,"OffLine");
      break;
    case JOB_STATUS_PAPEROUT:
      lstrcpy(szApp,"No carta");
      break;
    case JOB_STATUS_PAUSED:
      lstrcpy(szApp,"Pausa");
      break;
    case JOB_STATUS_PRINTED:
      lstrcpy(szApp,"Stampata");
      break;
    case JOB_STATUS_PRINTING:
      lstrcpy(szApp,"In stampa");
      break;
    case JOB_STATUS_SPOOLING:
      lstrcpy(szApp,"In spooling");
      break;
  }
  wsprintf(desc,"%s [%d]",szApp,status);
  return desc;
}