CreateFile

Here is the Reference from MSDN site ==>

Function Declaration

HANDLE WINAPI CreateFile(

  LPCTSTR lpFileName,

  DWORD dwDesiredAccess,

  DWORD dwShareMode,

  LPSECURITY_ATTRIBUTES lpSecurityAttributes,

  DWORD dwCreationDisposition,

 DWORD dwFlagsAndAttributes,
 HANDLE hTemplateFile

)

Usage if we to Open an Existing File

hfile = CreateFile(readFileName,FILE_READ_DATA,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
if ( hfile == INVALID_HANDLE_VALUE)
{
printf(“Open Failed \n”);
return;
}

=========================================

CreateFileMapping

Reference is here ==>

API Declaration

HANDLE WINAPI CreateFileMapping(

  HANDLE hFile,

  LPSECURITY_ATTRIBUTES lpAttributes,

  DWORD flProtect,

  DWORD dwMaximumSizeHigh,

  DWORD dwMaximumSizeLow,

  LPCTSTR lpName

);


USAGE

 If you want to map a Read only file, with 100 MB as the Max file Object size
fileMap = CreateFileMapping(hfile, 0,PAGE_READONLY,0, 0,"NoisyFile");
Since we are trying to map a file into processes memory, the  dwMaximumSizeHigh,

and dwMaximumSizeLow should be 0. These values need to be of the required size only when
"hFile" takes in  INVALID_HANDLE_VALUE as the argument

============================================================================
MapViewOfFile
 Once a FileMapping object is created, it need to be mapped to the process address space.
The following funtion does the mapping.


The reference for the function is here ==>

Function Declaration
LPVOID WINAPI MapViewOfFile(

  HANDLE hFileMappingObject,

  DWORD dwDesiredAccess,

  DWORD dwFileOffsetHigh,

  DWORD dwFileOffsetLow,

  SIZE_T dwNumberOfBytesToMap

);
 Function Usage
ptr = (unsigned char*)  MapViewOfFile(fileMap, FILE_MAP_READ, 0, 0,0);