ReactOS  0.4.15-dev-4920-g5fa8403
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 
9 int main(int argc, char* argv[])
10 {
11  HANDLE hFile;
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
#define CloseHandle
Definition: compat.h:598
#define MapViewOfFile
Definition: compat.h:604
#define CreateFileMapping
Definition: winbase.h:3611
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define argv
Definition: mplay32.c:18
#define GENERIC_WRITE
Definition: nt_native.h:90
#define FILE_MAP_ALL_ACCESS
Definition: winbase.h:156
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define _T(x)
Definition: vfdio.h:22
#define printf
Definition: freeldr.h:94
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
#define GENERIC_READ
Definition: compat.h:135
_In_ HANDLE hFile
Definition: mswsock.h:90
#define CREATE_ALWAYS
Definition: disk.h:72
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:913
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
int main(int argc, char *argv[])
Definition: sectest.c:9
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define UnmapViewOfFile
Definition: compat.h:605
#define PAGE_READWRITE
Definition: nt_native.h:1304