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

The OS/2 API Project

DosGiveSharedMem

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

Syntax

rc = DosGiveSharedMem( pBaseAddress, idProcessId, ulAttributeFlags );

Parameters

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.

Returns

APIRET rc
The following values can be returned
0NO_ERROR
5ERROR_ACCESS_DENIED
8ERROR_NOT_ENOUGH_MEMORY
87ERROR_INVALID_PARAMETER
95ERROR_INTERRUPT
212ERROR_LOCKED
303ERROR_INVALID_PROCID
487ERROR_INVALID_ADDRESS

Include Info

#define INCL_DOSMEMMGR
#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

Gotchas

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

Author

Stefan Mars - mars@lysator.liu.se

Additions

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

The OS/2 API Project

DosGiveSharedMem