disable defining ntstatus codes in windows.h/winnt.h when using ndk
[reactos.git] / rosapps / tests / apc / apc.c
1 #include <stdio.h>
2 #include <string.h>
3 #define WIN32_NO_STATUS
4 #include <windows.h>
5 #define NTOS_MODE_USER
6 #include <ndk/ntndk.h>
7
8 HANDLE OutputHandle;
9 HANDLE InputHandle;
10
11 VOID STDCALL
12 ApcRoutine(PVOID Context,
13 PIO_STATUS_BLOCK IoStatus,
14 ULONG Reserved)
15 {
16 printf("(apc.exe) ApcRoutine(Context %p)\n", Context);
17 }
18
19
20 int main(int argc, char* argv[])
21 {
22 NTSTATUS Status;
23 HANDLE FileHandle;
24 OBJECT_ATTRIBUTES ObjectAttributes;
25 UNICODE_STRING FileName = RTL_CONSTANT_STRING(L"\\C:\\a.txt");
26 IO_STATUS_BLOCK IoStatus;
27 CHAR Buffer[256];
28 HANDLE EventHandle;
29 LARGE_INTEGER off;
30
31 AllocConsole();
32 InputHandle = GetStdHandle(STD_INPUT_HANDLE);
33 OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
34
35 printf("APC test program\n");
36
37 EventHandle = CreateEventW(NULL,
38 FALSE,
39 FALSE,
40 NULL);
41 if (EventHandle == INVALID_HANDLE_VALUE)
42 {
43 printf("Failed to create event\n");
44 return 0;
45 }
46
47 printf("Opening file\n");
48 InitializeObjectAttributes(&ObjectAttributes,
49 &FileName,
50 0,
51 NULL,
52 NULL);
53
54 printf("Creating file\n");
55 FileHandle = CreateFileW(L"C:\\a.txt",
56 FILE_GENERIC_READ | FILE_GENERIC_WRITE,
57 0,
58 NULL,
59 OPEN_EXISTING,
60 FILE_FLAG_OVERLAPPED,
61 NULL);
62
63 if (FileHandle == INVALID_HANDLE_VALUE)
64 {
65
66 printf("Open failed last err 0x%lu\n",GetLastError());
67 return 0;
68 }
69
70 off.QuadPart = 0;
71
72 printf("Reading file\n");
73 Status = ZwReadFile(FileHandle,
74 NULL,
75 (PIO_APC_ROUTINE)ApcRoutine,
76 (PVOID) 0xdeadbeef,
77 &IoStatus,
78 Buffer,
79 256,//len
80 &off ,//offset must exist if file was opened for asynch. i/o aka. OVERLAPPED
81 NULL);
82
83 if (!NT_SUCCESS(Status))
84 {
85 printf("Read failed status 0x%lu\n",Status);
86 }
87 printf("Waiting\n");
88 WaitForSingleObjectEx(EventHandle, INFINITE, TRUE);
89 printf("Returned from wait\n");
90 ZwClose(FileHandle);
91 printf("Program finished\n");
92 return 0;
93 }
94