Kbase P70567: How to create a Windows Named Pipe server using 4GL ?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  3/5/2004 |
|
Status: Unverified
GOAL:
How to create a Windows Named Pipe server using 4GL ?
GOAL:
How to manage Windows Named Pipes from a 4GL session ?
FACT(s) (Environment):
Windows NT 32 Intel/Windows 2000
FIX:
Windows Named Pipes work on a client/server principle. The named pipes are created in a server process, and each instance of a pipe can have a single client connected at any one time.
A client is any process that writes to or reads from the pipe using basic file I/O (The 4GL INPUT FROM / OUTPUT TO mechanism, OS level Echo or Type commands).
The Progress 4GL does not have specific statements to handle the server aspects of the Windows named pipe implementation. However, the Windows kernel offers the APIs required, and these can be used from within the Progress 4GL using the DLL interface. Following are the Progress 4GL declarations for the DLL functions.
/* creates named pipe */
PROCEDURE CreateNamedPipeA EXTERNAL "kernel32.dll":
DEFINE INPUT PARAMETER lpName AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER dwOpenMode AS LONG NO-UNDO.
DEFINE INPUT PARAMETER dwPipeMode AS LONG NO-UNDO.
DEFINE INPUT PARAMETER nMaxInstances AS LONG NO-UNDO.
DEFINE INPUT PARAMETER nOutBufferSize AS LONG NO-UNDO.
DEFINE INPUT PARAMETER nInBufferSize AS LONG NO-UNDO.
DEFINE INPUT PARAMETER nDefaultTimeOut AS LONG NO-UNDO.
DEFINE INPUT PARAMETER lpSecurityAttributes AS LONG NO-UNDO.
DEFINE RETURN PARAMETER hReturnValue AS LONG NO-UNDO.
END PROCEDURE.
/* used to destroy named pipe */
PROCEDURE CloseHandle EXTERNAL "kernel32.dll":
DEFINE INPUT PARAMETER hObject AS LONG NO-UNDO.
DEFINE RETURN PARAMETER nReturnValue AS LONG NO-UNDO.
END PROCEDURE.
/* used to connect as server */
PROCEDURE ConnectNamedPipe EXTERNAL "kernel32.dll":
DEFINE INPUT PARAMETER hNamedPipe AS LONG NO-UNDO.
DEFINE INPUT PARAMETER lpOverlapped AS LONG NO-UNDO.
DEFINE RETURN PARAMETER nReturnValue AS LONG NO-UNDO.
END PROCEDURE.
/* used to disconnect as server */
PROCEDURE DisconnectNamedPipe EXTERNAL "kernel32.dll":
DEFINE INPUT PARAMETER hNamedPipe AS LONG NO-UNDO.
DEFINE RETURN PARAMETER nReturnValue AS LONG NO-UNDO.
END PROCEDURE.
/* used to read from named pipe as server */
PROCEDURE ReadFile EXTERNAL "kernel32.dll":
DEFINE INPUT PARAMETER hFile AS LONG NO-UNDO.
DEFINE INPUT PARAMETER lpBuffer AS MEMPTR NO-UNDO.
DEFINE INPUT PARAMETER nSizetoRead AS LONG NO-UNDO.
DEFINE OUTPUT PARAMETER nSizeActRead AS LONG NO-UNDO.
DEFINE INPUT PARAMETER lpOverlapped AS LONG NO-UNDO.
DEFINE RETURN PARAMETER nReturnValue AS LONG NO-UNDO.
END PROCEDURE.
/* used to write to named pipe as server */
PROCEDURE WriteFile EXTERNAL "kernel32.dll":
DEFINE INPUT PARAMETER hFile AS LONG NO-UNDO.
DEFINE INPUT PARAMETER lpBuffer AS MEMPTR NO-UNDO.
DEFINE INPUT PARAMETER nNumberOfBytesToWrite AS LONG NO-UNDO.
DEFINE OUTPUT PARAMETER lpNumberOfBytesWritten AS LONG NO-UNDO.
DEFINE INPUT PARAMETER lpOverlapped AS LONG NO-UNDO.
DEFINE RETURN PARAMETER nReturnValue AS LONG NO-UNDO.
END PROCEDURE.