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.

182 lines
4.6 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: ddemlsvr.C
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * DDE Manager main module - Contains all server side ddeml functions.
  7. *
  8. * 27-Aug-1991 Sanford Staab Created
  9. * 21-Jan-1992 IanJa ANSI/Unicode neutralized
  10. \***************************************************************************/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. // globals
  14. PSVR_INSTANCE_INFO psiiList;
  15. DWORD xxxCsDdeInitialize(
  16. PHANDLE phInst,
  17. HWND *phwndEvent,
  18. LPDWORD pMonitorFlags,
  19. DWORD afCmd,
  20. PVOID pcii)
  21. {
  22. PSVR_INSTANCE_INFO psii;
  23. PTHREADINFO ptiCurrent = PtiCurrent();
  24. CheckCritIn();
  25. psii = (PSVR_INSTANCE_INFO)HMAllocObject(PtiCurrent(), NULL,
  26. TYPE_DDEACCESS, sizeof(SVR_INSTANCE_INFO));
  27. if (psii == NULL) {
  28. return DMLERR_SYS_ERROR;
  29. }
  30. /*
  31. * We have to tell CreateWindow that window is not created for the same
  32. * module has the app, (CW_FLAGS_DIFFHMOD), so CreateWindow doesn't
  33. * assign a hotkey to this window. Other window are done in the
  34. * client-server thunk
  35. */
  36. Lock(&(psii->spwndEvent), xxxNVCreateWindowEx(
  37. 0,
  38. (PLARGE_STRING)gpsi->atomSysClass[ICLS_DDEMLEVENT],
  39. NULL,
  40. WS_POPUP | WS_CHILD,
  41. 0, 0, 0, 0,
  42. (PWND)NULL,
  43. (PMENU)NULL,
  44. hModuleWin,
  45. NULL,
  46. CW_FLAGS_DIFFHMOD | VER31));
  47. if (psii->spwndEvent == NULL) {
  48. HMFreeObject((PVOID)psii);
  49. return DMLERR_SYS_ERROR;
  50. }
  51. /*
  52. * This GWL offset does NOT leave the critical section!
  53. */
  54. xxxSetWindowLongPtr(psii->spwndEvent, GWLP_PSII, (LONG_PTR)PtoH(psii), FALSE);
  55. psii->afCmd = 0;
  56. psii->pcii = pcii;
  57. //
  58. // Link into global list
  59. //
  60. psii->next = psiiList;
  61. psiiList = psii;
  62. //
  63. // Link into per-process list
  64. //
  65. psii->nextInThisThread = ptiCurrent->psiiList;
  66. ptiCurrent->psiiList = psii;
  67. *phInst = PtoH(psii);
  68. *phwndEvent = PtoH(psii->spwndEvent);
  69. xxxChangeMonitorFlags(psii, afCmd); // sets psii->afCmd;
  70. *pMonitorFlags = MonitorFlags;
  71. return DMLERR_NO_ERROR;
  72. }
  73. DWORD _CsUpdateInstance(
  74. HANDLE hInst,
  75. LPDWORD pMonitorFlags,
  76. DWORD afCmd)
  77. {
  78. PSVR_INSTANCE_INFO psii;
  79. CheckCritIn();
  80. psii = (PSVR_INSTANCE_INFO)HMValidateHandleNoRip(hInst, TYPE_DDEACCESS);
  81. if (psii == NULL) {
  82. return DMLERR_INVALIDPARAMETER;
  83. }
  84. xxxChangeMonitorFlags(psii, afCmd);
  85. *pMonitorFlags = MonitorFlags;
  86. return DMLERR_NO_ERROR;
  87. }
  88. BOOL _CsDdeUninitialize(
  89. HANDLE hInst)
  90. {
  91. PSVR_INSTANCE_INFO psii;
  92. CheckCritIn();
  93. psii = HMValidateHandleNoRip(hInst, TYPE_DDEACCESS);
  94. if (psii == NULL) {
  95. return TRUE;
  96. }
  97. xxxDestroyThreadDDEObject(PtiCurrent(), psii);
  98. return TRUE;
  99. }
  100. VOID xxxDestroyThreadDDEObject(
  101. PTHREADINFO pti,
  102. PSVR_INSTANCE_INFO psii)
  103. {
  104. PSVR_INSTANCE_INFO psiiT;
  105. CheckCritIn();
  106. if (HMIsMarkDestroy(psii)) {
  107. return;
  108. }
  109. //
  110. // Unlink psii from the global list.
  111. //
  112. if (psii == psiiList) {
  113. psiiList = psii->next;
  114. } else {
  115. for (psiiT = psiiList; psiiT->next != psii; psiiT = psiiT->next) {
  116. UserAssert(psiiT->next != NULL);
  117. }
  118. psiiT->next = psii->next;
  119. }
  120. // psii->next = NULL;
  121. //
  122. // Unlink psii from the per-process list.
  123. //
  124. if (psii == pti->psiiList) {
  125. pti->psiiList = psii->nextInThisThread;
  126. } else {
  127. for (psiiT = pti->psiiList; psiiT->nextInThisThread != psii; psiiT = psiiT->nextInThisThread) {
  128. UserAssert(psiiT->nextInThisThread != NULL);
  129. }
  130. psiiT->nextInThisThread = psii->nextInThisThread;
  131. }
  132. // psii->nextInThisThread = NULL;
  133. if (HMMarkObjectDestroy(psii)) {
  134. PWND pwnd = psii->spwndEvent;
  135. /*
  136. * We already removed psii from the linked list. This means that it
  137. * will not get another chance to be cleaned up in
  138. * xxxDestroyThreadInfo(), Since xxxDestroyWindow might leave
  139. * the critical section the cleanup needs to be done in the below
  140. * sequence else we will leak pssi and pwnd might be locked for good.
  141. * [msadek - 03/12/2002]
  142. */
  143. if (Unlock(&(psii->spwndEvent))) {
  144. HMFreeObject(psii);
  145. xxxDestroyWindow(pwnd);
  146. } else {
  147. HMFreeObject(psii);
  148. }
  149. }
  150. }