Interprocess Communication Using Shared Memory (Part 1)

REQUEST *Request;                               /* Request structure     */
REPLY   *Reply;                                 /* Reply structure ptr   */
  :
CASE WMP_SENDREQUEST:
     rc = DosAllocShrMem(&Request,              /* Allocate memory obj   */
                         NULL,                  /* Anonymous memory obj  */
                         sizeof(REQUEST),       /* Size of memory obj    */
                         OBJ_GIVEABLE,          /* Object is giveable    */
                         PAG_WRITE |            /* Allow write access    */
                         PAG_READ  |            /* Allow read access     */
                         PAG_COMMIT);           /* Commit storage now    */
     rc = DosGiveSharedMem(Request,             /* Give access to object */
                           pidServer,           /* Process to get access */
                           PAG_WRITE |          /* Write access allowed  */
                           PAG_READ);           /* Read access allowed   */

     rc = DosAllocShrMem(&Reply,                /* Allocate memory obj   */
                         NULL,                  /* Anonymous memory obj  */
                         sizeof(REPLY),         /* Size of memory obj    */
                         OBJ_GIVEABLE,          /* Object is giveable    */
                         PAG_WRITE |            /* Allow write access    */
                         PAG_READ  |            /* Allow read access     */
                         PAG_COMMIT);           /* Commit storage now    */
     rc = DosGiveSharedMem(Reply,               /* Give access to object */
                           pidServer,           /* Process to get access */
                           PAG_WRITE |          /* Write access allowed  */
                           PAG_READ);           /* Read access allowed   */

     Request->hRequester = hWnd;                /* Set requester handle  */

     <Initialize other Request structure fields>

     WinPostMsg(hServer,                        /* Post msg to server    */
                WMP_DOREQUEST,                  /* DO_REQUEST message    */
                (MPARAM)Request,                /* Ptr to request object */
                (MPARAM)Reply);                 /* Ptr to reply object   */

     DosFreeMem(Request);                       /* Release request obj   */
     break;
       :
case WMP_REQUESTCOMPLETE:
     Reply=(PVOID)mp1;

     <Copy contents of Reply to private memory>

     DosFreeMem(Reply);                         /* Release reply object  */
     break;

This example shows a "requester" window procedure issuing requests and receiving replies by way of Presentation Manager messages.


[Back: Terminating a Process]
[Next: Interprocess Communication Using Shared Memory (Part 2)]