Tools.h++ Class Reference

Table Of Contents
In dynamic mode, the RWDDEstreambuf "owns" any allocated memory until the member
function str() is called, which "freezes" the buffer and returns an unlocked Windows handle to
it. The effect of any further insertions is undefined. Until str() has been called, it is the
responsibility of the RWDDEstreambuf destructor to free any allocated memory. After the call
to str(), it becomes the user's responsibility.
In static mode, the user always has the responsibility for freeing the memory handle. However,
because the constructor locks and dereferences the handle, you should not free the memory until
either the destructor or str() has been called, either of which will unlock the handle.
Note that although the user may have the "responsibility" for freeing the memory, whether it is
the client or the server that actually does the call to GlobalFree() will depend on the DDE
"release" flag.
Persistence
None
Example
This is an example of how the class might be used by a DDE server.
#include <rw/winstrea.h>
#include <iostream.h>
#include <windows.h>
#include <dde.h>
BOOL
postToDDE(HWND hwndServer, HWND hwndClient) {
RWDDEstreambuf* buf =
new RWDDEstreambuf(CF_TEXT, TRUE, TRUE, TRUE);
ostream ostr(buf);
double d = 12.34;
ostr << "Some text to be exchanged through the DDE.\n";
ostr << "The double you requested is: " << d << endl;
ostr.put(0); // Include the terminating null
// Lock the streambuf, get its handle:
HANDLE hMem = buf->str();
// Get an identifying atom:
ATOM aItem = GlobalAddAtom("YourData");
if(!PostMessage(hwndClient, WM_DDE_DATA, hwndServer,
MAKELONG(hMem, aItem))){
// Whoops! The message post failed, perhaps because
// the client terminated. Now we are responsible
// for deallocating the memory:
if( hMem != NULL )