Platform SDK: Memory

OpenFileMapping

The OpenFileMapping function opens a named file-mapping object.

HANDLE OpenFileMapping(
  DWORD dwDesiredAccess,  // access mode
  BOOL bInheritHandle,    // inherit flag
  LPCTSTR lpName          // object name
);

Parameters

dwDesiredAccess
[in] Specifies the access to the file-mapping object.

Windows NT/2000: This access is checked against any security descriptor on the target file-mapping object.

Windows 95/98: Security descriptors on file-mapping objects are not supported.

This parameter can be one of the following values.
Value Meaning
FILE_MAP_WRITE Read-write access. The target file-mapping object must have been created with PAGE_READWRITE or PAGE_WRITE protection. Allows a read-write view of the file to be mapped.
FILE_MAP_READ Read-only access. The target file-mapping object must have been created with PAGE_READWRITE or PAGE_READ protection. Allows a read-only view of the file to be mapped.
FILE_MAP_ALL_ACCESS All access. The target file-mapping object must have been created with PAGE_READWRITE protection. Allows a read-write view of the file to be mapped.
FILE_MAP_COPY Copy-on-write access. The target file-mapping object must have been created with PAGE_WRITECOPY protection. Allows a copy-on-write view of the file to be mapped.

bInheritHandle
[in] Specifies whether the returned handle is to be inherited by a new process during process creation. A value of TRUE indicates that the new process inherits the handle.
lpName
[in] Pointer to a string that names the file-mapping object to be opened. If there is an open handle to a file-mapping object by this name and the security descriptor on the mapping object does not conflict with the dwDesiredAccess parameter, the open operation succeeds.

Terminal Services: The name can have a "Global\" or "Local\" prefix to explicitly open an object in the global or session name space. The remainder of the name can contain any character except the backslash character (\). For more information, see Kernel Object Name Spaces.

Windows 2000: On Windows 2000 systems without Terminal Services running, the "Global\" and "Local\" prefixes are ignored. The remainder of the name can contain any character except the backslash character.

Windows NT 4.0 and earlier, Windows 95/98: The name can contain any character except the backslash character.

Return Values

If the function succeeds, the return value is an open handle to the specified file-mapping object.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The handle that OpenFileMapping returns can be used with any function that requires a handle to a file-mapping object.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

File Mapping Overview, File Mapping Functions, CreateFileMapping