ReactOS 0.4.15-dev-7659-ga55345b
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
12VOID
14 LPTSTR lpReply,
15 LPDWORD lpcbReplyBytes)
16{
17}
18
20{
21// MessageBox(NULL, Message, NULL, MB_OK);
23 ExitProcess(0);
24}
25
26
27
28
29int xx = 0;
30
31int 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,
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
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}
static int argc
Definition: ServiceArgs.c:12
int puts(const char *string)
Definition: crtsupp.c:23
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:739
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
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:137
static const WCHAR Message[]
Definition: register.c:74
int main()
Definition: test.c:6
DWORD dwThreadId
Definition: fdebug.c:31
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define printf
Definition: freeldr.h:94
#define TEXT(s)
Definition: k32.h:26
#define argv
Definition: mplay32.c:18
HANDLE hThread
Definition: wizard.c:28
BOOL WINAPI ConnectNamedPipe(IN HANDLE hNamedPipe, IN LPOVERLAPPED lpOverlapped)
Definition: npipe.c:701
BOOL WINAPI DisconnectNamedPipe(HANDLE hNamedPipe)
Definition: npipe.c:961
#define PIPE_TIMEOUT
Definition: npserver.c:8
VOID MyErrExit(LPTSTR Message)
Definition: npserver.c:19
VOID InstanceThread(LPVOID)
Definition: npserver.c:87
VOID GetAnswerToRequest(LPTSTR lpRequest, LPTSTR lpReply, LPDWORD lpcbReplyBytes)
Definition: npserver.c:13
#define BUFSIZE
Definition: npserver.c:7
int xx
Definition: npserver.c:29
PVOID HANDLE
Definition: typedefs.h:73
uint32_t * LPDWORD
Definition: typedefs.h:59
#define CreateNamedPipe
Definition: winbase.h:3692
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define PIPE_ACCESS_DUPLEX
Definition: winbase.h:164
#define PIPE_WAIT
Definition: winbase.h:171
#define PIPE_READMODE_MESSAGE
Definition: winbase.h:170
#define PIPE_TYPE_MESSAGE
Definition: winbase.h:168
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:729
#define PIPE_UNLIMITED_INSTANCES
Definition: winbase.h:175
#define ERROR_PIPE_CONNECTED
Definition: winerror.h:352
CHAR * LPTSTR
Definition: xmlstorage.h:192
char CHAR
Definition: xmlstorage.h:175