ReactOS 0.4.15-dev-7942-gd23573b
sectest.c
Go to the documentation of this file.
1#define UNICODE
2#define _UNICODE
3#include <windows.h>
4#include <stdio.h>
5#include <string.h>
6
7#include <tchar.h>
8
9int main(int argc, char* argv[])
10{
12 HANDLE Section;
14
15 printf("Section Test\n");
16
17 hFile = CreateFile(_T("sectest.txt"),
19 0,
20 NULL,
22 0,
23 0);
25 {
26 printf("Failed to create file (err=%ld)", GetLastError());
27 return 1;
28 }
29
30 Section = CreateFileMapping(hFile,
31 NULL,
33 0,
34 4096,
35 NULL);
36 if (Section == NULL)
37 {
38 printf("Failed to create section (err=%ld)", GetLastError());
39 return 1;
40 }
41
42 printf("Mapping view of section\n");
43 BaseAddress = MapViewOfFile(Section,
45 0,
46 0,
47 4096);
48 printf("BaseAddress %x\n", (UINT) BaseAddress);
49 if (BaseAddress == NULL)
50 {
51 printf("Failed to map section (%ld)\n", GetLastError());
52 return 1;
53 }
54
55 printf("Clearing section\n");
56 FillMemory(BaseAddress, 4096, ' ');
57 printf("Copying test data to section\n");
58 strcpy(BaseAddress, "test data");
59
61 {
62 printf("Failed to unmap view of file (%ld)\n", GetLastError());
63 return 1;
64 }
65
66 if (!CloseHandle(hFile))
67 {
68 printf("Failed to close file (%ld)\n", GetLastError());
69 return 1;
70 }
71
72 return 0;
73}
74
static int argc
Definition: ServiceArgs.c:12
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define UnmapViewOfFile
Definition: compat.h:746
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define MapViewOfFile
Definition: compat.h:745
int main()
Definition: test.c:6
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
#define printf
Definition: freeldr.h:97
#define CREATE_ALWAYS
Definition: disk.h:72
#define argv
Definition: mplay32.c:18
_In_ HANDLE hFile
Definition: mswsock.h:90
unsigned int UINT
Definition: ndis.h:50
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define GENERIC_WRITE
Definition: nt_native.h:90
#define _T(x)
Definition: vfdio.h:22
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateFileMapping
Definition: winbase.h:3750
#define FILE_MAP_ALL_ACCESS
Definition: winbase.h:156
#define CreateFile
Definition: winbase.h:3749