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.

315 lines
8.2 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1993 **/
  4. /**********************************************************************/
  5. /*
  6. mprthred.cxx
  7. Second thread for network connection dialog.
  8. FILE HISTORY:
  9. YiHsinS 4-Mar-1993 Created
  10. */
  11. #define INCL_NETERRORS
  12. #define INCL_WINDOWS_GDI
  13. #define INCL_WINDOWS
  14. #define INCL_DOSERRORS
  15. #define INCL_NETLIB
  16. #define INCL_NETWKSTA
  17. #include <lmui.hxx>
  18. #define INCL_BLT_DIALOG
  19. #define INCL_BLT_CONTROL
  20. #include <blt.hxx>
  21. #include <strnumer.hxx> // HEX_STR
  22. #include <uitrace.hxx>
  23. #include <mprbrows.hxx>
  24. /*******************************************************************
  25. NAME: MPR_ENUM_THREAD::MPR_ENUM_THREAD
  26. SYNOPSIS: Constructor
  27. ENTRY:
  28. EXIT:
  29. RETURNS:
  30. NOTES:
  31. HISTORY:
  32. YiHsinS 4-Mar-1993 Created
  33. ********************************************************************/
  34. MPR_ENUM_THREAD::MPR_ENUM_THREAD( HWND hwndDlg,
  35. UINT uiType,
  36. LPNETRESOURCE pnetresProvider,
  37. const TCHAR *pszWkstaDomain )
  38. : WIN32_THREAD( TRUE, 0, SZ("mprui.dll") ),
  39. _hwndDlg( hwndDlg ),
  40. _uiType ( uiType ),
  41. _nlsWkstaDomain( pszWkstaDomain ),
  42. _eventExitThread( NULL, FALSE ),
  43. _fThreadIsTerminating( FALSE )
  44. {
  45. if ( QueryError() )
  46. return;
  47. APIERR err = NERR_Success;
  48. if ( ((err = _eventExitThread.QueryError()) != NERR_Success )
  49. || ((err = _nlsWkstaDomain.QueryError()) != NERR_Success )
  50. )
  51. {
  52. ReportError( err );
  53. return;
  54. }
  55. UIASSERT( pnetresProvider != NULL );
  56. _netresProvider.dwScope = pnetresProvider->dwScope;
  57. _netresProvider.dwType = pnetresProvider->dwType;
  58. _netresProvider.dwDisplayType = pnetresProvider->dwDisplayType;
  59. _netresProvider.dwUsage = pnetresProvider->dwUsage;
  60. _netresProvider.lpRemoteName = NULL;
  61. _netresProvider.lpLocalName = NULL;
  62. _netresProvider.lpProvider = NULL;
  63. _netresProvider.lpComment = NULL;
  64. /* Note that we do new(count of characters) because we are using
  65. * the transmutable type TCHAR.
  66. */
  67. if ( pnetresProvider->lpRemoteName != NULL )
  68. {
  69. if ( (_netresProvider.lpRemoteName = new TCHAR[ ::strlenf( pnetresProvider->lpRemoteName ) + 1]) != NULL)
  70. ::strcpyf( _netresProvider.lpRemoteName, pnetresProvider->lpRemoteName);
  71. else
  72. ReportError( ERROR_NOT_ENOUGH_MEMORY ) ;
  73. }
  74. if ( pnetresProvider->lpLocalName != NULL )
  75. {
  76. if ((_netresProvider.lpLocalName = new TCHAR[ ::strlenf( pnetresProvider->lpLocalName ) + 1]) != NULL)
  77. ::strcpyf( _netresProvider.lpLocalName, pnetresProvider->lpLocalName);
  78. else
  79. ReportError( ERROR_NOT_ENOUGH_MEMORY ) ;
  80. }
  81. if ( pnetresProvider->lpProvider != NULL )
  82. {
  83. if ((_netresProvider.lpProvider = new TCHAR[ ::strlenf( pnetresProvider->lpProvider ) + 1]) != NULL)
  84. ::strcpyf( _netresProvider.lpProvider, pnetresProvider->lpProvider);
  85. else
  86. ReportError( ERROR_NOT_ENOUGH_MEMORY ) ;
  87. }
  88. if ( pnetresProvider->lpComment != NULL )
  89. {
  90. if ((_netresProvider.lpComment = new TCHAR[ ::strlenf( pnetresProvider->lpComment ) + 1])!=NULL )
  91. ::strcpyf( _netresProvider.lpComment, pnetresProvider->lpComment);
  92. else
  93. ReportError( ERROR_NOT_ENOUGH_MEMORY ) ;
  94. }
  95. }
  96. /*******************************************************************
  97. NAME: MPR_ENUM_THREAD::~MPR_ENUM_THREAD
  98. SYNOPSIS: Destructor
  99. ENTRY:
  100. EXIT:
  101. RETURNS:
  102. NOTES:
  103. HISTORY:
  104. YiHsinS 4-Mar-1993 Created
  105. ********************************************************************/
  106. MPR_ENUM_THREAD::~MPR_ENUM_THREAD()
  107. {
  108. delete _netresProvider.lpRemoteName;
  109. delete _netresProvider.lpLocalName;
  110. delete _netresProvider.lpProvider;
  111. delete _netresProvider.lpComment;
  112. _netresProvider.lpRemoteName = NULL;
  113. _netresProvider.lpLocalName = NULL;
  114. _netresProvider.lpProvider = NULL;
  115. _netresProvider.lpComment = NULL;
  116. }
  117. /*******************************************************************
  118. NAME: MPR_ENUM_THREAD::Main()
  119. SYNOPSIS: Get the information needed to fill in the "Show" listbox
  120. with the requested data (providers, containers or
  121. connectable items)
  122. ENTRY:
  123. EXIT:
  124. RETURNS:
  125. NOTES:
  126. HISTORY:
  127. YiHsinS 4-Mar-1993 Created
  128. ********************************************************************/
  129. APIERR MPR_ENUM_THREAD::Main( VOID )
  130. {
  131. APIERR err = NERR_Success;
  132. MPR_LBI_CACHE *pmprlbicacheDomain = NULL;
  133. MPR_LBI_CACHE *pmprlbicacheServer = NULL;
  134. INT i = -1;
  135. if ( !_fThreadIsTerminating )
  136. {
  137. // The errors that happened in the following two EnumerateShow
  138. // will be ignored. The cache returned will be NULL if error
  139. // occurred so nothing needs to be added to the listbox.
  140. // Get the domains
  141. APIERR err1 = ::EnumerateShow(
  142. _hwndDlg,
  143. RESOURCE_GLOBALNET,
  144. _uiType,
  145. 0,
  146. &_netresProvider,
  147. NULL,
  148. NULL,
  149. FALSE,
  150. NULL,
  151. &pmprlbicacheDomain );
  152. if ( !_fThreadIsTerminating
  153. && ( err1 == NERR_Success )
  154. && ( _nlsWkstaDomain.QueryTextLength() != 0 )
  155. && ( (i = pmprlbicacheDomain->FindItem( _nlsWkstaDomain )) >= 0 )
  156. )
  157. {
  158. // Get the servers, ignore the error
  159. ::EnumerateShow(
  160. _hwndDlg,
  161. RESOURCE_GLOBALNET,
  162. _uiType,
  163. 0,
  164. ((pmprlbicacheDomain->QueryPtr())[i])->QueryLPNETRESOURCE(),
  165. NULL,
  166. NULL,
  167. FALSE,
  168. NULL,
  169. &pmprlbicacheServer );
  170. }
  171. }
  172. MPR_RETURN_CACHE p;
  173. p.pcacheDomain = pmprlbicacheDomain;
  174. p.pcacheServer = pmprlbicacheServer;
  175. if ( !_fThreadIsTerminating )
  176. {
  177. if ( err == NERR_Success )
  178. {
  179. ::SendMessage( _hwndDlg,
  180. WM_LB_FILLED,
  181. (WPARAM) FALSE, // No error!
  182. (LPARAM) &p );
  183. }
  184. else
  185. {
  186. ::SendMessage( _hwndDlg,
  187. WM_LB_FILLED,
  188. (WPARAM) TRUE, // Error occurred!
  189. (LPARAM) err );
  190. }
  191. }
  192. // The following cache will have already been freed if the
  193. // dialog got and processed the SendMessage above.
  194. if ( p.pcacheDomain != NULL )
  195. {
  196. (p.pcacheDomain)->DeleteAllItems();
  197. delete p.pcacheDomain;
  198. p.pcacheDomain = NULL;
  199. }
  200. if ( p.pcacheServer != NULL )
  201. {
  202. (p.pcacheServer)->DeleteAllItems();
  203. delete p.pcacheServer;
  204. p.pcacheServer = NULL;
  205. }
  206. switch ( ::WaitForSingleObject( _eventExitThread.QueryHandle(), INFINITE ))
  207. {
  208. // Time to exit the thread
  209. case WAIT_OBJECT_0:
  210. break;
  211. // These two should not have happened, not a mutex and wait infinite
  212. case WAIT_ABANDONED:
  213. case WAIT_TIMEOUT:
  214. UIASSERT( FALSE );
  215. break;
  216. default:
  217. err = ::GetLastError();
  218. break;
  219. }
  220. return err;
  221. } // MPR_ENUM_THREAD::Main
  222. /*******************************************************************
  223. NAME: MPR_ENUM_THREAD::PostMain()
  224. SYNOPSIS: Clean up
  225. ENTRY:
  226. EXIT:
  227. RETURNS:
  228. NOTES:
  229. HISTORY:
  230. YiHsinS 4-Mar-1993 Created
  231. ********************************************************************/
  232. APIERR MPR_ENUM_THREAD::PostMain( VOID )
  233. {
  234. TRACEEOL("MPR_ENUM_THREAD::PostMain - Deleting \"this\" for thread "
  235. << HEX_STR( (ULONG) QueryHandle() )) ;
  236. DeleteAndExit( NERR_Success ) ; // This method should never return
  237. UIASSERT( FALSE );
  238. return NERR_Success;
  239. } // MPR_ENUM_THREAD::PostMain