Reverted latest changes.
[reactos.git] / reactos / apps / tests / apc / apc.c
1 #include <stdarg.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <windows.h>
5 #include <ddk/ntddk.h>
6
7 HANDLE OutputHandle;
8 HANDLE InputHandle;
9
10 VOID STDCALL
11 ApcRoutine(PVOID Context,
12 PIO_STATUS_BLOCK IoStatus,
13 ULONG Reserved)
14 {
15 printf("(apc.exe) ApcRoutine(Context %p)\n", Context);
16 }
17
18 int main(int argc, char* argv[])
19 {
20 NTSTATUS Status;
21 HANDLE FileHandle;
22 OBJECT_ATTRIBUTES ObjectAttributes;
23 UNICODE_STRING FileName = UNICODE_STRING_INITIALIZER(L"\\C:\\a.txt");
24 IO_STATUS_BLOCK IoStatus;
25 CHAR Buffer[256];
26 HANDLE EventHandle;
27
28 AllocConsole();
29 InputHandle = GetStdHandle(STD_INPUT_HANDLE);
30 OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
31
32 printf("APC test program\n");
33
34 EventHandle = CreateEventW(NULL,
35 FALSE,
36 FALSE,
37 NULL);
38 if (EventHandle == INVALID_HANDLE_VALUE)
39 {
40 printf("Failed to create event\n");
41 return 0;
42 }
43
44 printf("Opening file\n");
45 InitializeObjectAttributes(&ObjectAttributes,
46 &FileName,
47 0,
48 NULL,
49 NULL);
50
51 printf("Creating file\n");
52 FileHandle = CreateFileW(L"C:\\a.txt",
53 FILE_GENERIC_READ | FILE_GENERIC_WRITE,
54 0,
55 NULL,
56 OPEN_EXISTING,
57 FILE_FLAG_OVERLAPPED,
58 NULL);
59 if (FileHandle == INVALID_HANDLE_VALUE)
60 {
61 printf("Open failed\n");
62 return 0;
63 }
64 printf("Reading file\n");
65 Status = ZwReadFile(FileHandle,
66 NULL,
67 (PIO_APC_ROUTINE)ApcRoutine,
68 (PVOID)0xdeadbeef,
69 &IoStatus,
70 Buffer,
71 256,
72 NULL,
73 NULL);
74 if (!NT_SUCCESS(Status))
75 {
76 printf("Read failed\n");
77 }
78 printf("Waiting\n");
79 WaitForSingleObjectEx(EventHandle, INFINITE, TRUE);
80 printf("Returned from wait\n");
81 ZwClose(FileHandle);
82 printf("Program finished\n");
83 return 0;
84 }
85