Coding the C program
- Last Updated: January 17, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
Coding the C program
The non-OpenEdge program creates, connects, reads, writes, and closes the Windows named pipe or pipes.
The i-cpipe.c C
program demonstrates creating, connecting, reading, writing, and
closing Windows named pipe custpipe.
i-cpipe.c
|
|
The i-cpipe.c program:
- Declares include files.
- Defines data items.
- Calls an NT Console API function to give the window a more descriptive title.
- Creates named pipe
custpipe. ThePIPE_ACCESS_DUPLEXflag makes the pipe read/write. ThePIPE_WAITflag makes the pipe synchronous. The program checks for errors and prints debugging messages here and throughout. - Solicits and accepts a value ("1" to read the pipe, "2" to write the pipe) from the user.
- Connects the named pipe. This makes the pipe available to other applications, processes and threads.
- Either reads the pipe and displays the number of bytes read
along with the actual data, or else solicits a customer number,
appends a carriage return and a line feed (CR/LF), writes the result
to the named pipe, and flushes the buffers.
The program uses the same API calls for named pipes as for files. Named pipes are an integral part of the Windows file system, just as they are an integral part of UNIX file systems.
If the program did not append a CR/LF to the data it writes to the named pipe, the ABL program's
SETinput statement would wait for a line terminator or EOF marker, which does not ordinarily appear until the pipe is closed.The two programs use a quick and dirty hack to signal "named pipe EOF." The ABL program closes the named pipe with the
OUTPUT CLOSEstatement, which causes the C program's ReadFile() call to raise aBROKEN_PIPEerror, which the C program interprets as "named pipe EOF." - Closes the named pipe and exits.