[ Home | Alpha index | Topic index | Tutorials | Download | Feedback ]

The OS/2 API Project


[ Syntax | Params | Returns | Include | Usage | Structs | Gotchas | Code | Also ]


rc = DosGetNamedSharedMem( pBaseAddress, pszSharedMemName, ulAttributeFlags );


PPVOID pBaseAddress (output)
This is a pointer to the variable that should recieve the base address of the allocated memory space.

PSZ pszSharedMemName (input)
This an optional address of a name string that is to be associated with the shared memory block which we are about to allocate. The name should be in the format of an OS/2 filename, and is an ordinary ASCIIZ string. Will be stored in the \SHAREMEM\ subdirectory.

ULONG ulAttributeFlags (input)
Flags that describe the desired access protection and allocation attributes.

Access protection

Setting PAG_READ (0x00000001) tells the system that read access is desired.

Setting PAG_WRITE (0x00000002) tells the system that write access is desired.

Setting PAG_EXECUTE (0x00000004) tells the system that execute access is desired.

Setting PAG_GUARD (0x00000008) tells the system that access to the memory object should cause a guard page exception to be raised, in the subject process.

At least one of PAG_READ,PAG_WRITE or PAG_EXECUTE must be set.


The following values can be returned

Include Info

#include <bsememf.h>
#include <os2.h>

Usage Explanation

DosGetNamedSharedMem is used to get access to a named shared memory block. This will allocate the virtual address of the memory object into the process's virtual-address space. If you specify the name of the block, the name string must include the prefix "\SHAREMEM\". The returned address will be the same as the one returned to the process that created the memory block.

Relevant Structures


Sample Code

#define INCL_DOSMEMMGR #include <os2.h> #include <bsememf.h> PVOID BaseAddress; /* Pointer to the base address of the allocated memory. */ UCHAR Name[40]; /* Pointer to the requested name of the memory block */ /* which we are about to allocate. */ ULONG AttributeFlags; /* Flags describing the memory block's characteristics. */ APIRET rc; /* Receiving the return code */ strcpy(Name,"\\SHAREMEM\\BLOCK.DAT"); /* Name of the shared memory block. */ /* Note the \\SHAREMEM\\ prefix. */ AttributeFlags = PAG_WRITE | PAG_READ | PAG_COMMIT; /* We request read and write access to the shared memory */ /* block, and also have the pages of the memory block */ /* committed at once within the virtual memory. */ rc = DosGetNamedSharedMem( &BaseAddress, Name, AttributeFlags); if (rc != 0) { /* We have an error we must take care of. */ }

See Also

DosAllocSharedMem, DosGetSharedMem, DosGiveSharedMem


Stefan Mars - mars@lysator.liu.se


Last modified March 16/1996
Please send all errors, comments, and suggestions to: timur@vnet.ibm.com

The OS/2 API Project