Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
5.9 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: monitor.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * DDE Manager client side DDESPY monitoring functions.
  7. *
  8. * Created: 11/20/91 Sanford Staab
  9. \***************************************************************************/
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. //
  13. // Other monitor events are initiated directly from SetLastDDEMLError()
  14. // and DoCallback().
  15. //
  16. /***************************************************************************\
  17. * MonitorStringHandle
  18. *
  19. * Description:
  20. * Launches a string handle monitor event. This function should be
  21. * invoked via the MONHSZ() macro so as not to slow down things much
  22. * when no DDESpy is running.
  23. *
  24. * History:
  25. * 11-26-91 sanfords Created.
  26. \***************************************************************************/
  27. VOID MonitorStringHandle(
  28. PCL_INSTANCE_INFO pcii,
  29. HSZ hsz, // local atom
  30. DWORD fsAction)
  31. {
  32. WCHAR szT[256];
  33. PEVENT_PACKET pep;
  34. DWORD cchString;
  35. CheckDDECritIn;
  36. UserAssert(pcii->MonitorFlags & MF_HSZ_INFO);
  37. if (!(cchString = GetAtomName(LATOM_FROM_HSZ(hsz), szT,
  38. sizeof(szT) / sizeof(WCHAR)))) {
  39. SetLastDDEMLError(pcii, DMLERR_INVALIDPARAMETER);
  40. return ;
  41. }
  42. cchString++;
  43. pep = (PEVENT_PACKET)DDEMLAlloc(sizeof(EVENT_PACKET) - sizeof(DWORD) +
  44. sizeof(MONHSZSTRUCT) + cchString * sizeof(WCHAR));
  45. if (pep == NULL) {
  46. SetLastDDEMLError(pcii, DMLERR_MEMORY_ERROR);
  47. return ;
  48. }
  49. pep->EventType = MF_HSZ_INFO;
  50. pep->fSense = TRUE;
  51. pep->cbEventData = (WORD)(sizeof(MONHSZSTRUCT) + cchString * sizeof(WCHAR));
  52. #define phszs ((MONHSZSTRUCT *)&pep->Data)
  53. phszs->cb = sizeof(MONHSZSTRUCT);
  54. phszs->fsAction = fsAction;
  55. phszs->dwTime = NtGetTickCount();
  56. phszs->hsz = hsz;
  57. phszs->hTask = (HANDLE)LongToHandle( pcii->tid );
  58. // phszs->wReserved = 0; // zero init.
  59. wcscpy(phszs->str, szT);
  60. LeaveDDECrit;
  61. Event(pep);
  62. EnterDDECrit;
  63. #undef phszs
  64. }
  65. /***************************************************************************\
  66. * MonitorLink
  67. *
  68. * Description:
  69. * Launches a link monitor event. This function should be
  70. * invoked via the MONLINK() macro so as not to slow down things much
  71. * when no DDESpy is running.
  72. *
  73. * History:
  74. * 11-26-91 sanfords Created.
  75. \***************************************************************************/
  76. VOID MonitorLink(
  77. PCL_INSTANCE_INFO pcii,
  78. BOOL fEstablished,
  79. BOOL fNoData,
  80. LATOM aService,
  81. LATOM aTopic,
  82. GATOM aItem,
  83. WORD wFmt,
  84. BOOL fServer,
  85. HCONV hConvServer,
  86. HCONV hConvClient)
  87. {
  88. PEVENT_PACKET pep;
  89. CheckDDECritIn;
  90. UserAssert(pcii->MonitorFlags & MF_LINKS);
  91. pep = (PEVENT_PACKET)DDEMLAlloc(sizeof(EVENT_PACKET) - sizeof(DWORD) +
  92. sizeof(MONLINKSTRUCT));
  93. if (pep == NULL) {
  94. SetLastDDEMLError(pcii, DMLERR_MEMORY_ERROR);
  95. return ;
  96. }
  97. pep->EventType = MF_LINKS;
  98. pep->fSense = TRUE;
  99. pep->cbEventData = sizeof(MONLINKSTRUCT);
  100. #define pls ((MONLINKSTRUCT *)&pep->Data)
  101. pls->cb = sizeof(MONLINKSTRUCT);
  102. pls->dwTime = NtGetTickCount();
  103. pls->hTask = (HANDLE)LongToHandle( pcii->tid );
  104. pls->fEstablished = fEstablished;
  105. pls->fNoData = fNoData;
  106. // use global atoms here - these need to be changed to local atoms before
  107. // the callbacks to the ddespy apps.
  108. pls->hszSvc = (HSZ)LocalToGlobalAtom(aService);
  109. pls->hszTopic = (HSZ)LocalToGlobalAtom(aTopic);
  110. IncGlobalAtomCount(aItem);
  111. pls->hszItem = (HSZ)aItem;
  112. pls->wFmt = wFmt;
  113. pls->fServer = fServer;
  114. pls->hConvServer = hConvServer;
  115. pls->hConvClient = hConvClient;
  116. LeaveDDECrit;
  117. Event(pep);
  118. EnterDDECrit;
  119. GlobalDeleteAtom((ATOM)(ULONG_PTR)pls->hszSvc);
  120. GlobalDeleteAtom((ATOM)(ULONG_PTR)pls->hszTopic);
  121. GlobalDeleteAtom(aItem);
  122. #undef pls
  123. }
  124. /***************************************************************************\
  125. * MonitorConv
  126. *
  127. * Description:
  128. * Launches a conversation monitor event. This function should be
  129. * invoked via the MONCONV() macro so as not to slow down things much
  130. * when no DDESpy is running.
  131. *
  132. * History:
  133. * 11-26-91 sanfords Created.
  134. * 5-8-92 sanfords Since the hConv's mean nothing outside this process,
  135. * the hConv fields now hold hwnds. This lets DDESPY
  136. * tie together connect and disconnect events from each
  137. * side.
  138. \***************************************************************************/
  139. VOID MonitorConv(
  140. PCONV_INFO pcoi,
  141. BOOL fConnect)
  142. {
  143. PEVENT_PACKET pep;
  144. CheckDDECritIn;
  145. UserAssert(pcoi->pcii->MonitorFlags & MF_CONV);
  146. pep = (PEVENT_PACKET)DDEMLAlloc(sizeof(EVENT_PACKET) - sizeof(DWORD) +
  147. sizeof(MONCONVSTRUCT));
  148. if (pep == NULL) {
  149. SetLastDDEMLError(pcoi->pcii, DMLERR_MEMORY_ERROR);
  150. return ;
  151. }
  152. pep->EventType = MF_CONV;
  153. pep->fSense = TRUE;
  154. pep->cbEventData = sizeof(MONCONVSTRUCT);
  155. #define pcs ((MONCONVSTRUCT *)&pep->Data)
  156. pcs->cb = sizeof(MONCONVSTRUCT);
  157. pcs->fConnect = fConnect;
  158. pcs->dwTime = NtGetTickCount();
  159. pcs->hTask = (HANDLE)LongToHandle( pcoi->pcii->tid );
  160. pcs->hszSvc = (HSZ)LocalToGlobalAtom(pcoi->laService);
  161. pcs->hszTopic = (HSZ)LocalToGlobalAtom(pcoi->laTopic);
  162. if (pcoi->state & ST_CLIENT) {
  163. pcs->hConvClient = (HCONV)pcoi->hwndConv;
  164. pcs->hConvServer = (HCONV)pcoi->hwndPartner;
  165. } else {
  166. pcs->hConvClient = (HCONV)pcoi->hwndPartner;
  167. pcs->hConvServer = (HCONV)pcoi->hwndConv;
  168. }
  169. LeaveDDECrit;
  170. Event(pep);
  171. EnterDDECrit;
  172. GlobalDeleteAtom((ATOM)(ULONG_PTR)pcs->hszSvc);
  173. GlobalDeleteAtom((ATOM)(ULONG_PTR)pcs->hszTopic);
  174. #undef pcs
  175. }