Progress
External Program
Interfaces
Coding the C Program
The non-Progress program creates, connects, reads, writes, and closes the Windows NT named pipe or pipes.
The following C program demonstrates creating, connecting, reading, writing, and closing Windows NT named pipe “custpipe:”
- The program declares include files.
- The program defines data items.
- The program calls an NT Console API function to give the window a more descriptive title.
- The program creates named pipe custpipe. The PIPE_ACCESS_DUPLEX flag makes the pipe read/write. The PIPE_WAIT flag makes the pipe synchronous. The program checks for errors and prints debugging messages here and throughout.
- The program solicits and accepts a value (“1" to read the pipe, “2" to write the pipe) from the user.
- The program connects the named pipe. This makes the pipe available to other applications, processes and threads.
- The program 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 NT 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 4GL program’s SET input 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 4GL program closes the named pipe with the OUTPUT CLOSE statement, which causes the C program’s ReadFile() call to raise a BROKEN_PIPE error, which the C program interprets as “named pipe EOF.”
- The program closes the named pipe and exits.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |