ReactOS  0.4.14-dev-77-gd9e7c48
npserver.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <windows.h>
5 #include <tchar.h>
6 
7 #define BUFSIZE 1024
8 #define PIPE_TIMEOUT 1000
9 
11 
12 VOID
14  LPTSTR lpReply,
15  LPDWORD lpcbReplyBytes)
16 {
17 }
18 
20 {
21 // MessageBox(NULL, Message, NULL, MB_OK);
22  puts(Message);
23  ExitProcess(0);
24 }
25 
26 
27 
28 
29 int xx = 0;
30 
31 int main(int argc, char *argv[])
32 {
33  BOOL fConnected;
35  HANDLE hPipe, hThread;
36  LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\mynamedpipe");
37 
38 // for (;;)
39 // {
40  hPipe = CreateNamedPipe(lpszPipename,
44  PIPE_WAIT,
46  BUFSIZE,
47  BUFSIZE,
49  NULL);
50  if (hPipe == INVALID_HANDLE_VALUE)
51  {
52  printf("CreateNamedPipe() failed\n");
53  return 0;
54  }
55 
56  fConnected = ConnectNamedPipe(hPipe,
57  NULL) ? TRUE : (GetLastError () ==
59  if (fConnected)
60  {
61  printf("Pipe connected!\n");
62 
63  DisconnectNamedPipe(hPipe);
64 
65 #if 0
67  0,
69  (LPVOID) hPipe,
70  0,
71  &dwThreadId);
72  if (hThread == NULL)
73  MyErrExit("CreateThread");
74 #endif
75  }
76  else
77  {
78 // CloseHandle(hPipe);
79  }
80 // }
81 
82  CloseHandle(hPipe);
83 
84  return 0;
85 }
86 
88 {
89  CHAR chRequest[BUFSIZE];
90  CHAR chReply[BUFSIZE];
91  DWORD cbBytesRead, cbReplyBytes, cbWritten;
92  BOOL fSuccess;
93  HANDLE hPipe;
94 
95  hPipe = (HANDLE)lpvParam;
96  while (1)
97  {
98  fSuccess = ReadFile(hPipe,
99  chRequest,
100  BUFSIZE,
101  &cbBytesRead,
102  NULL);
103  if (!fSuccess || cbBytesRead == 0)
104  break;
105 
106  GetAnswerToRequest(chRequest, chReply, &cbReplyBytes);
107 
108  fSuccess = WriteFile(hPipe,
109  chReply,
110  cbReplyBytes,
111  &cbWritten,
112  NULL);
113  if (!fSuccess || cbReplyBytes != cbWritten)
114  break;
115  }
116 
117  FlushFileBuffers(hPipe);
118  DisconnectNamedPipe(hPipe);
119  CloseHandle(hPipe);
120 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
static int argc
Definition: ServiceArgs.c:12
#define CreateNamedPipe
Definition: winbase.h:3574
#define PIPE_UNLIMITED_INSTANCES
Definition: winbase.h:175
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:707
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define PIPE_TYPE_MESSAGE
Definition: winbase.h:168
char CHAR
Definition: xmlstorage.h:175
#define PIPE_WAIT
Definition: winbase.h:171
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define PIPE_TIMEOUT
Definition: npserver.c:8
#define argv
Definition: mplay32.c:18
CHAR * LPTSTR
Definition: xmlstorage.h:192
VOID GetAnswerToRequest(LPTSTR lpRequest, LPTSTR lpReply, LPDWORD lpcbReplyBytes)
Definition: npserver.c:13
VOID InstanceThread(LPVOID)
Definition: npserver.c:87
unsigned int BOOL
Definition: ntddk_ex.h:94
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:136
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:175
#define PIPE_ACCESS_DUPLEX
Definition: winbase.h:164
int xx
Definition: npserver.c:29
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID MyErrExit(LPTSTR Message)
Definition: npserver.c:19
CHAR Message[80]
Definition: alive.c:5
int main(int argc, char *argv[])
Definition: npserver.c:31
DWORD dwThreadId
Definition: fdebug.c:31
#define ERROR_PIPE_CONNECTED
Definition: winerror.h:352
BOOL WINAPI DisconnectNamedPipe(HANDLE hNamedPipe)
Definition: npipe.c:961
int puts(const char *string)
Definition: crtsupp.c:23
#define BUFSIZE
Definition: npserver.c:7
#define PIPE_READMODE_MESSAGE
Definition: winbase.h:170
#define TEXT(s)
Definition: k32.h:26
HANDLE hThread
Definition: wizard.c:27
uint32_t * LPDWORD
Definition: typedefs.h:57
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
BOOL WINAPI ConnectNamedPipe(IN HANDLE hNamedPipe, IN LPOVERLAPPED lpOverlapped)
Definition: npipe.c:701
#define printf
Definition: config.h:203