🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.os2.programmer.misc
1 messages
1 total messages Started by S�bastien JEAN-LOUIS Wed, 22 Jul 1998 00:00
Take a look at me now!!
#273
Author: S�bastien JEAN-LOUIS
Date: Wed, 22 Jul 1998 00:00
306 lines
9236 bytes
Good morning,

Please help me converting this source because WinAPI on printing are easy
but OS2 ones are tremendous!!!

Thanx





/***************************************************************************
*****************/






//ALL THE FUNCTION WITH FRENCH NAMES ARE MINE AND DON'T NEED TO BE CONVERTED
//ONLY WINDOWS FUNCTION NEED TO BE:

//AddJob,GetLastError,GetJob,SetJob,CloseHandle,ScheduleJob,GetProfileString
            //OpenPrinter,CreateFile,WriteFile,ClosePrinter      <- The most
important for me!
//AND THE VARIABLE:
//GENERIC_WRITE,FILE_SHARE_WRITE,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,INVALID_H
ANDLE_VALUE






#include "sysdpt.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <direct.h>

#define OUTIMPR

//MY INCLUDES
#include "globalnt.h"
#include "outil.h"
#include "outimpr.h"
#include "ressdpcl.h"

#define   TAILLE_BUF 64000

/*------------------------------Imprime/Print------------------------------
Send a file to designed printer or a default one
------------------------------------------------------------------------*/
BOOL Imprime(char *Imprimante,char *Fichier,char *NomDocument,short
Copies,BOOL GardeFichier)
{
  char   *ImprimanteDefaut;
  BOOL  Res=TRUE;

#ifdef DEBUGAGI
  agiprintf("D�but Imprime");
#endif
//Test de validit� de l'imprimante
  if(!TesteImprimante(Imprimante))
//L'imprimante donn�e n'est pas valide : recherche de l'imprimante par
d�faut
  {  ImprimanteDefaut=RecupImprimanteDefaut();
    if(!ImprimanteDefaut)
    {  LogWar(PTLOG,ID_PRINTER_DEF_NOK);
      Res=FALSE;
    }
//Copie du fichier dans le spool
    else
    {  Res=SpooleFichier(Fichier,ImprimanteDefaut,NomDocument,Copies);
      ImprimanteDefaut=Libere(ImprimanteDefaut);
    }
  }
  else
    Res=SpooleFichier(Fichier,Imprimante,NomDocument,Copies);

  if(!GardeFichier)
    SupprimeFichier(Fichier);


#ifdef DEBUGAGI
  agiprintf("Fin   Imprime");
#endif
  return(Res);
}


/*----------------------SpooleFichier/SpoolFile-----------------------------
-
Create a print job on a printer and warn the spooler
------------------------------------------------------------------------*/
BOOL SpooleFichier(char *Doc,char *Printer,char *NomJob,short Copies)
{
  HANDLE      hPrinter=(HANDLE)0;
  HANDLE      hPrint;

  ADDJOB_INFO_1  *Ajout=(ADDJOB_INFO_1 *)0;
  JOB_INFO_1     *pJobInfo=(JOB_INFO_1 *)0;


  DWORD       NbOctets=0;
  DWORD       Taille=0;
  BOOL        res=FALSE;
  DWORD       Error=0;
  DWORD       Temp=0;
  int         hFic;
  long        NbCar;
  char        *Buf;

#ifdef DEBUGAGI
  agiprintf("D�but SpoolFichier");
#endif
//Ouverture de l'imprimante fournie
  res=OpenPrinter(Printer,&hPrinter,0);
  if(!res)
  {  LogWar(PTLOG,ID_PRINTER_NOK,Printer,Doc);
    res=FALSE;
  }
  else
//Premi�re cr�ation de job pour r�cup�rer le nombre d'octets n�cessaires �
la
//structure contenant les informations sur le job
  {
    res=AddJob(hPrinter,(DWORD)1,(unsigned char *)Ajout,0,&NbOctets);
    if( (GetLastError()!=ERREUR_ADD_JOB) && (!res) && NbOctets)
    {  Ajout=(ADDJOB_INFO_1 *)Alloue(NbOctets);
//Deuxi�me cr�ation : cr�ation du job sur l'impriamante
      res=AddJob(hPrinter,(DWORD)1,(unsigned char *)Ajout,NbOctets,(DWORD
*)&Taille);
      if(res)
      {
        //Le job a �t� cr�� sur un spool local : modification du libell� du
document
        //Cette modification n'est pas possible sur un queue d�localis�e
        if(Ajout->JobId!=0xFFFFFFFF)
        {
  //        res=SetJob(hPrinter,Ajout->JobId,0,NULL,JOB_CONTROL_PAUSE);
          res=GetJob(hPrinter,Ajout->JobId,1,(LPBYTE)pJobInfo,0,&NbOctets);
          if(NbOctets)
          {  pJobInfo=(JOB_INFO_1 *)Alloue(NbOctets);

res=GetJob(hPrinter,Ajout->JobId,1,(LPBYTE)pJobInfo,NbOctets,&Taille);
            pJobInfo->pDocument=_Alloue(strlen(NomJob)+1);
            strcpy(pJobInfo->pDocument,NomJob);
          }
        }

hPrint=CreateFile(Ajout->Path,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_ALWAY
S,FILE_ATTRIBUTE_NORMAL,NULL);
        if(hPrint==INVALID_HANDLE_VALUE)
        {  LogWar(PTLOG,ID_PRN_COPY_NOK,NomJob,Printer);
        }
        else
        {
          hFic=OuvreFicR((char *)Doc);
          NbCar = PosFicFin(hFic);
          if(NbCar>0)
          {
            Buf=Alloue(TAILLE_BUF);
            for(;Copies;Copies--)
            {
              FicPosit(hFic,0L);
                do
                {
                res=LitFichier(hFic,Buf,TAILLE_BUF);
                res=WriteFile(hPrint,Buf,res,&Taille,NULL);
                 }while(res && Taille==TAILLE_BUF);
            }
            FermeFichier(hFic);
            Buf=Libere(Buf);

            if(Ajout->JobId!=0xFFFFFFFF)
            {  res=SetJob(hPrinter,Ajout->JobId,1,(LPBYTE)pJobInfo,0);
               if(pJobInfo->pDocument)
                 pJobInfo->pDocument=_Libere(pJobInfo->pDocument);
               pJobInfo=(JOB_INFO_1 *)Libere((char *)pJobInfo);
            }
            res=CloseHandle(hPrint);
            if(Ajout->JobId==0xFFFFFFFF)
            {  res=ScheduleJob(hPrinter,Ajout->JobId);
              if(!res)
              {  LogWar(PTLOG,ID_PRN_SCHED_NOK,NomJob,Printer);
              }
            }
          }
        }
      }
      else
      {  LogWar(PTLOG,ID_PRN_AJOUT_NOK,NomJob,Printer);
      }
    }
    else
    {  LogWar(PTLOG,ID_PRN_AJOUT_NOK,NomJob,Printer);
    }
//JRR 23/10/95
    if(Ajout)
      Ajout=(ADDJOB_INFO_1  *)Libere((char *)Ajout);
    ClosePrinter(hPrinter);
  }
  if(res)
    LogInf(PTLOG,ID_PRINTER_DEF,NomJob,Printer);

#ifdef DEBUGAGI
  agiprintf("Fin   SpoolFichier");
#endif
  return(res);
}

