2 * Simple Named Pipe Client
3 * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
4 * Published to the public domain
10 #define ECHODATA "Black Dog"
12 int main(int argc
, char *argv
[])
16 char *outbuffer
= malloc(strlen(ECHODATA
));
19 printf("Usage: %s pipename\n", argv
[0]);
20 printf(" Where pipename is something like \\\\servername\\NPECHO\n");
24 h
= CreateFile(argv
[1], GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
25 if (h
== INVALID_HANDLE_VALUE
) {
26 printf("Error opening: %d\n", GetLastError());
30 if (!WriteFile(h
, ECHODATA
, strlen(ECHODATA
), &numread
, NULL
)) {
31 printf("Error writing: %d\n", GetLastError());
35 if (!ReadFile(h
, outbuffer
, strlen(ECHODATA
), &numread
, NULL
)) {
36 printf("Error reading: %d\n", GetLastError());
40 printf("Read: %s\n", outbuffer
);
42 if (!TransactNamedPipe(h
, ECHODATA
, strlen(ECHODATA
), outbuffer
, strlen(ECHODATA
), &numread
, NULL
)) {
43 printf("TransactNamedPipe failed: %d!\n", GetLastError());
47 printf("Result: %s\n", outbuffer
);