[archive] Fax from ACUCOBOL-GT using Windows Fax services

[Migrated content. Thread originally posted on 30 June 2009]

My colleague Claudio has created this nice little example on how to send fax from ACUCOBOL-GT using the Windows Fax Services.
Thought we should share it with you, as I seem to remember there were an inquiry for this some time ago.

To run this, you have to generate the fxcomdef.def using AxDefGen.exe.
You also need to provide the document to fax.


       IDENTIFICATION DIVISION.
       PROGRAM-ID. fax-from-cobol.
       ENVIRONMENT DIVISION.
       CONFIGURATION                SECTION.
       SPECIAL-NAMES.
           COPY    "fxscomex.def".
                   .
       DATA        DIVISION.
       WORKING-STORAGE              SECTION.
       01 ERROR-INFO.
          03  ERROR-INFO-RESULT    USAGE UNSIGNED-INT.
          03  ERROR-INFO-FACILITY  USAGE UNSIGNED-SHORT.
          03  ERROR-INFO-CODE      USAGE UNSIGNED-SHORT.
       01 ERROR-SOURCE               PIC X(50).
       01 ERROR-DESCRIPTION          PIC X(200).
       01 ERROR-HELP-FILE            PIC X(50).
       01 ERROR-HELP-CONTEXT         USAGE UNSIGNED-LONG.

       77  hdlFax                   HANDLE OF FaxServer.
       77  hdlFaxDoc                HANDLE OF FaxDocument.
       77  JobID                    PIC S9(9) COMP-5.

       77  ws-cover-path            PIC x(50) VALUE
                    "C:\mycover.cov".
       77  ws-doc-path               PIC x(50) VALUE
                    "C:\myfaxdocument.rtf".

       PROCEDURE DIVISION.
       DECLARATIVES.
      *COM-ERROR SECTION.
      *     USE AFTER STANDARD EXCEPTION ON OBJECT.
      *     CONTINUE.
       OBJECT-EXCEPTION SECTION.
           USE AFTER EXCEPTION ON OBJECT.
       OBJECT-EXCEPTION-HANDLER.
           CALL    "C$EXCEPINFO"    USING
                   ERROR-INFO
                   ERROR-SOURCE
                   ERROR-DESCRIPTION
                   ERROR-HELP-FILE
                   ERROR-HELP-CONTEXT.
           IF ERROR-INFO-RESULT NOT = 2147614725
              DISPLAY MESSAGE BOX "Uknown error"
              GOBACK
           ELSE
              INITIALIZE ERROR-INFO-RESULT
              | This is an error we have no explanation of, the
              | fax goes just fine, so we just ignore this error.
           END-IF
       END DECLARATIVES.   
       Main.

      * To have further info:
      * [URL]msdn.microsoft.com/.../URL]
      * [URL]sandlerco.com/.../URL]

           CREATE  FaxServer        OF FAXCOMEXLib
                   HANDLE           IN hdlFax.   

           MODIFY  hdlFax           @connect = "".     

           CREATE  FaxDocument      OF FAXCOMEXLib
                   HANDLE           IN hdlFaxDoc.   

      * Optionally, set the sender properties.                         
      *    MODIFY  hdlFaxDoc        @Sender::Name = "".
      *    MODIFY  hdlFaxDoc        @Sender::Email = "".                         
      *    MODIFY  hdlFaxDoc        @Sender::FaxNumber = "".

      * Cover page's subject field
           MODIFY  hdlFaxDoc        @Subject =
                                      "Fax from ACUCOBOL-GT".
      * Document's friendly name           
           MODIFY  hdlFaxDoc        @DocumentName =
                                     "Test of Fax functionality".

      * Add recipient's fax number. If this string contains a canonical fax number
      * (starting with plus followed by country code, area code in round brackets and the fax number),
      * the Fax Service will translate that number into dialable format in accordance with your current location.
      * Otherwise, make sure the international prefix or long distance prefix is specified when needed,
      * as the fax number will be passed on to a fax driver (Fax Service Provider) unchanged.
      * For example, sending a fax from San Francisco to Sydney's fax number 123456, the canonical address
      * 61(2)123456 will be translated into dialable address 011612123456.
      * If you are using T37FSP in conjunction with Internet Fax Service, specify absolute address
      * 612123456 (without leading plus, to avoid translation into dialable format),
      * as Internet Fax Service expects the number in the absolute format.
           MODIFY  hdlFaxDoc        @Recipients::Add ("00523623155").



      * The CoverPage property is a null-terminated string that contains the name
      * of the cover page template file (.cov) to associate with the fax document.
      * This .cov file has to be associated with an application that is installed on the computer,
      * and the application has to support the PrintTo verb; otherwise, the fax will fail.
      * To specify a server-based cover page file, you must set the FaxDocument.CoverPageType property to 2.
      * To specify a local or personal cover page file, you must set the FaxDocument.CoverPageType property to 1.
      *    MODIFY  hdlFaxDoc        @CoverPageType = 1
      *    MODIFY  hdlFaxDoc        @CoverPage = ws-cover-path.

      * The Note property is a null-terminated string that contains the contents
      * of the note field on the cover page of the fax.   
      *    MODIFY  hdlFaxDoc        @Note =
      *                      "For the kind attention of Sales Office". 


      * The Body property provides the path to the file that comprises the body of a fax.
      * The body of a fax consists of the fax pages other than the cover page.   
      * Examples of documents that you can send as a fax body are a text file (.txt),
      * a Microsoft Word document (.doc), or a Microsoft Excel spreadsheet (.xls).
      * When you send a fax from a client computer, the body has to be associated
      * with an application that is installed on that computer, and the application
      * has to support the PrintTo verb; otherwise, the fax will fail.                         
           MODIFY  hdlFaxDoc        @BODY = ws-doc-path.



      * Submit the document to the connected fax server and get back the job ID.
           MODIFY  hdlFaxDoc        @ConnectedSubmit(hdlFax)
                   GIVING           JobID     

           DESTROY hdlFax.
           DESTROY hdlFaxDoc.

           ACCEPT  OMITTED.

           stop run.
  • Hello Queenofmean, to restore Windows Fax Service on your printer you have to go for these steps as I believe that they will help you in fixing this issue. Learn more about how to restore Windows Fax service on your printer go for that site now. As first step just connect to your CocoFax interface and tap on the option of Settings. Here you are supposed to arrange or get the email address to obtain your PDF fax. In case Automatic Email Manager is not connected on your PC, just download and install it and press on the option that says Accounts and then go for 'Add account. Now add the email address which will receive your faxes and go for the on screen commands. The time when account is arranged, you just have to include the action Print Attachment(s).