This function provides access to an area of shared memory. It improves on SHLockShared by offering a choice between read-only and read-write access.


SHLockSharedEx (
    HANDLE hData,
    DWORD dwProcessId,
    BOOL bWriteAccess);


The hData argument is a handle to the shared memory.

The dwProcessId argument is the process identifier (PID) of the process that provides the context for interpreting the given handle.

The bWriteAccess argument should be FALSE if read-only access suffices.

Return Value

If successful, the function returns a pointer to the shared memory. Otherwise, the function returns NULL.


The function treats the hData and dwProcessId arguments as a pair that together identify the shared memory. In general, hData will have been the result of some earlier call to SHAllocShared (possibly in some other process) and dwProcessId will have been the last of the arguments given in that same call to SHAllocShared.

The handle refers to a file-mapping object that contains the shared memory. The function duplicates the given handle into the context of the current process and uses the duplicate to map a view of the file-mapping object into the address space of the current process.


The SHLockSharedEx function is exported from SHLWAPI.DLL as ordinal 510 in version 6.00 and higher.

Though this function dates from 2001, it was still not documented by Microsoft in the MSDN Library at least as late as the CD edition dated January 2004.