Added error reporting to lpcsrv and lpcclt.

svn path=/trunk/; revision=955
This commit is contained in:
Emanuele Aliberti 2000-01-22 22:22:48 +00:00
parent 5415f6f333
commit 74131ebded
2 changed files with 35 additions and 18 deletions

View file

@ -1,7 +1,13 @@
/* $Id: lpcclt.c,v 1.5 2000/01/22 22:22:48 ea Exp $
*
* DESCRIPTION: Simple LPC Client
* PROGRAMMER: David Welch
*/
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
HANDLE OutputHandle; HANDLE OutputHandle;
HANDLE InputHandle; HANDLE InputHandle;
@ -18,7 +24,7 @@ void debug_printf(char* fmt, ...)
} }
void main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
UNICODE_STRING PortName; UNICODE_STRING PortName;
NTSTATUS Status; NTSTATUS Status;
@ -30,7 +36,7 @@ void main(int argc, char* argv[])
RtlInitUnicodeString(&PortName, L"\\TestPort"); RtlInitUnicodeString(&PortName, L"\\TestPort");
printf("(lpcclt.exe) Connecting to port\n"); printf("(lpcclt.exe) Connecting to port \"\\TestPort\"\n");
ConnectInfoLength = 0; ConnectInfoLength = 0;
Status = NtConnectPort(&PortHandle, Status = NtConnectPort(&PortHandle,
&PortName, &PortName,
@ -42,21 +48,22 @@ void main(int argc, char* argv[])
&ConnectInfoLength); &ConnectInfoLength);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
printf("(lpcclt.exe) Failed to connect\n"); printf("(lpcclt.exe) Failed to connect (Status = 0x%08X)\n", Status);
return; return EXIT_FAILURE;
} }
strcpy(Request.MessageData, GetCommandLineA()); strcpy(Request.MessageData, GetCommandLineA());
Request.ActualMessageLength = strlen(Request.MessageData); Request.ActualMessageLength = strlen(Request.MessageData);
Request.TotalMessageLength = sizeof(LPCMESSAGE); Request.TotalMessageLength = sizeof(LPCMESSAGE);
printf("(lpcclt.exe) Sending message\n"); printf("(lpcclt.exe) Sending message \"%s\"\n", (char *) Request.MessageData);
Status = NtRequestPort(PortHandle, &Request); Status = NtRequestPort(PortHandle, &Request);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
printf("(lpcclt.exe) Failed to send request\n"); printf("(lpcclt.exe) Failed to send request (Status = 0x%=8X)\n", Status);
return; return EXIT_FAILURE;
} }
printf("(lpcclt.exe) Succeeded\n"); printf("(lpcclt.exe) Succeeded\n");
return EXIT_SUCCESS;
} }

View file

@ -1,7 +1,13 @@
/* $Id: lpcsrv.c,v 1.4 2000/01/22 22:22:48 ea Exp $
*
* DESCRIPTION: Simple LPC Server
* PROGRAMMER: David Welch
*/
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
HANDLE OutputHandle; HANDLE OutputHandle;
HANDLE InputHandle; HANDLE InputHandle;
@ -18,7 +24,7 @@ void debug_printf(char* fmt, ...)
} }
void main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
UNICODE_STRING PortName; UNICODE_STRING PortName;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
@ -44,8 +50,8 @@ void main(int argc, char* argv[])
0); 0);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
printf("(lpcsrv.exe) Failed to create port\n"); printf("(lpcsrv.exe) Failed to create port (Status = 0x%08X)\n", Status);
return; return EXIT_FAILURE;
} }
@ -54,8 +60,8 @@ void main(int argc, char* argv[])
&ConnectMsg); &ConnectMsg);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
printf("(lpcsrv.exe) Failed to listen for connections\n"); printf("(lpcsrv.exe) Failed to listen for connections (Status = 0x%08X)\n", Status);
return; return EXIT_FAILURE;
} }
printf("(lpcsrv.exe) Accepting connections\n"); printf("(lpcsrv.exe) Accepting connections\n");
@ -67,16 +73,16 @@ void main(int argc, char* argv[])
NULL); NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
printf("(lpcsrv.exe) Failed to accept connection\n"); printf("(lpcsrv.exe) Failed to accept connection (Status = 0x%08X)\n", Status);
return; return EXIT_FAILURE;
} }
printf("(lpcsrv.exe) Completing connection\n"); printf("(lpcsrv.exe) Completing connection\n");
Status = NtCompleteConnectPort(PortHandle); Status = NtCompleteConnectPort(PortHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
printf("(lpcsrv.exe) Failed to complete connection\n"); printf("(lpcsrv.exe) Failed to complete connection (Status = 0x%08X)\n", Status);
return; return EXIT_FAILURE;
} }
for(;;) for(;;)
@ -89,10 +95,14 @@ void main(int argc, char* argv[])
&Request); &Request);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
printf("(lpcsrv.exe) Failed to receive request\n"); printf("(lpcsrv.exe) Failed to receive request (Status = 0x%08X)\n", Status);
return; return EXIT_FAILURE;
} }
printf("(lpcsrv.exe) Message contents are <%s>\n", Request.MessageData); printf("(lpcsrv.exe) Message contents are <%s>\n", Request.MessageData);
} }
return EXIT_SUCCESS;
} }
/* EOF */