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.

383 lines
10 KiB

  1. /** Microsoft LAN Manager **/
  2. /** Copyright(c) Microsoft Corp., 1987-1990 **/
  3. /********************************************************************/
  4. /*
  5. * FILE STATUS:
  6. * 10/07/91 Created
  7. * 12/28/91 Changed WNetEnum type
  8. * 01/03/92 Capitalize the Resource_XXX manifest
  9. */
  10. /****************************************************************************
  11. PROGRAM: test10.cxx
  12. PURPOSE: Test module to test WNetOpenEnum, WNetResourceEnum,
  13. WNetCloseEnum
  14. FUNCTIONS:
  15. test10()
  16. COMMENTS:
  17. ****************************************************************************/
  18. #ifdef CODESPEC
  19. /*START CODESPEC*/
  20. /********
  21. TEST10.CXX
  22. ********/
  23. /************
  24. end TEST10.CXX
  25. ************/
  26. /*END CODESPEC*/
  27. #endif // CODESPEC
  28. #define INCL_NETSHARE
  29. #define INCL_NETSERVER
  30. #define INCL_NETUSE
  31. #include "apptest.hxx"
  32. #include "testa.h"
  33. #include <lmobj.hxx>
  34. #include <lmoshare.hxx>
  35. #include <lmoesh.hxx>
  36. #include <lmodev.hxx>
  37. #include <lmosrv.hxx>
  38. #include <lmoesrv.hxx>
  39. #define L3_NETRESOURCE_NUM 15
  40. extern "C"
  41. {
  42. #include <string.h>
  43. BOOL FAR PASCAL EnumWndProc(HWND,WORD,WORD,LONG);
  44. #ifdef WIN32
  45. VOID DoIt(HANDLE , HWND );
  46. VOID SetListbox( HWND );
  47. #endif
  48. }
  49. /* Provided for error returns
  50. */
  51. TCHAR achError[256], achProvider[256] ;
  52. #ifdef WIN32
  53. HWND hwndEnum;
  54. BOOL fShare = FALSE;
  55. VOID SetListbox( HWND hDlg )
  56. {
  57. HCURSOR hCursor = SetCursor( LoadCursor( NULL, IDC_WAIT));
  58. ShowCursor( TRUE );
  59. HWND hwndListbox = GetDlgItem( hDlg, ID_LISTBOX);
  60. HWND hwndGo = GetDlgItem( hDlg, ID_GO );
  61. SendMessage( hwndListbox, LB_RESETCONTENT, 0, 0 );
  62. if (fShare )
  63. {
  64. SetWindowText( hwndGo, SZ("CONNECTED"));
  65. }
  66. else
  67. {
  68. SetWindowText( hwndGo, SZ("GLOBALNET"));
  69. }
  70. HANDLE hEnum;
  71. DWORD err;
  72. if (fShare )
  73. err = WNetOpenEnum( RESOURCE_GLOBALNET, 0, 0, NULL, &hEnum );
  74. else
  75. err = WNetOpenEnum( RESOURCE_CONNECTED, 0, 0,NULL,&hEnum);
  76. if ( err != WN_SUCCESS)
  77. {
  78. TCHAR pszStr[100];
  79. wsprintf( pszStr, "Cannot open enum: error %d", err );
  80. if ( err != 2 )
  81. {
  82. wsprintf( pszStr, "Cannot open enum : error %d", err );
  83. }
  84. else
  85. {
  86. UINT uErr;
  87. WNetGetLastError( (DWORD*)&uErr, achError, sizeof(achError)/sizeof(TCHAR), achProvider, sizeof(achProvider)/sizeof(TCHAR) );
  88. wsprintf( pszStr, "Cannot open enum: error %d, Text: %s Provider: %s", uErr, achError, achProvider );
  89. }
  90. MessageBox( hDlg, pszStr, SZ("test"), MB_OK );
  91. return;
  92. }
  93. NETRESOURCE *pBuffer =(NETRESOURCE *) malloc(sizeof(NETRESOURCE) + 50 );
  94. DWORD Count = 1;
  95. DWORD dwBuffSize = sizeof( NETRESOURCE)+50 ;
  96. err = WNetEnumResource( hEnum, &Count, pBuffer, &dwBuffSize );
  97. if ( err != WN_NO_MORE_ENTRIES )
  98. {
  99. if ( err != WN_SUCCESS)
  100. {
  101. TCHAR pszStr[100];
  102. wsprintf( pszStr, "Cannot Enum resource: error %d", err );
  103. UIDEBUG(pszStr);
  104. UIDEBUG(SZ("\n\r"));
  105. SendMessage( hwndListbox, LB_ADDSTRING,0,(LONG)pszStr);
  106. }
  107. else
  108. {
  109. TCHAR pszStr[100];
  110. wsprintf( pszStr,"%s connect:%s Scope:%s Type:%s Usage:%s",
  111. pBuffer->lpRemoteName ,
  112. ( pBuffer->dwScope != RESOURCE_CONNECTED ) ? SZ("no"):
  113. (( pBuffer->lpLocalName == NULL )?SZ("<empty localname>"):
  114. pBuffer->lpLocalName),
  115. ( pBuffer->dwScope == RESOURCE_CONNECTED )?SZ("connected"):SZ("globalnet"),
  116. ( pBuffer->dwType == 0 )?SZ("disk and print"):
  117. ( pBuffer->dwType == RESOURCETYPE_DISK )?SZ("disk"):SZ("print"),
  118. ( pBuffer->dwUsage == 0 )?SZ("unknow"):
  119. (pBuffer->dwUsage == RESOURCEUSAGE_CONTAINER )?SZ("container"):
  120. SZ("connectable")
  121. );
  122. SendMessage( hwndListbox, LB_ADDSTRING, 0, (LONG)pszStr);
  123. if (fShare)
  124. {
  125. HANDLE hEnum2;
  126. DWORD err;
  127. err = WNetOpenEnum( RESOURCE_GLOBALNET, 0, RESOURCEUSAGE_CONTAINER, pBuffer,&hEnum2);
  128. if ( err != WN_SUCCESS)
  129. {
  130. TCHAR pszStr[100];
  131. wsprintf( pszStr, "Cannot open enum 2: error %d", err );
  132. MessageBox( hDlg, pszStr, SZ("test"), MB_OK );
  133. return;
  134. }
  135. NETRESOURCE *pBuffer2=(NETRESOURCE *)malloc(sizeof(NETRESOURCE)+50);
  136. for(INT cCount =0; cCount < 60; cCount ++)
  137. {
  138. DWORD Count = 1;
  139. DWORD dwBuffSize = sizeof(NETRESOURCE)+50 ;
  140. err=WNetEnumResource(hEnum2,&Count,pBuffer2,&dwBuffSize );
  141. if (( err == WN_NO_MORE_ENTRIES ) || (Count!=1))
  142. {
  143. break;
  144. }
  145. if ( err != WN_SUCCESS)
  146. {
  147. TCHAR pszStr[100];
  148. if ( err != 2 )
  149. {
  150. wsprintf( pszStr, "Cannot Enum resource 2: error %d", err );
  151. }
  152. else
  153. {
  154. UINT uErr;
  155. WNetGetLastError( (DWORD*)&uErr, achError, sizeof(achError)/sizeof(TCHAR), achProvider, sizeof(achProvider)/sizeof(TCHAR) );
  156. wsprintf( pszStr, "Cannot Enum resource 2: error %d, Text: %s Provider: %s", uErr, achError, achProvider );
  157. }
  158. UIDEBUG(pszStr);
  159. UIDEBUG(SZ("\n\r"));
  160. SendMessage(hwndListbox,LB_ADDSTRING,0,(LONG)pszStr);
  161. break;
  162. }
  163. TCHAR pszStr[100];
  164. wsprintf( pszStr," %s:%s connect:%s Scope:%s Type:%s Usage:%s",
  165. pBuffer->lpRemoteName,
  166. pBuffer2->lpRemoteName ,
  167. ( pBuffer2->dwScope != RESOURCE_CONNECTED ) ? SZ("no"):
  168. (( pBuffer2->lpLocalName == NULL )?SZ("<empty localname>"):
  169. pBuffer2->lpLocalName),
  170. ( pBuffer2->dwScope == RESOURCE_CONNECTED )?SZ("connected"):
  171. SZ("globalnet"),
  172. ( pBuffer2->dwType == 0 )?SZ("disk and print"):
  173. ( pBuffer2->dwType == RESOURCETYPE_DISK )?SZ("disk"):SZ("print"),
  174. ( pBuffer2->dwUsage == 0 )?SZ("unknow"):
  175. (pBuffer2->dwUsage == RESOURCEUSAGE_CONTAINER )?SZ("container"):
  176. SZ("connectable")
  177. );
  178. SendMessage( hwndListbox,LB_ADDSTRING, 0,
  179. (LONG)pszStr);
  180. if ( TRUE )
  181. /*
  182. if ((strcmp( pBuffer2->lpRemoteName, "\\\\ANDREWCO2") != 0 ) &&
  183. (strcmp( pBuffer2->lpRemoteName, "\\\\DAVEGOE") != 0 ) &&
  184. (strcmp( pBuffer2->lpRemoteName, "\\\\JOHNOW") != 0 ) &&
  185. (strcmp( pBuffer2->lpRemoteName, "\\\\TOMM3") != 0 ) &&
  186. (strcmp( pBuffer2->lpRemoteName, "\\\\DAVIDRO2") != 0 ) &&
  187. (strcmp( pBuffer2->lpRemoteName, "\\\\JUICYFRUIT") != 0 ) &&
  188. (strcmp( pBuffer2->lpRemoteName, "\\\\ROBERTRE4") != 0 ) &&
  189. (strcmp( pBuffer2->lpRemoteName, "\\\\STEVEWO_OS2") != 0 ))
  190. */
  191. {
  192. UIDEBUG(pBuffer2->lpRemoteName );
  193. UIDEBUG(SZ("\n\r"));
  194. HANDLE hEnum3;
  195. err = WNetOpenEnum( RESOURCE_GLOBALNET, 0, 0,pBuffer2,&hEnum3);
  196. if ( err != WN_SUCCESS)
  197. {
  198. TCHAR pszStr[100];
  199. wsprintf( pszStr, "Cannot open enum 3: error %d", err );
  200. MessageBox( hDlg, pszStr, SZ("test"), MB_OK );
  201. return;
  202. }
  203. NETRESOURCE *pBegin=(NETRESOURCE *)malloc(L3_NETRESOURCE_NUM*sizeof(NETRESOURCE)+50);
  204. NETRESOURCE *pBuffer3 = pBegin;
  205. for(;;)
  206. {
  207. DWORD Count = 1;
  208. DWORD dwBuffSize = L3_NETRESOURCE_NUM*sizeof(NETRESOURCE)+50 ;
  209. err=WNetEnumResource(hEnum3,&Count,pBuffer3, &dwBuffSize );
  210. if (( err == WN_NO_MORE_ENTRIES ) || (Count!=1))
  211. {
  212. break;
  213. }
  214. if ( err != WN_SUCCESS)
  215. {
  216. TCHAR pszStr[100];
  217. if ( err != 2 )
  218. {
  219. wsprintf( pszStr, "Cannot Enum resource 3: error %d", err );
  220. }
  221. else
  222. {
  223. UINT uErr;
  224. WNetGetLastError( (DWORD*)&uErr, achError, sizeof(achError)/sizeof(TCHAR), achProvider, sizeof(achProvider)/sizeof(TCHAR) );
  225. wsprintf( pszStr, "Cannot Enum resource 3: error %d, Text: %s Provider: %s", uErr, achError, achProvider );
  226. }
  227. UIDEBUG(pszStr);
  228. UIDEBUG(SZ("\n\r"));
  229. SendMessage(hwndListbox,LB_ADDSTRING,0,(LONG)pszStr);
  230. break;
  231. }
  232. for (DWORD i=0; i < Count; i++, pBuffer3++)
  233. {
  234. TCHAR pszStr[100];
  235. wsprintf( pszStr,
  236. " %s:%s:%s connect:%s Scope:%s Type:%s Usage:%s",
  237. pBuffer->lpRemoteName, pBuffer2->lpRemoteName ,
  238. pBuffer3->lpRemoteName,
  239. ( pBuffer3->dwScope != RESOURCE_CONNECTED ) ? SZ("no"):
  240. (( pBuffer3->lpLocalName == NULL )?SZ("<empty localname>"):
  241. pBuffer3->lpLocalName),
  242. ( pBuffer3->dwScope == RESOURCE_CONNECTED )?SZ("connected"):
  243. SZ("globalnet"),
  244. ( pBuffer3->dwType == 0 )?SZ("disk and print"):
  245. ( pBuffer3->dwType == RESOURCETYPE_DISK )?SZ("disk"):SZ("print"),
  246. ( pBuffer3->dwUsage == 0 )?SZ("unknow"):
  247. (pBuffer3->dwUsage == RESOURCEUSAGE_CONTAINER )?SZ("container"):
  248. SZ("connectable")
  249. );
  250. SendMessage( hwndListbox,LB_ADDSTRING, 0,
  251. (LONG)pszStr);
  252. }
  253. if ( err == WN_NO_MORE_ENTRIES )
  254. {
  255. break;
  256. }
  257. }
  258. err = WNetCloseEnum( hEnum3 );
  259. if ( err != WN_SUCCESS)
  260. {
  261. TCHAR pszStr[100];
  262. wsprintf( pszStr, "Cannot close enum 3: error %d", err );
  263. MessageBox( hDlg, pszStr, SZ("test"), MB_OK );
  264. }
  265. if (pBegin != NULL )
  266. free(pBegin);
  267. }
  268. }
  269. err = WNetCloseEnum( hEnum2 );
  270. if ( err != WN_SUCCESS)
  271. {
  272. TCHAR pszStr[100];
  273. wsprintf( pszStr, "Cannot close enum 2: error %d", err );
  274. MessageBox( hDlg, pszStr, SZ("test"), MB_OK );
  275. }
  276. free(pBuffer2);
  277. }
  278. }
  279. }
  280. err = WNetCloseEnum( hEnum );
  281. if ( err != WN_SUCCESS)
  282. {
  283. TCHAR pszStr[100];
  284. wsprintf( pszStr, "Cannot close enum: error %d", err );
  285. MessageBox( hDlg, pszStr, SZ("test"), MB_OK );
  286. return;
  287. }
  288. free(pBuffer);
  289. ShowCursor( FALSE );
  290. SetCursor( hCursor);
  291. return;
  292. }
  293. #endif
  294. BOOL EnumWndProc( HWND hDlg, WORD message, WORD wParam, LONG lParam )
  295. {
  296. #ifdef WIN32
  297. switch(message)
  298. {
  299. case WM_INITDIALOG:
  300. fShare = FALSE;
  301. SetListbox(hDlg );
  302. return TRUE;
  303. case WM_COMMAND:
  304. {
  305. switch(wParam)
  306. {
  307. case ID_GO:
  308. if ( fShare )
  309. {
  310. fShare = FALSE;
  311. SetListbox(hDlg );
  312. }
  313. else
  314. {
  315. fShare = TRUE;
  316. SetListbox(hDlg );
  317. }
  318. return TRUE;
  319. case ID_END:
  320. DestroyWindow(hDlg );
  321. return TRUE;
  322. }
  323. }
  324. }
  325. #endif
  326. return FALSE;
  327. }
  328. #ifdef WIN32
  329. VOID DoIt(HANDLE hInstance, HWND hwndParent )
  330. {
  331. hwndEnum = CreateDialog( hInstance, SZ("TEST_A"), hwndParent,
  332. (DLGPROC) MakeProcInstance((WNDPROC) EnumWndProc, hInstance));
  333. }
  334. /****************************************************************************
  335. FUNCTION: test10()
  336. PURPOSE: test WNetOpenEnum
  337. COMMENTS:
  338. ****************************************************************************/
  339. void test10(HANDLE hInstance, HWND hwndParent)
  340. {
  341. MessageBox(hwndParent,SZ("Welcome to sunny test10"),SZ("Test"),MB_OK);
  342. DoIt( hInstance, hwndParent );
  343. //MessageBox(hwndParent,"Thanks for visiting test10 -- please come again!","Test",MB_OK);
  344. }
  345. #endif