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.

318 lines
7.3 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: rnawnd.cpp
  4. //
  5. // Module: CMMON32.EXE
  6. //
  7. // Synopsis: Kill the DUN Reconnect dialog for Win95 Gold
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // Author: quintinb Created header 08/17/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include "cmmaster.h"
  15. #include <process.h>
  16. struct RECONNECT_PARAM
  17. {
  18. HANDLE hEvent;
  19. BOOL *pbConnLost;
  20. };
  21. static unsigned long __stdcall ZapRNAReconnectThread(void *pvParam)
  22. {
  23. RECONNECT_PARAM* pParam = (RECONNECT_PARAM*) pvParam;
  24. HANDLE hEvent = pParam->hEvent;
  25. BOOL *pbConnLost = pParam->pbConnLost;
  26. long lRes;
  27. BOOL bRes;
  28. HMODULE hLibrary;
  29. HRSRC hrsrcDlg;
  30. HGLOBAL hgDlg;
  31. LPDLGTEMPLATE pDlg;
  32. WCHAR szTmp[MAX_PATH];
  33. unsigned uRes = 1;
  34. HWND hwndRNA;
  35. HLOCAL hRes;
  36. CMTRACE(TEXT("ZapRNAReconnectThread()"));
  37. hRes = LocalFree(pvParam);
  38. #ifdef DEBUG
  39. if (hRes)
  40. {
  41. CMTRACE1(TEXT("ZapRNAReconnectThread() LocalFree() failed, GLE=%u."), GetLastError());
  42. }
  43. #endif
  44. szTmp[0] = 0;
  45. hLibrary = LoadLibraryExA("rnaapp.exe", NULL, LOAD_LIBRARY_AS_DATAFILE);
  46. if (hLibrary)
  47. {
  48. hrsrcDlg = FindResourceExU(hLibrary, TEXT("#1010"), RT_DIALOG, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
  49. if (hrsrcDlg)
  50. {
  51. hgDlg = LoadResource(hLibrary, hrsrcDlg);
  52. if (hgDlg)
  53. {
  54. pDlg = (LPDLGTEMPLATE) LockResource(hgDlg);
  55. if (pDlg)
  56. {
  57. LPWSTR pszTmp = (LPWSTR) (pDlg + 1);
  58. switch (*pszTmp)
  59. {
  60. case 0x0000:
  61. pszTmp++;
  62. break;
  63. case 0xffff:
  64. pszTmp += 2;
  65. break;
  66. default:
  67. pszTmp += lstrlenU(pszTmp) + 1;
  68. break;
  69. }
  70. switch (*pszTmp)
  71. {
  72. case 0x0000:
  73. pszTmp++;
  74. break;
  75. case 0xffff:
  76. pszTmp += 2;
  77. break;
  78. default:
  79. pszTmp += lstrlenU(pszTmp) + 1;
  80. }
  81. lstrcpyU(szTmp, pszTmp);
  82. }
  83. else
  84. {
  85. CMTRACE(TEXT("ZapRNAReconnectThread() LockResource() failed."));
  86. }
  87. }
  88. else
  89. {
  90. CMTRACE1(TEXT("ZapRNAReconnectThread() LoadResource() failed, GLE=%u."), GetLastError());
  91. }
  92. }
  93. else
  94. {
  95. CMTRACE1(TEXT("ZapRNAReconnectThread() FindResource() failed, GLE=%u."), GetLastError());
  96. }
  97. bRes = FreeLibrary(hLibrary);
  98. #ifdef DEBUG
  99. if (!bRes)
  100. {
  101. CMTRACE1(TEXT("ZapRNAReconnectThread() FreeLibrary() failed, GLE=%u."), GetLastError());
  102. }
  103. #endif
  104. }
  105. else
  106. {
  107. CMTRACE1(TEXT("ZapRNAReconnectThread() LoadLibraryEx() failed, GLE=%u."), GetLastError());
  108. }
  109. if (szTmp[0])
  110. {
  111. CMTRACE1(TEXT("ZapRNAReconnectThread() is watching for a window named %s."), szTmp);
  112. while (1)
  113. {
  114. lRes = WaitForSingleObject(hEvent,750);
  115. if (lRes != WAIT_TIMEOUT)
  116. {
  117. #ifdef DEBUG
  118. if (WAIT_FAILED == lRes)
  119. {
  120. CMTRACE1(TEXT("ZapRNAReconnectThread() WaitForSingleObject() failed, GLE=%u."),
  121. GetLastError());
  122. }
  123. else if (WAIT_OBJECT_0 == lRes)
  124. {
  125. CMTRACE(TEXT("ZapRNAReconnectThread() was told to die."));
  126. }
  127. #endif
  128. break;
  129. }
  130. hwndRNA = FindWindowExU(NULL, NULL, WC_DIALOG, szTmp);
  131. if (hwndRNA)
  132. {
  133. CMTRACE(TEXT("ZapRNAReconnectThread() is canceling the reconnect dialog."));
  134. PostMessageA(hwndRNA,WM_COMMAND,IDCANCEL,0);
  135. if (pbConnLost)
  136. {
  137. *pbConnLost = TRUE;
  138. }
  139. }
  140. }
  141. }
  142. bRes = CloseHandle(hEvent);
  143. #ifdef DEBUG
  144. if (!bRes)
  145. {
  146. CMTRACE1(TEXT("ZapRNAReconnectThread() CloseHandle() failed, GLE=%u."), GetLastError());
  147. }
  148. CMTRACE1(TEXT("ZapRNAReconnectThread() is exiting with uRes=%u."), uRes);
  149. #endif
  150. return (uRes);
  151. }
  152. HANDLE ZapRNAReconnectStart(BOOL *pbConnLost)
  153. {
  154. HANDLE hEvent;
  155. BOOL bRes;
  156. HANDLE hThread = NULL;
  157. unsigned long tidThread;
  158. RECONNECT_PARAM* pParam = NULL;
  159. HLOCAL hRes;
  160. CMTRACE(TEXT("ZapRNAReconnectStart()"));
  161. //
  162. // Not quite right for multiple connections. This is unlike to happen for Win95 Gold w DUN1.0
  163. //
  164. hEvent = CreateEventA(NULL, FALSE, FALSE, "IConnMgr ZRRS Event");
  165. #ifdef DEBUG
  166. if (!hEvent)
  167. {
  168. CMTRACE1(TEXT("ZapRNAReconnectStart() CreateEvent() failed, GLE=%u."), GetLastError());
  169. }
  170. else if (hEvent && (ERROR_ALREADY_EXISTS == GetLastError()))
  171. {
  172. CMTRACE(TEXT("ZapRNAReconnectStart() ZapRNAReconnectThread() is already running."));
  173. }
  174. #endif
  175. if (hEvent && (GetLastError() != ERROR_ALREADY_EXISTS))
  176. {
  177. pParam = (RECONNECT_PARAM*) LocalAlloc(LPTR,sizeof(*pParam));
  178. if (pParam)
  179. {
  180. pParam->hEvent = hEvent;
  181. pParam->pbConnLost = pbConnLost;
  182. hThread = (HANDLE) CreateThread(NULL,0,ZapRNAReconnectThread,pParam,0,&tidThread);
  183. #ifdef DEBUG
  184. if (!hThread)
  185. {
  186. CMTRACE1(TEXT("ZapRNAReconnectStart() CreateThread() failed, GLE=%u."), GetLastError());
  187. }
  188. #endif
  189. }
  190. }
  191. if (!hThread)
  192. {
  193. bRes = CloseHandle(hEvent);
  194. #ifdef DEBUG
  195. if (!bRes)
  196. {
  197. CMTRACE1(TEXT("ZapRNAReconnectStart() CloseHandle() failed, GLE=%u."), GetLastError());
  198. }
  199. #endif
  200. if (pParam)
  201. {
  202. hRes = LocalFree(pParam);
  203. #ifdef DEBUG
  204. if (hRes)
  205. {
  206. CMTRACE1(TEXT("ZapRNAReconnectStart() LocalFree() failed, GLE=%u."), GetLastError());
  207. }
  208. #endif
  209. }
  210. }
  211. CMTRACE1(TEXT("ZapRNAReconnectStart() is exiting with hThread=%u."), hThread);
  212. return hThread;
  213. }
  214. void ZapRNAReconnectStop(HANDLE hThread)
  215. {
  216. HANDLE hEvent;
  217. BOOL bRes;
  218. long lRes;
  219. CMTRACE(TEXT("ZapRNAReconnectStop()"));
  220. MYDBGASSERT(hThread);
  221. hEvent = OpenEventA(EVENT_MODIFY_STATE, FALSE, "IConnMgr ZRRS Event");
  222. if (hEvent)
  223. {
  224. bRes = SetEvent(hEvent);
  225. #ifdef DEBUG
  226. if (!bRes)
  227. {
  228. CMTRACE1(TEXT("ZapRNAReconnectStop() SetEvent() failed, GLE=%u."), GetLastError());
  229. }
  230. #endif
  231. bRes = CloseHandle(hEvent);
  232. #ifdef DEBUG
  233. if (!bRes)
  234. {
  235. CMTRACE1(TEXT("ZapRNAReconnectStop() CloseHandle(hEvent) failed, GLE=%u."), GetLastError());
  236. }
  237. #endif
  238. lRes = WaitForSingleObject(hThread,2000);
  239. #ifdef DEBUG
  240. if (WAIT_OBJECT_0 != lRes)
  241. {
  242. CMTRACE2(TEXT("ZapRNAReconnectStop() WaitForSingleObject() returns %u, GLE=%u."),
  243. lRes, (WAIT_FAILED == lRes) ? GetLastError() : 0);
  244. }
  245. #endif
  246. bRes = CloseHandle(hThread);
  247. #ifdef DEBUG
  248. if (!bRes)
  249. {
  250. CMTRACE1(TEXT("ZapRNAReconnectStop() CloseHandle(hThread) failed, GLE=%u."), GetLastError());
  251. }
  252. #endif
  253. }
  254. else
  255. {
  256. CMTRACE1(TEXT("ZapRNAReconnectStop() OpenEvent() failed, GLE=%u."), GetLastError());
  257. }
  258. CloseHandle(hThread);
  259. CMTRACE1(TEXT("ZapRNAReconnectStop() is exiting."), hThread);
  260. }