b7e01f666df7def1abc1294b8dd6992c8a35e386
[reactos.git] / apps / tests / lpc / lpcclt.c
1 /* $Id$
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 = UNICODE_STRING_INITIALIZER(TEST_PORT_NAME_U);
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    printf("%s: Connecting to port \"%s\"...\n", MyName, TEST_PORT_NAME);
45    ConnectInfoLength = 0;
46    ZeroMemory (& Sqos, sizeof Sqos);
47    Status = NtConnectPort(&PortHandle,
48                           &PortName,
49                           & Sqos,
50                           0,
51                           0,
52                           0,
53                           NULL,
54                           &ConnectInfoLength);
55    if (!NT_SUCCESS(Status))
56      {
57         printf("%s: NtConnectPort() failed with status = 0x%08X.\n", MyName, Status);
58         return EXIT_FAILURE;
59      }
60
61    printf("%s: Connected to \"%s\" with anonymous port 0x%x.\n", MyName, TEST_PORT_NAME, PortHandle);
62
63    ZeroMemory(& Request, sizeof Request);
64    strcpy(Request.Data, GetCommandLineA());
65    Request.Header.DataSize = strlen(Request.Data);
66    Request.Header.MessageSize = sizeof(LPC_MESSAGE_HEADER) + 
67      Request.Header.DataSize;
68    
69    printf("%s: Sending to port 0x%x message \"%s\"...\n", 
70           MyName,
71           PortHandle,
72           (char *) Request.Data);
73    Status = NtRequestPort(PortHandle, 
74                           &Request.Header);
75    if (!NT_SUCCESS(Status))
76      {
77         printf("%s: NtRequestPort(0x%x) failed with status = 0x%8X.\n", 
78                MyName,
79                PortHandle,
80                Status);
81         return EXIT_FAILURE;
82      }
83    
84    printf("%s: Sending datagram to port 0x%x succeeded.\n", MyName, PortHandle);
85
86    Sleep(2000);
87
88    printf("%s: Disconnecting...", MyName);
89    NtClose (PortHandle);
90
91    return EXIT_SUCCESS;
92 }