13-9
Dynamic Data Exchange
SendPoke(
HWND hwnd, /* Our Window handle */
HWND hWndPartnerDDE, /* handle for partner in DDE */
char *szItem, /* String ID for transfer */
int iData, /* Value to be transferred */
char *szValue, /* Data to be transferred */
int iValCount /* Number of bytes in transfer */
)
{
ATOM atomItem;
HANDLE hPokeData;
DDEPOKE FAR * lpPokeData;
LPSTR pTemp;
/* Allocate size of DDE data header, plus the data: a string */
/* terminated by <CR> <LF> <NULL>. The <NULL> is counted by */
/* by DDEPOKE.Value[1]. */
if (!(hPokeData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
(LONG)sizeof(DDEPOKE) + iValCount + sizeof(int) + 2)))
return;
if (!(lpPokeData = (DDEPOKE FAR*)GlobalLock(hPokeData)))
return;
lpPokeData->fRelease = TRUE;
lpPokeData->cfFormat = CF_TEXT;
pTemp = lpPokeData-> Value;
*(int far *)pTemp = iData;
pTemp += sizeof(int);
if (iValCount)
_fmemcpy(pTemp, szValue, iValCount);
/* each line of CF_TEXT data is terminated by CR/LF */
lstrcpy((LPSTR)(pTemp + iValCount), (LPSTR)”\r\n”);
GlobalUnlock(hPokeData);
atomItem = GlobalAddAtom((LPSTR)szItem);
if (!PostMessage(
hWndPartnerDDE,
WM_DDE_POKE,
hWnd,
MAKELONG(hPokeData, atomItem))
)
{
GlobalDeleteAtom(atomItem);
GlobalFree(hPokeData);
}
return;
}