Microsoft Windows DDESpy (DDESPY.EXE) monitors DDE activity in the system. You can use DDESpy as a tool for debugging your DDE applications. For more information about DDESpy, see Microsoft Windows Programming Tools.
You can use the API elements of the DDEML to create your own DDE monitoring applications. Like any DDEML application, a DDE monitoring application contains a DDE callback function. The DDEML notifies a monitoring application's DDE callback function whenever a DDE event occurs, passing information about the event to the callback function. The application typically displays the information in a window or writes it to a file.
To receive notifications from the DDEML, an application must have registered itself as a DDE monitor by specifying the APPCLASS_MONITOR flag in a call to the DdeInitialize function. In this same call, the application can specify one or more monitor flags to indicate the types of events of which the DDEML is to notify the application's callback function. The following table describes each of the monitor flags an application can specify:
Flag | Meaning |
MF_CALLBACKS | Notifies the callback function whenever a transaction is sent to any DDE callback function in the system. |
MF_CONV | Notifies the callback function whenever a conversation is established or terminated. |
MF_ERRORS | Notifies the callback function whenever a DDEML error occurs. |
MF_HSZ_INFO | Notifies the callback function whenever a DDEML application creates, frees, or increments the use count of a string handle or whenever a string handle is freed as a result of a call to the DdeUninitialize function. |
MF_LINKS | Notifies the callback function whenever an advise loop is started or ended. |
MF_POSTMSGS | Notifies the callback function whenever the system or an application posts a DDE message. |
MF_SENDMSGS | Notifies the callback function whenever the system or an application sends a DDE message. |
The following example shows how to register a DDE monitoring application so that its DDE callback function receives notifications of all DDE events:
DWORD idInst;
PFNCALLBACK lpDdeProc;
hInst = hInstance;
lpDdeProc = (PFNCALLBACK) MakeProcInstance(
(FARPROC) DDECallback, /* points to callback function */
hInstance); /* instance handle */
if (DdeInitialize(
(LPDWORD) &idInst, /* instance identifier */
lpDdeProc, /* points to callback function */
APPCLASS_MONITOR | /* this is a monitoring application */
MF_CALLBACKS | /* monitor callback functions */
MF_CONV | /* monitor conversation data */
MF_ERRORS | /* monitor DDEML errors */
MF_HSZ_INFO | /* monitor data-handle activity */
MF_LINKS | /* monitor advise loops */
MF_POSTMSGS | /* monitor posted DDE messages */
MF_SENDMSGS, /* monitor sent DDE messages */
0L)) /* reserved */
return FALSE;
The DDEML informs a monitoring application of a DDE event by sending an XTYP_MONITOR transaction to the application's DDE callback function. During this transaction, the DDEML passes a monitor flag that specifies the type of DDE event that has occurred and a handle of a global memory object that contains detailed information about the event. The DDEML provides a set of structures that the application can use to extract the information from the memory object. There is a corresponding structure for each type of DDE event. The following table describes each of these structures:
Structure | Description |
MONCBSTRUCT | Contains information about a transaction. |
MONCONVSTRUCT | Contains information about a conversation. |
MONERRSTRUCT | Contains information about the latest DDE error. |
MONLINKSTRUCT | Contains information about an advise loop. |
MONHSZSTRUCT | Contains information about a string handle. |
MONMSGSTRUCT | Contains information about a DDE message that was sent or posted. |
The following example shows the DDE callback function of a DDE monitoring application that formats information about each string handle event and then displays the information in a window. The function uses the MONHSZSTRUCT structure to extract the information from the global memory object.
HDDEDATA CALLBACK DDECallback(wType, wFmt, hConv, hsz1, hsz2,
hData, dwData1, dwData2)
WORD wType;
WORD wFmt;
HCONV hConv;
HSZ hsz1;
HSZ hsz2;
HDDEDATA hData;
DWORD dwData1;
DWORD dwData2;
{
LPVOID lpData;
char *szAction;
char buf[256];
DWORD cb;
switch (wType) {
case XTYP_MONITOR:
/* Obtain a pointer of the global memory object. */
if (lpData = DdeAccessData(hData, &cb)) {
/* Examine the monitor flag. */
switch (dwData2) {
case MF_HSZ_INFO:
#define PHSZS ((MONHSZSTRUCT FAR *)lpData)
/*
* The global memory object contains
* string-handle data. Use the MONHSZSTRUCT
* structure to access the data.
*/
switch (PHSZS->fsAction) {
/*
* Examine the action flags to determine
* the action performed on the handle.
*/
case MH_CREATE:
szAction = "Created";
break;
case MH_KEEP:
szAction = "Incremented";
break;
case MH_DELETE:
szAction = "Deleted";
break;
case MH_CLEANUP:
szAction = "Cleaned up";
break;
default:
DdeUnaccessData(hData);
return ((HDDEDATA) 0);
}
/* Write formatted output to a buffer. */
wsprintf(buf,
"Handle %s, Task: %x, Hsz: %lx(%s)",
(LPSTR) szAction, PHSZS->hTask, PHSZS->hsz,
(LPSTR) PHSZS->str);
.
. /* Display text in window or write to file. */
.
break;
#undef PHSZS
.
. /* Process other MF_* flags. */
.
default:
break;
}
}
/* Free the global memory object. */
DdeUnaccessData(hData);
break;
default:
break;
}
return ((HDDEDATA) 0);
}