--- os2sdk/demos/examples/pipes/pipes.c 2018/08/09 12:25:13 1.1 +++ os2sdk/demos/examples/pipes/pipes.c 2018/08/09 12:26:11 1.1.1.2 @@ -1,22 +1,31 @@ /*** pipes.c - parent program * - * Example of DOSMAKEPIPE usage in parent/child communication + * Example of DosMakePipe usage in parent/child communication * * This program gets some shared memory, makes a pipe, writes * a string into it, and then execs a child. The child gets * the shared memory segment, then reads from the pipe using * the handle passed in the shared memory segment. + * + * Created by Microsoft Corp. 1987 */ + +#define INCL_DOSPROCESS +#define INCL_DOSFILEMGR +#define INCL_DOSMEMMGR +#define INCL_DOSQUEUES + +#include #include -#include +#include typedef struct { /* structure of shared mem segment */ - unsigned read_handle; /* pipe read handle */ - unsigned write_handle; /* pipe write handle */ + SHANDLE read_handle; /* pipe read handle */ + SHANDLE write_handle; /* pipe write handle */ } SharedData; SharedData far *fp; /* pointer to shared memory */ -unsigned mem_handle; /* selector of the allocated segment */ +SEL mem_handle; /* selector of the allocated segment */ main() @@ -28,21 +37,21 @@ main() char *pgmname = "pchild.exe"; /* name of child program */ int i; int retcode; /* holds return code from call */ - struct ResultCodes tcodes; /* termination codes from DosExecPgm */ + RESULTCODES tcodes; /* termination codes from DosExecPgm */ unsigned far *fpinit; /* pointer to shared memory */ - unsigned buflen; /* DosWrite buffer length */ - unsigned memsiz = 1024; /* size of memory segment requested */ - unsigned pipe_size; /* size to reserve for the pipe */ - unsigned written; /* number bytes written by DosWrite */ + USHORT buflen; /* DosWrite buffer length */ + USHORT memsiz = 1024; /* size of memory segment requested */ + USHORT pipe_size; /* size to reserve for the pipe */ + USHORT written; /* number bytes written by DosWrite */ /* allocate 1k shared memory segment and initialize it */ printf("Getting shared memory segment\n"); - retcode = DOSALLOCSHRSEG( memsiz, (char far *)pname, - (unsigned far *)&mem_handle); + retcode = DosAllocShrSeg( memsiz, (PSZ)pname, + (PSEL)&mem_handle); /* create pointers to shared memory segment */ - fp = (SharedData far *)(((unsigned long)mem_handle << 16) | 0); - fpinit = (unsigned far *)(((unsigned long)mem_handle << 16) | 0); + fp = (SharedData far *)MAKEP(mem_handle,0); + fpinit = (unsigned far *)MAKEP(mem_handle,0); /* zero initialize the segment */ for (i = 0; i < memsiz / 2; i++) { @@ -53,8 +62,8 @@ main() /* make the pipe */ pipe_size = 0; /* use default size */ printf("Making the pipe\n"); - retcode = DOSMAKEPIPE((unsigned far *)&fp->read_handle, - (unsigned far *)&fp->write_handle, pipe_size); + retcode = DosMakePipe((PHFILE)&fp->read_handle, + (PHFILE)&fp->write_handle, pipe_size); if ( retcode ) { printf("DosMakePipe returned error %d, aborting\n", retcode); @@ -66,8 +75,8 @@ main() /* write string to pipe */ buflen = strlen(writeout) + 1; - if( retcode = DOSWRITE( fp->write_handle, (char far *)writeout, - buflen, (unsigned far *)&written)) { + if( retcode = DosWrite( fp->write_handle, (PCHAR)writeout, + buflen, &written)) { printf("Write to pipe failed, retcode %d\n", retcode); exit(2); } @@ -77,10 +86,9 @@ main() /* create the child */ printf("Creating child\n"); - retcode = DOSEXECPGM( (char far *)exec_buf, 100, 0, - (unsigned far *)0L, - (unsigned far *)0L, - (struct ResultCodes far *)&tcodes, pgmname ); + retcode = DosExecPgm( exec_buf, 100, EXEC_SYNC, + (PSZ)0L, (PSZ)0L, + &tcodes, pgmname ); if ( retcode ) printf("DosExecPgm of child error %d\n", retcode); @@ -88,9 +96,9 @@ main() printf("Back in parent\n"); /* close the pipe */ - DOSCLOSE( fp->read_handle ); - DOSCLOSE( fp->write_handle ); + DosClose( fp->read_handle ); + DosClose( fp->write_handle ); - DOSEXIT(1,0); /* Terminate, kill any dangling children */ + DosExit(EXIT_PROCESS,0); /* Terminate, kill any dangling children */ }