home *** CD-ROM | disk | FTP | other *** search
/ IBM CD Showcase / OS2_CD_ROM.iso / smce0001 / faxpm / demo / api0 / FAXEXIT2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-10  |  5.8 KB  |  169 lines

  1. /*****************************************************************************
  2. /*
  3. /* File         FAXEXIT2.C
  4. /*
  5. /* Description  This file is a sample for the RECEIVEDFAX function. This
  6. /*              function is run when a fax has just been received, and is
  7. /*              located in the FAXEXIT2.DLL file.
  8. /*              This program describes how to use the RECEIVEDFAX function.
  9. /*              This function just calls the Fax/PM Viewer to display the
  10. /*              received fax.
  11. /*
  12. /* Functions    RECEIVEDFAX
  13. /*              GetFaxPMPath      [static]
  14. /*
  15. /* Last modif   March 15, 1993
  16. /*
  17. /* Copyright    (c) Microformatic S.A. 1993
  18. /*
  19. /*****************************************************************************/
  20.  
  21.  
  22. /*****************************************************************************
  23. /* Includes
  24. /*****************************************************************************/
  25.  
  26. #define INCL_DOS
  27. #define INCL_WIN
  28. #define INCL_GPI
  29. #include <os2.h>
  30.  
  31. #include <memory.h>
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <string.h>
  35.  
  36.  
  37. /*****************************************************************************
  38. /* Defines
  39. /*****************************************************************************/
  40.  
  41. #define MEMORY_4K 4096
  42. #define PAG_RWC PAG_READ | PAG_WRITE | PAG_COMMIT
  43. #define PROGRAM_NAME  "FaxView.Exe"
  44. #define FAXPM_ENV_VAR "FAXPM"
  45.  
  46.  
  47. /*****************************************************************************
  48. /* Prototypes
  49. /*****************************************************************************/
  50.  
  51. static APIRET APIENTRY GetFaxPMPath (PSZ pszPath) ;
  52.  
  53.  
  54. /*****************************************************************************
  55. /*
  56. /* Function     RECEIVEDFAX
  57. /*
  58. /* Description  Called when a fax has been received.
  59. /*
  60. /* Parameters   PSZ pszFile : complete name of the received fax.
  61. /*              PSZ pszId : remote fax identifier. This may be a NULL string.
  62. /*              ULONG ulChannel : channel. For Fax/PM 2.0 standalone, this
  63. /*                                number is always 1.
  64. /*
  65. /* Return code  APIRET. In Fax/PM 2.0 standalone, the return code is ignored.
  66. /*
  67. /****************************************************************************/
  68.  
  69. APIRET APIENTRY RECEIVEDFAX ( PSZ pszFile, PSZ pszId, ULONG ulChannel ) {
  70.  
  71.   ULONG ulRc ;                        /* return code for function calls      */
  72.   PSZ pszProgram ;                    /* program name                        */
  73.   PSZ pszArgument0 ;                  /* 1st argument = program name         */
  74.   PSZ pszArguments ;                  /* program arguments                   */
  75.   RESULTCODES RcExec ;                /* result codes of the program         */
  76.  
  77.  
  78.   /***************************************************************************
  79.   /* Allocate memory for the environment
  80.   /**************************************************************************/
  81.   ulRc = DosAllocMem ((PPVOID)&pszProgram, MEMORY_4K, PAG_RWC) ;
  82.   if (ulRc) {
  83.     return 1L ;
  84.   }
  85.   pszArgument0 = &pszProgram [1024] ;
  86.  
  87.  
  88.   /***************************************************************************
  89.   /* Get the Fax/PM path
  90.   /**************************************************************************/
  91.   GetFaxPMPath (pszProgram) ;
  92.  
  93.  
  94.   /***************************************************************************
  95.   /* Build the program name and the arguments list.
  96.   /**************************************************************************/
  97.   strcat (pszProgram, PROGRAM_NAME) ;
  98.   strcpy (pszArgument0, pszProgram) ;
  99.   pszArguments = &pszArgument0[strlen(pszArgument0)+1] ;
  100.   strcpy (pszArguments, pszFile) ;
  101.  
  102.  
  103.   /***************************************************************************
  104.   /* Run the program
  105.   /**************************************************************************/
  106.   ulRc = DosExecPgm (NULL, 0L, EXEC_ASYNC, pszArgument0, NULL, &RcExec,
  107.                      pszProgram) ;
  108.  
  109.  
  110.   /***************************************************************************
  111.   /* Terminate
  112.   /**************************************************************************/
  113.   DosFreeMem ((PVOID)pszProgram) ;
  114.   
  115.   return ulRc ;
  116.  
  117. }
  118.  
  119.  
  120. /*****************************************************************************
  121. /*
  122. /* Function     GetFaxPMPath            [static]
  123. /*
  124. /* Description  This function returns the Fax/PM path. The path is retrieved
  125. /*              from the FAXPM environment variable path. It is returned with
  126. /*              a terminating backslash. If no path is found, the current
  127. /*              directory is assumed.
  128. /*
  129. /* Parameters   PSZ pszPath : receives the Fax/PM path.
  130. /*
  131. /* Return code  0
  132. /*
  133. /****************************************************************************/
  134.  
  135. static APIRET APIENTRY GetFaxPMPath ( PSZ pszPath ) {
  136.  
  137.   ULONG ulRc ;                        /* return code for function calls      */
  138.   PSZ pszEnvVar ;                     /* environment variable                */
  139.   PCHAR pchLast ;                     /* last character in the string        */
  140.  
  141.  
  142.   /***************************************************************************
  143.   /* Query the environment variable
  144.   /**************************************************************************/
  145.   ulRc = DosScanEnv (FAXPM_ENV_VAR, &pszEnvVar) ;
  146.   if (ulRc) {
  147.    strcpy (pszPath, ".\\") ;
  148.    return 0L ;
  149.   }
  150.   else {
  151.     strcpy (pszPath, pszEnvVar) ;
  152.   }
  153.  
  154.  
  155.   /***************************************************************************
  156.   /* Removes terminating '\' or ';' and adds a '\'
  157.   /**************************************************************************/
  158.   pchLast = &pszPath [strlen(pszPath)-1] ;
  159.   if (*pchLast=='\\' || *pchLast==';') {
  160.     *pchLast='\\' ;
  161.   }
  162.   else {
  163.     strcat (pszPath, "\\") ;
  164.   }
  165.  
  166.   return 0l ;
  167.  
  168. }
  169.