2005-05-07 21:24:31 +00:00
|
|
|
/* $Id$ */
|
2004-10-21 04:53:21 +00:00
|
|
|
#define UNICODE
|
|
|
|
#define _UNICODE
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
HANDLE Section;
|
|
|
|
PVOID BaseAddress;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:53:21 +00:00
|
|
|
printf("Section Test\n");
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:53:21 +00:00
|
|
|
hFile = CreateFile(_T("sectest.txt"),
|
2005-05-07 21:24:31 +00:00
|
|
|
GENERIC_READ | GENERIC_WRITE,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
CREATE_ALWAYS,
|
|
|
|
0,
|
2004-10-21 04:53:21 +00:00
|
|
|
0);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
printf("Failed to create file (err=%ld)", GetLastError());
|
|
|
|
return 1;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:53:21 +00:00
|
|
|
Section = CreateFileMapping(hFile,
|
|
|
|
NULL,
|
2005-05-07 21:24:31 +00:00
|
|
|
PAGE_READWRITE,
|
2004-10-21 04:53:21 +00:00
|
|
|
0,
|
|
|
|
4096,
|
|
|
|
NULL);
|
|
|
|
if (Section == NULL)
|
|
|
|
{
|
|
|
|
printf("Failed to create section (err=%ld)", GetLastError());
|
|
|
|
return 1;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:53:21 +00:00
|
|
|
printf("Mapping view of section\n");
|
|
|
|
BaseAddress = MapViewOfFile(Section,
|
|
|
|
FILE_MAP_ALL_ACCESS,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
4096);
|
|
|
|
printf("BaseAddress %x\n", (UINT) BaseAddress);
|
|
|
|
if (BaseAddress == NULL)
|
|
|
|
{
|
|
|
|
printf("Failed to map section (%ld)\n", GetLastError());
|
|
|
|
return 1;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:53:21 +00:00
|
|
|
printf("Clearing section\n");
|
|
|
|
FillMemory(BaseAddress, 4096, ' ');
|
|
|
|
printf("Copying test data to section\n");
|
|
|
|
strcpy(BaseAddress, "test data");
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:53:21 +00:00
|
|
|
if (!UnmapViewOfFile(BaseAddress))
|
2005-05-07 21:24:31 +00:00
|
|
|
{
|
2004-10-21 04:53:21 +00:00
|
|
|
printf("Failed to unmap view of file (%ld)\n", GetLastError());
|
|
|
|
return 1;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:53:21 +00:00
|
|
|
if (!CloseHandle(hFile))
|
2005-05-07 21:24:31 +00:00
|
|
|
{
|
2004-10-21 04:53:21 +00:00
|
|
|
printf("Failed to close file (%ld)\n", GetLastError());
|
|
|
|
return 1;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:53:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|