home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / drgwps.zip / commdata.c next >
C/C++ Source or Header  |  1993-08-02  |  7KB  |  128 lines

  1. /*********************************************************************
  2.  *                                                                   *
  3.  * MODULE NAME :  commdata.c             AUTHOR:  Rick Fishman       *
  4.  * DATE WRITTEN:  08-01-93                                           *
  5.  *                                                                   *
  6.  * DESCRIPTION:                                                      *
  7.  *                                                                   *
  8.  *   This module is part of the DRGPMWPS sample program. It is used  *
  9.  *   by both DRGPMWPS.EXE and DRGAGENT.DLL. It allocates and controls*
  10.  *   a shared memory segment that is common to both modules.         *
  11.  *                                                                   *
  12.  * CALLABLE FUNCTIONS:                                               *
  13.  *                                                                   *
  14.  *   CommdataCreate                                                  *
  15.  *   CommdataDestroy                                                 *
  16.  *                                                                   *
  17.  * HISTORY:                                                          *
  18.  *                                                                   *
  19.  *  08-01-93 - Started coding.                                       *
  20.  *                                                                   *
  21.  *  Rick Fishman                                                     *
  22.  *  Code Blazers, Inc.                                               *
  23.  *  4113 Apricot                                                     *
  24.  *  Irvine, CA. 92720                                                *
  25.  *  CIS ID: 72251,750                                                *
  26.  *                                                                   *
  27.  *********************************************************************/
  28.  
  29. #pragma strings(readonly)
  30.  
  31. /*********************************************************************/
  32. /*------- Include relevant sections of the OS/2 header files --------*/
  33. /*********************************************************************/
  34.  
  35. #define  INCL_DOSERRORS
  36. #define  INCL_DOSPROCESS
  37. #define  INCL_DOSMEMMGR
  38.  
  39. /**********************************************************************/
  40. /*----------------------------- INCLUDES -----------------------------*/
  41. /**********************************************************************/
  42.  
  43. #define GLOBALS_DEFINED
  44.  
  45. #include <os2.h>
  46. #include <stdarg.h>
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <string.h>
  50. #include "common.h"
  51.  
  52. /*********************************************************************/
  53. /*------------------- APPLICATION DEFINITIONS -----------------------*/
  54. /*********************************************************************/
  55.  
  56. #define MEM_NAME  "\\SHAREMEM\\CBLAZERS\\DRGPMWPS\\COMMDATA.MEM"
  57.  
  58. /**********************************************************************/
  59. /*---------------------------- STRUCTURES ----------------------------*/
  60. /**********************************************************************/
  61.  
  62. /**********************************************************************/
  63. /*----------------------- FUNCTION PROTOTYPES ------------------------*/
  64. /**********************************************************************/
  65.  
  66.  
  67. /**********************************************************************/
  68. /*------------------------ GLOBAL VARIABLES --------------------------*/
  69. /**********************************************************************/
  70.  
  71.  
  72. /**********************************************************************/
  73. /*------------------------- CommdataCreate ---------------------------*/
  74. /*                                                                    */
  75. /*  CREATE THE SHARED MEMORY USED TO HOLD COMMON DATA.                */
  76. /*                                                                    */
  77. /*  PARMS: nothing                                                    */
  78. /*                                                                    */
  79. /*  NOTES:                                                            */
  80. /*                                                                    */
  81. /*  RETURNS: nothing                                                  */
  82. /*                                                                    */
  83. /*--------------------------------------------------------------------*/
  84. /**********************************************************************/
  85. void CommdataCreate()
  86. {
  87.     APIRET rc;
  88.  
  89.     rc = DosGetNamedSharedMem( (PPVOID) &pCommData, MEM_NAME,
  90.                                PAG_READ | PAG_WRITE );
  91.     if( rc )
  92.     {
  93.         if( rc == ERROR_FILE_NOT_FOUND )
  94.         {
  95.             rc = DosAllocSharedMem( (PPVOID) &pCommData, MEM_NAME,
  96.                                     sizeof( COMMDATA ),
  97.                                     PAG_COMMIT | PAG_READ | PAG_WRITE );
  98.             if( rc )
  99.                 Msg( "CommdataCreate DosAllocSharedMem failed! rc:%u", rc );
  100.         }
  101.         else
  102.             Msg( "CommdataCreate DosGetNamedSharedMem failed! rc:%u", rc );
  103.     }
  104. }
  105.  
  106. /**********************************************************************/
  107. /*------------------------- CommdataDestroy --------------------------*/
  108. /*                                                                    */
  109. /*  DESTROY THE SHARED COMMON DATA.                                   */
  110. /*                                                                    */
  111. /*  PARMS: nothing                                                    */
  112. /*                                                                    */
  113. /*  NOTES:                                                            */
  114. /*                                                                    */
  115. /*  RETURNS: nothing                                                  */
  116. /*                                                                    */
  117. /*--------------------------------------------------------------------*/
  118. /**********************************************************************/
  119. void CommdataDestroy()
  120. {
  121.     if( pCommData )
  122.         DosFreeMem( pCommData );
  123. }
  124.  
  125. /*************************************************************************
  126.  *                     E N D     O F     S O U R C E                     *
  127.  *************************************************************************/
  128.