Source code of Windows XP (NT5)
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.

342 lines
7.9 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: rnawnd.cpp
  4. //
  5. // Module: CMDIAL32.DLL
  6. //
  7. // Synopsis: Win9x Rnaapp.exe workaround code.
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // Author: quintinb created Header 08/16/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include "cmmaster.h"
  15. #include <process.h>
  16. #define MAX_RNA_WND_TITLE_LEN 26 // Max chars for window title compare
  17. #define MAX_ZAPRNA_PAUSE 50 // milliseconds to pause between window enumerations
  18. typedef struct tagFRCTParam {
  19. HANDLE hEvent;
  20. LPSTR pszDun;
  21. } ZRCTParam, *PZRCTP;
  22. typedef struct tagFindParam {
  23. LPCSTR pszTitle;
  24. HWND hwndRNA;
  25. } FINDPARAM, *PFINDPARAM;
  26. //+---------------------------------------------------------------------------
  27. //
  28. // Function: FindRnaWindow
  29. //
  30. // Synopsis: Callback for EnumWindows(). It receives the hwnd of all the
  31. // top-level windows. It's job is to look for the RNA status wnd.
  32. //
  33. // Arguments: hwndTop hwnd of the top-level window
  34. // lParam title of the rna wnd to be found.
  35. //
  36. // Returns: NONE
  37. //
  38. // History: henryt Created 8/19/97
  39. //----------------------------------------------------------------------------
  40. BOOL CALLBACK FindRnaWindow(
  41. HWND hwndTop,
  42. LPARAM lParam)
  43. {
  44. MYDBGASSERT(lParam);
  45. PFINDPARAM pFindParam = (PFINDPARAM) lParam;
  46. CHAR szTitle[MAX_RNA_WND_TITLE_LEN + 1];
  47. if (NULL == pFindParam)
  48. {
  49. return TRUE;
  50. }
  51. //
  52. // We are looking for a top-level window with a title matching lParam
  53. //
  54. if (MAKEINTATOM(GetClassLongU(hwndTop, GCW_ATOM)) == WC_DIALOG)
  55. {
  56. GetWindowTextA(hwndTop, szTitle, MAX_RNA_WND_TITLE_LEN + 1);
  57. //
  58. // truncate the window title as we only check the first few chars
  59. //
  60. szTitle[MAX_RNA_WND_TITLE_LEN] = '\0';
  61. if (lstrcmpA(szTitle, pFindParam->pszTitle) == 0)
  62. {
  63. //
  64. // Its a match, update the hwnd and bail
  65. //
  66. pFindParam->hwndRNA = hwndTop;
  67. return FALSE;
  68. }
  69. }
  70. return TRUE;
  71. }
  72. //+----------------------------------------------------------------------------
  73. //
  74. // Function: fnZRCT
  75. //
  76. // Synopsis: Thread to terminate RNA "Connected To" dlg
  77. //
  78. // Arguments: void *pvParam - Thread parameters PZRCTP containing connectoid
  79. // name is expected
  80. //
  81. // Returns: unsigned long - Standard thread return code
  82. //
  83. // History: nickball Created 3/5/98
  84. //
  85. //+----------------------------------------------------------------------------
  86. static unsigned long __stdcall fnZRCT(void *pvParam)
  87. {
  88. PZRCTP pParam = (PZRCTP) pvParam;
  89. PFINDPARAM pFindParam = NULL;
  90. unsigned uRes = 1;
  91. HMODULE hLibrary = NULL;
  92. BOOL bRes;
  93. HLOCAL hRes;
  94. LPSTR pszFmt = NULL;
  95. CHAR szTmp[MAX_PATH];
  96. DWORD dwIdx;
  97. DWORD dwWait;
  98. MYDBGASSERT(pParam->hEvent);
  99. MYDBGASSERT(pParam->pszDun);
  100. //
  101. // Load RNAAPP.EXE, so we can access its resources
  102. //
  103. hLibrary = LoadLibraryExA("rnaapp.exe", NULL, LOAD_LIBRARY_AS_DATAFILE);
  104. if (!hLibrary)
  105. {
  106. uRes = GetLastError();
  107. CMTRACE1(TEXT("fnZRCT() LoadLibraryEx() failed, GLE=%u."), GetLastError());
  108. goto done;
  109. }
  110. //
  111. // Extract string #204 from RNAAPP.EXE, then release.
  112. //
  113. if (!LoadStringA(hLibrary, 204, szTmp, sizeof(szTmp)/sizeof(CHAR)-1))
  114. {
  115. uRes = GetLastError();
  116. CMTRACE1(TEXT("fnZRCT() LoadString() failed, GLE=%u."), GetLastError());
  117. goto done;
  118. }
  119. bRes = FreeLibrary(hLibrary);
  120. hLibrary = NULL;
  121. #ifdef DEBUG
  122. if (!bRes)
  123. {
  124. CMTRACE1(TEXT("fnZRCT() FreeLibrary() failed, GLE=%u."), GetLastError());
  125. }
  126. #endif
  127. //
  128. // Format the string with our DUN name
  129. //
  130. pszFmt = (LPSTR)CmMalloc((lstrlenA(szTmp)+1)*sizeof(TCHAR));
  131. if (!pszFmt)
  132. {
  133. uRes = GetLastError();
  134. CMTRACE1(TEXT("fnZRCT() CmMalloc() failed, GLE=%u."), GetLastError());
  135. goto done;
  136. }
  137. lstrcpyA(pszFmt, szTmp);
  138. wsprintfA(szTmp, pszFmt, pParam->pszDun);
  139. //
  140. // to work around a bug where a long connectoid/profile name can prevent
  141. // us to look for the RNA window(because the window title will be truncated)
  142. // we only read the first 26 chars.
  143. //
  144. szTmp[MAX_RNA_WND_TITLE_LEN] = '\0';
  145. //
  146. // Setup param for FindRnaWindow callback used in EnumWindows
  147. //
  148. pFindParam = (PFINDPARAM)CmMalloc(sizeof(FINDPARAM));
  149. if (!pFindParam)
  150. {
  151. CMTRACE1(TEXT("ZapRNAConnectedTo() CmMalloc() failed, GLE=%u."), GetLastError());
  152. goto done;
  153. }
  154. pFindParam->pszTitle = szTmp;
  155. pFindParam->hwndRNA = NULL;
  156. //
  157. // Try to find the window every 50 milliseconds up to 200 times
  158. //
  159. CMTRACE1(TEXT("fnZRCT() is watching for a window named %s."), szTmp);
  160. for (dwIdx=0; dwIdx < 200; dwIdx++)
  161. {
  162. EnumWindows(FindRnaWindow, (LPARAM) pFindParam);
  163. //hwndRNA = FindWindow(TEXT("#32770"),szTmp);
  164. //
  165. // If hwnd has a value, its the RNA wind, hide it and bail
  166. //
  167. if (pFindParam->hwndRNA)
  168. {
  169. CMTRACE(TEXT("fnZRCT() is hiding the dialog."));
  170. ShowWindowAsync(pFindParam->hwndRNA,SW_HIDE);
  171. uRes = 0;
  172. break;
  173. }
  174. //
  175. // Wait for MAX_ZAPRNA_PAUSE milliseconds, or until event is signaled
  176. //
  177. dwWait = WaitForSingleObject(pParam->hEvent, MAX_ZAPRNA_PAUSE);
  178. //
  179. // If not a timeout, we're done
  180. //
  181. if (WAIT_TIMEOUT != dwWait)
  182. {
  183. //
  184. // If not an event signal, report
  185. //
  186. if (WAIT_OBJECT_0 != dwWait)
  187. {
  188. CMTRACE1(TEXT("fnZRCT() WAIT_OBJECT_0 != dwWait, GLE=%u."), GetLastError());
  189. }
  190. break;
  191. }
  192. }
  193. done:
  194. //
  195. // Cleanup
  196. //
  197. #ifdef DEBUG
  198. if (uRes)
  199. {
  200. CMTRACE(TEXT("fnZRCT() has exited without hiding the dialog."));
  201. }
  202. #endif
  203. CmFree(pParam->pszDun);
  204. CmFree(pParam);
  205. CmFree(pFindParam);
  206. CmFree(pszFmt);
  207. #ifdef DEBUG
  208. if (uRes)
  209. {
  210. CMTRACE(TEXT("fnZRCT() could not free all of its alloc-ed memory"));
  211. }
  212. #endif
  213. if (hLibrary)
  214. {
  215. bRes = FreeLibrary(hLibrary);
  216. }
  217. CMTRACE1(TEXT("fnZRCT() is exiting with uRes=%u."), uRes);
  218. return (uRes);
  219. }
  220. //+----------------------------------------------------------------------------
  221. //
  222. // Function: ZapRNAConnectedTo
  223. //
  224. // Synopsis: Fires off thread to hide the RNA "Connected To" dlg
  225. //
  226. // Arguments: LPCTSTR pszDUN - The name of the DUN entry that we are connecting
  227. // HANDLE hEvent - Handle to CM termination event
  228. //
  229. // Returns: HANDLE - Handle of created thread or NULL on failure
  230. //
  231. // History: nickball Created Header 3/5/98
  232. //
  233. //+----------------------------------------------------------------------------
  234. HANDLE ZapRNAConnectedTo(LPCTSTR pszDUN, HANDLE hEvent)
  235. {
  236. MYDBGASSERT(pszDUN);
  237. MYDBGASSERT(hEvent);
  238. PZRCTP pParam;
  239. unsigned long tidThread;
  240. HANDLE hThread = NULL;
  241. if (NULL == pszDUN || NULL == *pszDUN || NULL == hEvent)
  242. {
  243. return hThread;
  244. }
  245. pParam = (PZRCTP) CmMalloc(sizeof(ZRCTParam));
  246. if (!pParam)
  247. {
  248. CMTRACE1(TEXT("ZapRNAConnectedTo() CmMalloc() failed, GLE=%u."), GetLastError());
  249. return hThread;
  250. }
  251. pParam->pszDun = WzToSzWithAlloc(pszDUN);
  252. if (!pParam->pszDun)
  253. {
  254. CMTRACE1(TEXT("ZapRNAConnectedTo() CmMalloc() failed, GLE=%u."), GetLastError());
  255. return hThread;
  256. }
  257. //
  258. // Setup params to be passed to thread
  259. //
  260. pParam->hEvent = hEvent;
  261. //
  262. // Create the Zap thread
  263. //
  264. hThread = (HANDLE) CreateThread(NULL, 0, fnZRCT, pParam, 0, &tidThread);
  265. if (!hThread)
  266. {
  267. //
  268. // Couldn't create thread, free params
  269. //
  270. CMTRACE1(TEXT("ZapRNAConnectedTo() CreateThread() failed, GLE=%u."), GetLastError());
  271. CmFree(pParam);
  272. }
  273. //
  274. // Note: pParam is release inside thread
  275. //
  276. CMTRACE1(TEXT("fnZRCT() is exiting with hThread=%u."), hThread);
  277. return hThread;
  278. }