/*---------------------------RecupImprimanteDefaut-----------------------
Get the default printer
------------------------------------------------------------------------*/
char *RecupImprimanteDefaut()

{  char  *Buffer=(char*)0;
  char  *ImprimanteDefaut=(char *)0;
  DWORD  Res,i;

  ImprimanteDefaut=Alloue(LG_CHEMIN+1);
  Res=GetProfileString("windows","device",NULL,ImprimanteDefaut,LG_CHEMIN);
  if(!Res)
    ImprimanteDefaut=Libere(ImprimanteDefaut);
  else
  {  for(i=0;i<Res;i++)
      if(ImprimanteDefaut[i]==',')
      {  ImprimanteDefaut[i]=(char)0;
        break;
      }
  }
  return(ImprimanteDefaut);
}


/*------------------------------TesteImprimante--------------------------
Test if printer exist
------------------------------------------------------------------------*/
BOOL TesteImprimante(char *printer)

{  char  **Imprimantes=(char **)0;
  BOOL  Trouve=FALSE;
  HANDLE  hPrinter;
  short  i;

  ListeImprimantes(&Imprimantes);
  for(i=0;Imprimantes && Imprimantes[i];i++)
  {
    if(Imprimantes[i]==GTROU) continue;
    if(!strcmp(Imprimantes[i],printer))
    {
      if(OpenPrinter(printer,&hPrinter,0))
      {
        ClosePrinter(hPrinter);
        Trouve=TRUE;
      }
      break;
    }
  }
  if(Imprimantes)
    Imprimantes=(char**)LibereTable((void **)Imprimantes);

  return(Trouve);
}

/*-----------------------------ListeImprimantes--------------------------
Make a list of all the printers on local or network PC
------------------------------------------------------------------------*/
BOOL ListeImprimantes(char ***printers)

{
  LPPRINTER_INFO_2 TabPrinters;


  DWORD  NbOctets,NbPrinters,i;
  DWORD   Flags = PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL;

// appel pour conna�tre la taille du tableau
  EnumPrinters(Flags ,NULL,2,NULL,0,&NbOctets,&NbPrinters);

  TabPrinters=(LPPRINTER_INFO_2)Alloue(NbOctets+4);

  if(EnumPrinters(Flags
,NULL,2,(LPBYTE)TabPrinters,NbOctets,&NbOctets,&NbPrinters))
  {
    for(i=0;i<NbPrinters;i++)
      *printers=AjouteTabChar((char **)*printers,(char *)(TabPrinters +
i)->pPrinterName);
   }
  Libere((char*)TabPrinters);
  return(TRUE);
}

/***************************************************************************
*********************************/






--
sebjl@bigfoot.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads