Named Buffer

Sometimes you need to communicate with other modules or even other processes. In that case it's very useful to have an easy to use method of sharing a data block. For this purpose madKernel offers the "INamedBuffer" interface. See also the INamedBuffer Reference.

type INamedBuffer = interface (IKernelObj) ['{AA4C5EE0-C417-11D3-A530-00005A180D69}'];

First of all you must call "NewNamedBuffer" to make it all work. Enter the desired buffer size and a system wide unique name. As a result you'll get an INamedBuffer instance. Now while this instance is valid every other module in every other process can open this buffer for read or write access by calling "OpenNamedBuffer". It's also possible to call "NewNamedBuffer" instead of "OpenNamedBuffer". If the buffer already existed before you called "NewNamedBuffer", the effect is the same as if you would have called "OpenNamedBuffer" with write access. Please note, that you can't change the size of an existing buffer.

function NewNamedBuffer (name : string;
                         size : integer) : INamedBuffer;

function OpenNamedBuffer (name        : string;
                          writeAccess : boolean = true) : INamedBuffer;

Which name does this buffer have?

property INamedBuffer.Name : string;

How bug is this named buffer? Don't dare to write over the bounds!

property INamedBuffer.Size : integer;

Where in memory is this buffer located?

property INamedBuffer.Memory : pointer;

// Example:
nb := NewNamedBuffer('MadshisWindowsHookHandle', 4);
cardinal(nb.Memory^) := SetWindowsHookEx(...);

Do we have write access to this buffer?

function INamedBuffer.IsWriteAccess : boolean;