Modified demo LPC server and client with verbose output.
[reactos.git] / reactos / apps / tests / lpc / lpcclt.c
1 /* $Id: lpcclt.c,v 1.8 2002/02/24 17:44:22 ea Exp $
2 *
3 * DESCRIPTION: Simple LPC Client
4 * PROGRAMMER: David Welch
5 */
6 #include <ddk/ntddk.h>
7 #include <windows.h>
8 #include <napi/lpc.h>
9 #include <stdarg.h>
10 #include <string.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 #include "lpctest.h"
15
16 const char * MyName = "LPC-CLI";
17 HANDLE OutputHandle;
18 HANDLE InputHandle;
19
20 void debug_printf(char* fmt, ...)
21 {
22 va_list args;
23 char buffer[255];
24
25 va_start(args,fmt);
26 vsprintf(buffer,fmt,args);
27 WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL);
28 va_end(args);
29 }
30
31
32 int main(int argc, char* argv[])
33 {
34 UNICODE_STRING PortName;
35 NTSTATUS Status;
36 HANDLE PortHandle;
37 LPC_MAX_MESSAGE Request;
38 ULONG ConnectInfo;
39 ULONG ConnectInfoLength = 0;
40 SECURITY_QUALITY_OF_SERVICE Sqos;
41
42 printf("%s: Lpc test client\n", MyName);
43
44 RtlInitUnicodeString(&PortName, TEST_PORT_NAME_U);
45
46 printf("%s: Connecting to port \"%s\"...\n", MyName, TEST_PORT_NAME);
47 ConnectInfoLength = 0;
48 ZeroMemory (& Sqos, sizeof Sqos);
49 Status = NtConnectPort(&PortHandle,
50 &PortName,
51 & Sqos,
52 0,
53 0,
54 0,
55 NULL,
56 &ConnectInfoLength);
57 if (!NT_SUCCESS(Status))
58 {
59 printf("%s: NtConnectPort() failed with status = 0x%08X.\n", MyName, Status);
60 return EXIT_FAILURE;
61 }
62
63 printf("%s: Connected to \"%s\" with anonymous port 0x%x.\n", MyName, TEST_PORT_NAME, PortHandle);
64
65 ZeroMemory(& Request, sizeof Request);
66 strcpy(Request.Data, GetCommandLineA());
67 Request.Header.DataSize = strlen(Request.Data);
68 Request.Header.MessageSize = sizeof(LPC_MESSAGE_HEADER) +
69 Request.Header.DataSize;
70
71 printf("%s: Sending to port 0x%x message \"%s\"...\n",
72 MyName,
73 PortHandle,
74 (char *) Request.Data);
75 Status = NtRequestPort(PortHandle,
76 &Request.Header);
77 if (!NT_SUCCESS(Status))
78 {
79 printf("%s: NtRequestPort(0x%x) failed with status = 0x%8X.\n",
80 MyName,
81 PortHandle,
82 Status);
83 return EXIT_FAILURE;
84 }
85
86 printf("%s: Sending datagram to port 0x%x succeeded.\n", MyName, PortHandle);
87
88 Sleep(2000);
89
90 printf("%s: Disconnecting...", MyName);
91 NtClose (PortHandle);
92
93 return EXIT_SUCCESS;
94 }