SUMMARY
An application can use the DdeCreateDataHandle function to create a
handle to a block of data. The application can use the handle to pass
the data to another application in a dynamic data exchange (DDE)
conversation using the Dynamic Data Exchange Management Libraries
(DDEML). All DDEML functions refer to blocks of memory using data
handles.
An application can allocate memory and manually create a data handle
associated with the memory (using method 1 below), or automatically by
using the DdeCreateDataHandle function (method 2 below).
Method 1
- Obtain a block of memory using the GlobalAlloc or LocalAlloc
function or by declaring a variable in your application.
- Fill the block of memory with the desired data.
- Call the DdeCreateDataHandle function to create a data handle
associated with the block of memory.
Method 2
- Call the DdeCreateDataHandle function with the lpvSrcBuf parameter
set to NULL, the cbInitData parameter set to zero, and the
offSrcBuf parameter set to the number of bytes of memory required.
- To retrieve a handle to the memory block, specify the data handle
returned by DdeCreateDataHandle as the hData parameter of the
DdeAccessData function. This operation is similar to calling the
GlobalLock function on a handle returned from GlobalAlloc.
- Use the pointer to fill the memory block with data.
- Call DdeUnaccessData to unaccess the object. This operation is
similar to calling the GlobalUnlock function on a handle returned
from GlobalAlloc.
The following code fragment demonstrates method 2:
// Retrieve the length of the data to be stored
cbLen = lstrlen("This is a test") + 1;
// Create the data handle and allocate the memory
hData = DdeCreateDataHandle(idInst, NULL, 0, cbLen,
hszItem, wFmt, 0);
// Access the data handle
lpstrData = (LPSTR)DdeAccessData(hData, NULL);
// Fill the block of memory
lstrcpy(lpstrData, "This is a test");
// Unaccess the data handle
DdeUnaccessData(hData);
When an application obtains a data handle from DdeCreateDataHandle,
the application should next call DdeAccessData with the handle. If a
data handle is first specified as a parameter to a DDEML function
other than DdeAccessData, when the application later calls
DdeAccessData, the application receives only read access to the
associated memory block.