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.

140 lines
3.9 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: register.c
  3. *
  4. * DDE Manager - server registration module
  5. *
  6. * Created: 4/15/94 sanfords
  7. * to allow interoperability between DDEML16 and DDEML32
  8. \***************************************************************************/
  9. #include <windows.h>
  10. #include <string.h>
  11. #include "ddemlp.h"
  12. /*
  13. * interoperable DDEML service registration is accomplished via the
  14. * two messages UM_REGISTER and UM_UNREGISTER. (WM_USER range)
  15. * wParam=gaApp,
  16. * lParam=src hwndListen, (for instance specific HSZ generation.)
  17. * These messages are sent and the sender is responsible for freeing
  18. * the gaApp.
  19. */
  20. /*
  21. * Broadcast-sends the given message to all top-level windows of szClass
  22. * except to hwndSkip.
  23. */
  24. VOID SendMessageToClass(
  25. ATOM atomClass,
  26. UINT msg,
  27. GATOM ga,
  28. HWND hwndFrom,
  29. HWND *ahwndSkip,
  30. int chwndSkip,
  31. BOOL fPost)
  32. {
  33. HWND hwnd;
  34. int i;
  35. BOOL fSkipIt;
  36. hwnd = GetWindow(GetDesktopWindow(), GW_CHILD);
  37. while (hwnd != NULL) {
  38. if (GetClassWord(hwnd, GCW_ATOM) == atomClass) {
  39. fSkipIt = FALSE;
  40. for (i = 0; i < chwndSkip; i++) {
  41. if (hwnd == ahwndSkip[i]) {
  42. fSkipIt = TRUE;
  43. break;
  44. }
  45. }
  46. if (!fSkipIt) {
  47. IncHszCount(ga); // receiver frees
  48. if (fPost) {
  49. PostMessage(hwnd, msg, (WPARAM)ga, (LPARAM)hwndFrom);
  50. } else {
  51. SendMessage(hwnd, msg, (WPARAM)ga, (LPARAM)hwndFrom);
  52. }
  53. }
  54. }
  55. hwnd = GetWindow(hwnd, GW_HWNDNEXT);
  56. }
  57. }
  58. /*
  59. * Broadcast-sends a UM_REGISTER or UM_UNREGISTER message to all DDEML16
  60. * and DDEML32 listening windows in the system except hwndSkip.
  61. */
  62. VOID RegisterService(
  63. BOOL fRegister,
  64. GATOM gaApp,
  65. HWND hwndListen)
  66. {
  67. PAPPINFO paiT;
  68. int cSkips = 1;
  69. HWND *ahwndSkip;
  70. int i;
  71. extern ATOM gatomDDEMLMom;
  72. extern ATOM gatomDMGClass;
  73. /*
  74. * First send (always!) to our own guys the same way we used to
  75. * for compatability. WordPerfect 6.0a relies on this!
  76. */
  77. for (paiT = pAppInfoList; paiT != NULL; paiT = paiT->next) {
  78. IncHszCount(gaApp); // receiver frees atom
  79. SendMessage(paiT->hwndDmg,
  80. fRegister ? UM_REGISTER : UM_UNREGISTER,
  81. (WPARAM)gaApp, (LPARAM)hwndListen);
  82. cSkips++;
  83. }
  84. /*
  85. * build up the hwndskip list.
  86. */
  87. ahwndSkip = (HWND *)LocalAlloc(LPTR, sizeof(HWND) * cSkips);
  88. if (ahwndSkip == NULL) {
  89. return;
  90. }
  91. for (paiT = pAppInfoList, i = 0;
  92. paiT != NULL;
  93. paiT = paiT->next, i++) {
  94. ahwndSkip[i] = paiT->hwndDmg;
  95. }
  96. AssertF(gatomDDEMLMom, "gatomDDEMLMom not initialized in RegisterService");
  97. AssertF(gatomDMGClass, "gatomDMGClass not initialized in RegisterService");
  98. /*
  99. * Send notification to each DDEML32 listening window.
  100. */
  101. SendMessageToClass(gatomDDEMLMom, fRegister ? UM_REGISTER : UM_UNREGISTER,
  102. gaApp, hwndListen, ahwndSkip, i, fRegister);
  103. /*
  104. * Send notification to each DDEML16 listening window.
  105. */
  106. SendMessageToClass(gatomDMGClass, fRegister ? UM_REGISTER : UM_UNREGISTER,
  107. gaApp, hwndListen, ahwndSkip, i, fRegister);
  108. LocalFree((HLOCAL)ahwndSkip);
  109. }
  110. LRESULT ProcessRegistrationMessage(
  111. HWND hwnd,
  112. UINT msg,
  113. WPARAM wParam,
  114. LPARAM lParam)
  115. {
  116. /*
  117. * wParam = GATOM of app
  118. * lParam = hwndListen of source
  119. */
  120. DoCallback((PAPPINFO)GetWindowWord(hwnd, GWW_PAI), (HCONV)0L, (HSZ)wParam,
  121. MakeInstAppName(wParam, (HWND)lParam), 0,
  122. msg == UM_REGISTER ? XTYP_REGISTER : XTYP_UNREGISTER,
  123. (HDDEDATA)0, 0L, 0L);
  124. GlobalDeleteAtom((ATOM)wParam); // receiver frees.
  125. return(1);
  126. }