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

The OS/2 API Project


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


rc = DosGiveSharedMem( pBaseAddress, idProcessId, ulAttributeFlags );


PVOID pBaseAddress (input)
This should contain the base address of the shared and giveable memory block. It should be the same address as the one returned when the block was created, using DosAllocSharedMem.

PID idProcessId (input)
The identifier of the process that should get access to the shared memory block.

ULONG ulAttributeFlags (input)
Attribute flags describing the desired access protection of the shared memory block.

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 <os2.h>
#include <bsememf.h>

Usage Explanation

DosGiveSharedMem is used to give another process access to a shared memory block. This will allocate the virtual address of the memory block into the virtual-address space of the process that recieves the access of the memory block. This is very similar to the process using DosGetSharedMem by itself to gain access to the shared memory block.

The shared memory block that is specified with the virtual address must be a giveable block. That is, it must have been created using DosAllocSharedMem with the OBJ_GIVEABLE attribute set.

The desired access protection must also be compatible with the access protection the shared memory block received when it was created.

Relevant Structures


Sample Code

#define INCL_DOSMEMMGR #include <os2.h> #include <bsememf.h> PVOID BaseAddress; /* Pointer to the shared memory block. */ ULONG AttributeFlags; /* Flags describing the memory block */ PID ProcessID; /* Identificarion of the process that should be */ /* granted access to the shared and giveable */ /* memory block. */ APIRET rc; /* Just for taking care of the return code */ /* So we create another process, and store the identification in */ /* ProcessID. We also use DosAllocSharedMem to create a */ /* shared and givable memory block, storing the base address */ /* of this block in BaseAddress. For this example we assume the */ /* memory block was created as giveable, readable and writeable. */ AttributeFlags = PAG_WRITE | PAG_READ; rc = DosGiveSharedMem( BaseAddress, ProcessID, AttributeFlags); if (rc != 0) { /* We have an error we must take care of. */ }

See Also

DosAllocSharedMem, DosGetNamedSharedMem, DosGetSharedMem


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