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.

1268 lines
34 KiB

  1. /*++
  2. Copyright (c) 1989-1993 Microsoft Corporation
  3. Module Name:
  4. to32.c
  5. Abstract:
  6. Provides entry points for the Functions from WFW3.1
  7. Network provider design which are niw thunked to some
  8. 32 bit equivalent.
  9. Author:
  10. Chuck Y Chan (ChuckC) 25-Mar-1993
  11. Revision History:
  12. --*/
  13. #include <windows.h>
  14. #include <locals.h>
  15. //
  16. // addresses to 32 bit entry points. note these cannot be
  17. // called directly. CallProc32W must be used,
  18. //
  19. LPVOID lpfnWNetAddConnection = NULL ;
  20. LPVOID lpfnWNetCancelConnection = NULL ;
  21. LPVOID lpfnWNetGetConnection = NULL ;
  22. LPVOID lpfnWNetRestoreConnection = NULL ;
  23. LPVOID lpfnWNetGetUser = NULL ;
  24. LPVOID lpfnWNetBrowseDialog = NULL ;
  25. LPVOID lpfnWNetConnectDialog = NULL ;
  26. LPVOID lpfnWNetDisconnectDialog = NULL ;
  27. LPVOID lpfnWNetConnectionDialog = NULL ;
  28. LPVOID lpfnWNetPropertyDialog = NULL ;
  29. LPVOID lpfnWNetGetPropertyText = NULL ;
  30. LPVOID lpfnWNetShareAsDialog = NULL ;
  31. LPVOID lpfnWNetStopShareDialog = NULL ;
  32. LPVOID lpfnWNetServerBrowseDialog = NULL ;
  33. LPVOID lpfnWNetGetDirectoryType = NULL ;
  34. LPVOID lpfnWNetDirectoryNotify = NULL ;
  35. LPVOID lpfnGetLastError32 = NULL ;
  36. LPVOID lpfnClosePrinter = NULL ;
  37. LPVOID lpfnConnectToPrinter = NULL ;
  38. //
  39. // forward declare
  40. //
  41. WORD Get32BitEntryPoints( LPVOID *lplpfn, DWORD dwDll, LPSTR lpProcName ) ;
  42. WORD API PrintConnectDialog(HWND p1) ;
  43. WORD GetAlignedMemory(LPVOID FAR *pAligned, HANDLE FAR *pHandle, WORD wSize) ;
  44. void FreeAlignedMemory(HANDLE handle) ;
  45. //
  46. // WNetAddConnection thunk to Win32
  47. //
  48. UINT API WNetAddConnection(LPSTR p1,LPSTR p2,LPSTR p3)
  49. {
  50. WORD err ;
  51. LPSTR aligned_p1 = NULL, aligned_p2 = NULL, aligned_p3 = NULL ;
  52. HANDLE handle_p1 = NULL, handle_p2 = NULL, handle_p3 = NULL;
  53. if (p1 == NULL || p3 == NULL)
  54. return WN_BAD_POINTER ;
  55. if (p2 && (*p2 == '\0'))
  56. p2 = NULL ;
  57. if (!lpfnWNetAddConnection)
  58. {
  59. //
  60. // start off as a our code until we get the entry point
  61. //
  62. vLastCall = LAST_CALL_IS_LOCAL ;
  63. //
  64. // get the entry point from 32 bit side
  65. //
  66. err = Get32BitEntryPoints( &lpfnWNetAddConnection,
  67. USE_MPR_DLL,
  68. "WNetAddConnectionA" ) ;
  69. if (err)
  70. {
  71. SetLastError(err) ;
  72. return err ;
  73. }
  74. }
  75. //
  76. // make copy of parameters so that we are aligned (p1 & p3 wont be NULL)
  77. //
  78. if (err = GetAlignedMemory(&aligned_p1, &handle_p1, lstrlen(p1)+1))
  79. goto ExitPoint ;
  80. lstrcpy(aligned_p1, p1) ;
  81. if (err = GetAlignedMemory(&aligned_p3, &handle_p3, lstrlen(p3)+1))
  82. goto ExitPoint ;
  83. lstrcpy(aligned_p3, p3) ;
  84. if (p2)
  85. {
  86. if (err = GetAlignedMemory(&aligned_p2, &handle_p2, lstrlen(p2)+1))
  87. goto ExitPoint ;
  88. lstrcpy(aligned_p2, p2) ;
  89. }
  90. //
  91. // note it is no longer an error in our code. and call the API
  92. //
  93. vLastCall = LAST_CALL_IS_WIN32 ;
  94. err = MapWin32ErrorToWN16( CallProc32W(aligned_p1,
  95. (DWORD)aligned_p2,
  96. (DWORD)aligned_p3,
  97. lpfnWNetAddConnection,
  98. (DWORD)7,
  99. (DWORD)3) ) ;
  100. ExitPoint:
  101. FreeAlignedMemory(handle_p1) ;
  102. FreeAlignedMemory(handle_p2) ;
  103. FreeAlignedMemory(handle_p3) ;
  104. return err ;
  105. }
  106. //
  107. // WNetCancelConnection thunk to Win32
  108. //
  109. UINT API WNetCancelConnection(LPSTR p1,BOOL p2)
  110. {
  111. WORD err ;
  112. LPSTR aligned_p1 = NULL ;
  113. HANDLE handle_p1 = NULL ;
  114. if (p1 == NULL)
  115. return WN_BAD_POINTER ;
  116. if (!lpfnWNetCancelConnection)
  117. {
  118. //
  119. // start off as a our code until we get the entry point
  120. //
  121. vLastCall = LAST_CALL_IS_LOCAL ;
  122. //
  123. // get the entry point from 32 bit side
  124. //
  125. err = Get32BitEntryPoints( &lpfnWNetCancelConnection,
  126. USE_MPR_DLL,
  127. "WNetCancelConnectionA" ) ;
  128. if (err)
  129. {
  130. SetLastError(err) ;
  131. return err ;
  132. }
  133. }
  134. //
  135. // make copy of parameters so that we are aligned
  136. //
  137. if (err = GetAlignedMemory(&aligned_p1, &handle_p1, lstrlen(p1)+1))
  138. goto ExitPoint ;
  139. lstrcpy(aligned_p1, p1) ;
  140. //
  141. // note it is no longer an error in our code. and call the API
  142. //
  143. vLastCall = LAST_CALL_IS_WIN32 ;
  144. err = MapWin32ErrorToWN16( CallProc32W(aligned_p1,
  145. (DWORD)p2,
  146. (DWORD)lpfnWNetCancelConnection,
  147. (DWORD)2,
  148. (DWORD)2) ) ;
  149. ExitPoint:
  150. FreeAlignedMemory(handle_p1) ;
  151. return err ;
  152. }
  153. //
  154. // WNetGetConnection thunk to Win32
  155. //
  156. UINT API WNetGetConnection(LPSTR p1,LPSTR p2, UINT FAR *p3)
  157. {
  158. WORD err ;
  159. LPSTR aligned_p1 = NULL, aligned_p2 = NULL ;
  160. LPDWORD aligned_p3 = NULL ;
  161. HANDLE handle_p1 = NULL, handle_p2 = NULL, handle_p3 = NULL;
  162. if (p1 == NULL || p2 == NULL || p3 == NULL)
  163. return WN_BAD_POINTER ;
  164. if (!lpfnWNetGetConnection)
  165. {
  166. //
  167. // start off as a our code until we get the entry point
  168. //
  169. vLastCall = LAST_CALL_IS_LOCAL ;
  170. //
  171. // get the entry point from 32 bit side
  172. //
  173. err = Get32BitEntryPoints( &lpfnWNetGetConnection,
  174. USE_MPR_DLL,
  175. "WNetGetConnectionA" ) ;
  176. if (err)
  177. {
  178. SetLastError(err) ;
  179. return err ;
  180. }
  181. }
  182. //
  183. // make copy of parameters so that we are aligned
  184. //
  185. if (err = GetAlignedMemory(&aligned_p1, &handle_p1, lstrlen(p1)+1))
  186. goto ExitPoint ;
  187. lstrcpy(aligned_p1, p1) ;
  188. if (err = GetAlignedMemory(&aligned_p2, &handle_p2, *p3 ? *p3 : 1))
  189. goto ExitPoint ;
  190. if (err = GetAlignedMemory(&aligned_p3, &handle_p3, sizeof(DWORD)))
  191. goto ExitPoint ;
  192. *aligned_p3 = *p3 ;
  193. //
  194. // note it is no longer an error in our code. and call the API
  195. //
  196. vLastCall = LAST_CALL_IS_WIN32 ;
  197. err = MapWin32ErrorToWN16( CallProc32W(aligned_p1,
  198. (DWORD)aligned_p2,
  199. (DWORD)aligned_p3,
  200. lpfnWNetGetConnection,
  201. (DWORD)7,
  202. (DWORD)3) ) ;
  203. lstrcpy(p2, aligned_p2) ;
  204. if (err == WN_SUCCESS)
  205. *p3 = lstrlen(p2) + 1;
  206. else
  207. *p3 = (UINT)*aligned_p3 ;
  208. ExitPoint:
  209. FreeAlignedMemory(handle_p1) ;
  210. FreeAlignedMemory(handle_p2) ;
  211. FreeAlignedMemory(handle_p3) ;
  212. return err ;
  213. }
  214. UINT API WNetRestoreConnection(HWND p1,LPSTR p2)
  215. {
  216. WORD err ;
  217. LPSTR aligned_p2 = NULL ;
  218. HANDLE handle_p2 = NULL ;
  219. if (p2 == NULL)
  220. return WN_BAD_POINTER ;
  221. if (!lpfnWNetRestoreConnection)
  222. {
  223. //
  224. // start off as a our code until we get the entry point
  225. //
  226. vLastCall = LAST_CALL_IS_LOCAL ;
  227. //
  228. // get the entry point from 32 bit side
  229. //
  230. err = Get32BitEntryPoints( &lpfnWNetRestoreConnection,
  231. USE_MPRUI_DLL,
  232. "WNetRestoreConnectionA" ) ;
  233. if (err)
  234. {
  235. SetLastError(err) ;
  236. return err ;
  237. }
  238. }
  239. //
  240. // guard against this weird case from Win3.0 days where -1
  241. // means something special. NULL is close approximation -> ie all.
  242. //
  243. if (p2 == (LPSTR)-1)
  244. p2 = NULL ;
  245. if (p2)
  246. {
  247. if (err = GetAlignedMemory(&aligned_p2, &handle_p2, lstrlen(p2)+1))
  248. goto ExitPoint ;
  249. lstrcpy(aligned_p2, p2) ;
  250. }
  251. //
  252. // note it is no longer an error in our code. and call the API
  253. //
  254. vLastCall = LAST_CALL_IS_WIN32 ;
  255. err = MapWin32ErrorToWN16( CallProc32W((LPVOID)TO_HWND32(p1),
  256. (DWORD)aligned_p2,
  257. (DWORD)lpfnWNetRestoreConnection,
  258. (DWORD)1,
  259. (DWORD)2) ) ;
  260. ExitPoint:
  261. FreeAlignedMemory(handle_p2) ;
  262. return err ;
  263. }
  264. WORD API WNetGetUser(LPSTR p1,LPINT p2)
  265. {
  266. WORD err ;
  267. LONG lTmp = *p2 ;
  268. LPSTR aligned_p1 = NULL ;
  269. LPINT aligned_p2 = NULL ;
  270. HANDLE handle_p1 = NULL, handle_p2 = NULL ;
  271. if (p1 == NULL || p2 == NULL)
  272. return WN_BAD_POINTER ;
  273. if (!lpfnWNetGetUser)
  274. {
  275. //
  276. // start off as a our code until we get the entry point
  277. //
  278. vLastCall = LAST_CALL_IS_LOCAL ;
  279. //
  280. // get the entry point from 32 bit side
  281. //
  282. err = Get32BitEntryPoints( &lpfnWNetGetUser,
  283. USE_MPR_DLL,
  284. "WNetGetUserA" ) ;
  285. if (err)
  286. {
  287. SetLastError(err) ;
  288. return err ;
  289. }
  290. }
  291. if (err = GetAlignedMemory(&aligned_p1, &handle_p1, *p2))
  292. goto ExitPoint ;
  293. if (err = GetAlignedMemory(&aligned_p2, &handle_p2, sizeof(DWORD)))
  294. goto ExitPoint ;
  295. *aligned_p2 = *p2 ;
  296. //
  297. // note it is no longer an error in our code. and call the API
  298. //
  299. vLastCall = LAST_CALL_IS_WIN32 ;
  300. err = MapWin32ErrorToWN16( CallProc32W(NULL,
  301. (DWORD)aligned_p1,
  302. (DWORD)aligned_p2,
  303. lpfnWNetGetUser,
  304. (DWORD)7,
  305. (DWORD)3) );
  306. *p2 = (int) *aligned_p2 ;
  307. lstrcpy(p1, aligned_p1) ;
  308. ExitPoint:
  309. FreeAlignedMemory(handle_p1) ;
  310. FreeAlignedMemory(handle_p2) ;
  311. return err ;
  312. }
  313. WORD API WNetBrowseDialog(HWND p1,WORD p2,LPSTR p3)
  314. {
  315. WORD err ;
  316. DWORD dwErr ;
  317. LPSTR aligned_p3 = NULL ;
  318. HANDLE handle_p3 = NULL ;
  319. if (p3 == NULL)
  320. return WN_BAD_POINTER ;
  321. if (!lpfnWNetBrowseDialog)
  322. {
  323. //
  324. // start off as a our code until we get the entry point
  325. //
  326. vLastCall = LAST_CALL_IS_LOCAL ;
  327. //
  328. // get the entry point from 32 bit side
  329. //
  330. err = Get32BitEntryPoints( &lpfnWNetBrowseDialog,
  331. USE_MPRUI_DLL,
  332. "BrowseDialogA0" ) ;
  333. if (err)
  334. {
  335. SetLastError(err) ;
  336. return err ;
  337. }
  338. }
  339. //
  340. // note that the WFW API does not let user specify buffer size.
  341. // we have a tmp buffer, and then copy over. this takes care
  342. // data alignment, also make sure we dont fault on 32 bit side.
  343. //
  344. // the 128 is consistent with what their docs specs the buffer
  345. // size should be.
  346. //
  347. if (err = GetAlignedMemory(&aligned_p3, &handle_p3, 128))
  348. goto ExitPoint ;
  349. //
  350. // note it is no longer an error in our code. and call the API
  351. //
  352. vLastCall = LAST_CALL_IS_WIN32 ;
  353. dwErr = CallProc32W((LPVOID)TO_HWND32(p1),
  354. (DWORD)MapWNType16To32(p2),
  355. (DWORD)aligned_p3,
  356. (DWORD)128,
  357. lpfnWNetBrowseDialog,
  358. (DWORD)2,
  359. (DWORD)4) ;
  360. if (dwErr == 0xFFFFFFFF)
  361. err = WN_CANCEL ;
  362. else
  363. err = MapWin32ErrorToWN16( dwErr ) ;
  364. if (!err)
  365. lstrcpy(p3,aligned_p3) ;
  366. ExitPoint:
  367. FreeAlignedMemory(handle_p3) ;
  368. return err ;
  369. }
  370. WORD API WNetConnectDialog(HWND p1,WORD p2)
  371. {
  372. WORD err ;
  373. DWORD dwErr ;
  374. if (p2 == WNTYPE_PRINTER)
  375. {
  376. err = PrintConnectDialog(p1) ;
  377. return err ;
  378. }
  379. if (!lpfnWNetConnectDialog)
  380. {
  381. //
  382. // start off as a our code until we get the entry point
  383. //
  384. vLastCall = LAST_CALL_IS_LOCAL ;
  385. //
  386. // get the entry point from 32 bit side
  387. //
  388. err = Get32BitEntryPoints( &lpfnWNetConnectDialog,
  389. USE_MPR_DLL,
  390. "WNetConnectionDialog" ) ;
  391. if (err)
  392. {
  393. SetLastError(err) ;
  394. return err ;
  395. }
  396. }
  397. //
  398. // note it is no longer an error in our code. and call the API
  399. //
  400. vLastCall = LAST_CALL_IS_WIN32 ;
  401. dwErr = CallProc32W( (LPVOID)TO_HWND32(p1),
  402. (DWORD)MapWNType16To32(p2),
  403. (DWORD)lpfnWNetConnectDialog,
  404. (DWORD) 0,
  405. (DWORD) 2 ) ;
  406. if (dwErr == 0xFFFFFFFF)
  407. err = WN_CANCEL ;
  408. else
  409. err = MapWin32ErrorToWN16( dwErr ) ;
  410. return err ;
  411. }
  412. WORD API WNetDisconnectDialog(HWND p1,WORD p2)
  413. {
  414. WORD err ;
  415. DWORD dwErr ;
  416. if (!lpfnWNetDisconnectDialog)
  417. {
  418. //
  419. // start off as a our code until we get the entry point
  420. //
  421. vLastCall = LAST_CALL_IS_LOCAL ;
  422. //
  423. // get the entry point from 32 bit side
  424. //
  425. err = Get32BitEntryPoints( &lpfnWNetDisconnectDialog,
  426. USE_MPR_DLL,
  427. "WNetDisconnectDialog" ) ;
  428. if (err)
  429. {
  430. SetLastError(err) ;
  431. return err ;
  432. }
  433. }
  434. //
  435. // note it is no longer an error in our code. and call the API
  436. //
  437. vLastCall = LAST_CALL_IS_WIN32 ;
  438. dwErr = CallProc32W( (LPVOID)TO_HWND32(p1),
  439. (DWORD)MapWNType16To32(p2),
  440. (DWORD)lpfnWNetDisconnectDialog,
  441. (DWORD) 0,
  442. (DWORD) 2 ) ;
  443. if (dwErr == 0xFFFFFFFF)
  444. err = WN_CANCEL ;
  445. else
  446. err = MapWin32ErrorToWN16( dwErr ) ;
  447. return err ;
  448. }
  449. WORD API WNetConnectionDialog(HWND p1,WORD p2)
  450. {
  451. return (WNetConnectDialog(p1,p2)) ;
  452. }
  453. WORD API PrintConnectDialog(HWND p1)
  454. {
  455. WORD err ;
  456. DWORD dwErr ;
  457. DWORD handle ;
  458. if (!lpfnClosePrinter)
  459. {
  460. //
  461. // start off as a our code until we get the entry point
  462. //
  463. vLastCall = LAST_CALL_IS_LOCAL ;
  464. //
  465. // get the entry point from 32 bit side
  466. //
  467. err = Get32BitEntryPoints( &lpfnClosePrinter,
  468. USE_WINSPOOL_DRV,
  469. "ClosePrinter" ) ;
  470. if (err)
  471. {
  472. SetLastError(err) ;
  473. return err ;
  474. }
  475. }
  476. if (!lpfnConnectToPrinter)
  477. {
  478. //
  479. // start off as a our code until we get the entry point
  480. //
  481. vLastCall = LAST_CALL_IS_LOCAL ;
  482. //
  483. // get the entry point from 32 bit side
  484. //
  485. err = Get32BitEntryPoints( &lpfnConnectToPrinter,
  486. USE_WINSPOOL_DRV,
  487. "ConnectToPrinterDlg" ) ;
  488. if (err)
  489. {
  490. SetLastError(err) ;
  491. return err ;
  492. }
  493. }
  494. //
  495. // note it is no longer an error in our code. and call the API
  496. //
  497. err = WN_SUCCESS ;
  498. vLastCall = LAST_CALL_IS_WIN32 ;
  499. handle = CallProc32W( (LPVOID)TO_HWND32(p1),
  500. (DWORD) 0,
  501. (DWORD)lpfnConnectToPrinter,
  502. (DWORD) 0,
  503. (DWORD) 2 ) ;
  504. if (handle == 0)
  505. err = WN_CANCEL ; // most likely reason
  506. else
  507. {
  508. dwErr = MapWin32ErrorToWN16( CallProc32W((LPVOID)handle,
  509. (DWORD)lpfnClosePrinter,
  510. (DWORD)0,
  511. (DWORD)1) );
  512. // but ignore the error
  513. }
  514. return err ;
  515. }
  516. WORD API WNetPropertyDialog(HWND hwndParent,
  517. WORD iButton,
  518. WORD nPropSel,
  519. LPSTR lpszName,
  520. WORD nType)
  521. {
  522. WORD err ;
  523. LPSTR aligned_name = NULL ;
  524. HANDLE handle_name = NULL ;
  525. if (!lpfnWNetPropertyDialog)
  526. {
  527. //
  528. // start off as a our code until we get the entry point
  529. //
  530. vLastCall = LAST_CALL_IS_LOCAL ;
  531. //
  532. // get the entry point from 32 bit side
  533. //
  534. err = Get32BitEntryPoints( &lpfnWNetPropertyDialog,
  535. USE_MPR_DLL,
  536. "WNetPropertyDialogA" ) ;
  537. if (err)
  538. {
  539. SetLastError(err) ;
  540. return err ;
  541. }
  542. }
  543. if (lpszName)
  544. {
  545. if (err = GetAlignedMemory(&aligned_name,
  546. &handle_name,
  547. lstrlen(lpszName)+1))
  548. goto ExitPoint ;
  549. lstrcpy(aligned_name, lpszName) ;
  550. }
  551. //
  552. // note it is no longer an error in our code. and call the API
  553. //
  554. vLastCall = LAST_CALL_IS_WIN32 ;
  555. err = MapWin32ErrorToWN16( CallProc32W( (LPVOID)TO_HWND32(hwndParent),
  556. (DWORD) iButton,
  557. (DWORD) nPropSel,
  558. (DWORD) aligned_name,
  559. (DWORD) nType,
  560. lpfnWNetPropertyDialog,
  561. (DWORD)2,
  562. (DWORD)5) ) ;
  563. ExitPoint:
  564. FreeAlignedMemory(handle_name) ;
  565. return err ;
  566. }
  567. WORD API WNetGetPropertyText(WORD iButton,
  568. WORD nPropSel,
  569. LPSTR lpszName,
  570. LPSTR lpszButtonName,
  571. WORD cbButtonName,
  572. WORD nType)
  573. {
  574. WORD err ;
  575. LPSTR aligned_name = NULL, aligned_button_name = NULL ;
  576. HANDLE handle_name = NULL, handle_button_name = NULL ;
  577. if (lpszButtonName == NULL)
  578. return WN_BAD_POINTER ;
  579. if (!lpfnWNetGetPropertyText)
  580. {
  581. //
  582. // start off as a our code until we get the entry point
  583. //
  584. vLastCall = LAST_CALL_IS_LOCAL ;
  585. //
  586. // get the entry point from 32 bit side
  587. //
  588. err = Get32BitEntryPoints( &lpfnWNetGetPropertyText,
  589. USE_MPR_DLL,
  590. "WNetGetPropertyTextA" ) ;
  591. if (err)
  592. {
  593. SetLastError(err) ;
  594. return err ;
  595. }
  596. }
  597. if (lpszName)
  598. {
  599. if (err = GetAlignedMemory(&aligned_name,
  600. &handle_name,
  601. lstrlen(lpszName)+1))
  602. goto ExitPoint ;
  603. lstrcpy(aligned_name, lpszName) ;
  604. }
  605. if (err = GetAlignedMemory(&aligned_button_name,
  606. &handle_button_name,
  607. cbButtonName))
  608. goto ExitPoint ;
  609. //
  610. // note it is no longer an error in our code. and call the API
  611. //
  612. vLastCall = LAST_CALL_IS_WIN32 ;
  613. err = MapWin32ErrorToWN16( CallProc32W( (LPVOID)iButton,
  614. (DWORD) nPropSel,
  615. (DWORD) aligned_name,
  616. (DWORD) aligned_button_name,
  617. (DWORD) cbButtonName,
  618. (DWORD) nType,
  619. lpfnWNetGetPropertyText,
  620. (DWORD)12,
  621. (DWORD)6) ) ;
  622. if (err == WN_SUCCESS)
  623. lstrcpy(lpszButtonName, aligned_button_name) ;
  624. ExitPoint:
  625. FreeAlignedMemory(handle_name) ;
  626. FreeAlignedMemory(handle_button_name) ;
  627. return err ;
  628. }
  629. WORD API WNetShareAsDialog(HWND hwndParent,
  630. WORD iType,
  631. LPSTR lpszPath)
  632. {
  633. WORD err ;
  634. LPSTR aligned_path = NULL ;
  635. HANDLE handle_path = NULL ;
  636. if (!lpfnWNetShareAsDialog)
  637. {
  638. //
  639. // start off as a our code until we get the entry point
  640. //
  641. vLastCall = LAST_CALL_IS_LOCAL ;
  642. //
  643. // get the entry point from 32 bit side
  644. //
  645. err = Get32BitEntryPoints( &lpfnWNetShareAsDialog,
  646. USE_NTLANMAN_DLL,
  647. "ShareAsDialogA0" ) ;
  648. if (err)
  649. {
  650. SetLastError(err) ;
  651. return err ;
  652. }
  653. }
  654. if (lpszPath)
  655. {
  656. if (err = GetAlignedMemory(&aligned_path,
  657. &handle_path,
  658. lstrlen(lpszPath)+1))
  659. goto ExitPoint ;
  660. lstrcpy(aligned_path, lpszPath) ;
  661. }
  662. //
  663. // note it is no longer an error in our code. and call the API
  664. //
  665. vLastCall = LAST_CALL_IS_WIN32 ;
  666. err = MapWin32ErrorToWN16( CallProc32W( (LPVOID)TO_HWND32(hwndParent),
  667. (DWORD) MapWNType16To32(iType),
  668. (DWORD) aligned_path,
  669. lpfnWNetShareAsDialog,
  670. (DWORD)1,
  671. (DWORD)3) ) ;
  672. ExitPoint:
  673. FreeAlignedMemory(handle_path) ;
  674. return err ;
  675. }
  676. WORD API WNetStopShareDialog(HWND hwndParent,
  677. WORD iType,
  678. LPSTR lpszPath)
  679. {
  680. WORD err ;
  681. LPSTR aligned_path = NULL ;
  682. HANDLE handle_path = NULL ;
  683. if (!lpfnWNetStopShareDialog)
  684. {
  685. //
  686. // start off as a our code until we get the entry point
  687. //
  688. vLastCall = LAST_CALL_IS_LOCAL ;
  689. //
  690. // get the entry point from 32 bit side
  691. //
  692. err = Get32BitEntryPoints( &lpfnWNetStopShareDialog,
  693. USE_NTLANMAN_DLL,
  694. "StopShareDialogA0" ) ;
  695. if (err)
  696. {
  697. SetLastError(err) ;
  698. return err ;
  699. }
  700. }
  701. if (lpszPath)
  702. {
  703. if (err = GetAlignedMemory(&aligned_path,
  704. &handle_path,
  705. lstrlen(lpszPath)+1))
  706. goto ExitPoint ;
  707. lstrcpy(aligned_path, lpszPath) ;
  708. }
  709. //
  710. // note it is no longer an error in our code. and call the API
  711. //
  712. vLastCall = LAST_CALL_IS_WIN32 ;
  713. err = MapWin32ErrorToWN16( CallProc32W( (LPVOID)TO_HWND32(hwndParent),
  714. (DWORD) MapWNType16To32(iType),
  715. (DWORD) aligned_path,
  716. lpfnWNetStopShareDialog,
  717. (DWORD)1,
  718. (DWORD)3) ) ;
  719. ExitPoint:
  720. FreeAlignedMemory(handle_path) ;
  721. return err ;
  722. }
  723. WORD API WNetServerBrowseDialog(HWND hwndParent,
  724. LPSTR lpszSectionName,
  725. LPSTR lpszBuffer,
  726. WORD cbBuffer,
  727. DWORD flFlags)
  728. {
  729. WORD err ;
  730. LPSTR aligned_buffer = NULL ;
  731. HANDLE handle_buffer = NULL ;
  732. UNREFERENCED(lpszSectionName) ;
  733. UNREFERENCED(flFlags) ;
  734. if (!lpfnWNetServerBrowseDialog)
  735. {
  736. //
  737. // start off as a our code until we get the entry point
  738. //
  739. vLastCall = LAST_CALL_IS_LOCAL ;
  740. //
  741. // get the entry point from 32 bit side
  742. //
  743. err = Get32BitEntryPoints( &lpfnWNetServerBrowseDialog,
  744. USE_NTLANMAN_DLL,
  745. "ServerBrowseDialogA0" ) ;
  746. if (err)
  747. {
  748. SetLastError(err) ;
  749. return err ;
  750. }
  751. }
  752. if (lpszBuffer)
  753. {
  754. if (err = GetAlignedMemory(&aligned_buffer, &handle_buffer, cbBuffer))
  755. goto ExitPoint ;
  756. }
  757. //
  758. // note it is no longer an error in our code. and call the API
  759. //
  760. vLastCall = LAST_CALL_IS_WIN32 ;
  761. err = MapWin32ErrorToWN16( CallProc32W( (LPVOID)TO_HWND32(hwndParent),
  762. (DWORD) aligned_buffer,
  763. (DWORD) cbBuffer,
  764. lpfnWNetServerBrowseDialog,
  765. (DWORD)2,
  766. (DWORD)3) ) ;
  767. if (err == WN_SUCCESS)
  768. lstrcpy(lpszBuffer, aligned_buffer) ;
  769. ExitPoint:
  770. FreeAlignedMemory(handle_buffer) ;
  771. return err ;
  772. }
  773. WORD API WNetGetDirectoryType(LPSTR p1,LPINT p2)
  774. {
  775. WORD err ;
  776. LPSTR aligned_p1 = NULL ;
  777. LPDWORD aligned_p2 = NULL ;
  778. HANDLE handle_p1 = NULL, handle_p2 = NULL ;
  779. if (p1 == NULL || p2 == NULL)
  780. return WN_BAD_POINTER ;
  781. if (!lpfnWNetGetDirectoryType)
  782. {
  783. //
  784. // start off as a our code until we get the entry point
  785. //
  786. vLastCall = LAST_CALL_IS_LOCAL ;
  787. //
  788. // get the entry point from 32 bit side
  789. //
  790. err = Get32BitEntryPoints( &lpfnWNetGetDirectoryType,
  791. USE_MPR_DLL,
  792. "WNetGetDirectoryTypeA" ) ;
  793. if (err)
  794. {
  795. SetLastError(err) ;
  796. return err ;
  797. }
  798. }
  799. if (err = GetAlignedMemory(&aligned_p1, &handle_p1, lstrlen(p1)+1))
  800. goto ExitPoint ;
  801. lstrcpy(aligned_p1, p1) ;
  802. if (err = GetAlignedMemory(&aligned_p2, &handle_p2, sizeof(DWORD)))
  803. goto ExitPoint ;
  804. //
  805. // note it is no longer an error in our code. and call the API
  806. //
  807. vLastCall = LAST_CALL_IS_WIN32 ;
  808. err = MapWin32ErrorToWN16( CallProc32W(aligned_p1,
  809. (DWORD)aligned_p2,
  810. (DWORD)TRUE,
  811. lpfnWNetGetDirectoryType,
  812. (DWORD)6,
  813. (DWORD)3) ) ;
  814. *p2 = (int) *aligned_p2 ;
  815. ExitPoint:
  816. FreeAlignedMemory(handle_p1) ;
  817. FreeAlignedMemory(handle_p2) ;
  818. return err ;
  819. }
  820. WORD API WNetDirectoryNotify(HWND p1,LPSTR p2,WORD p3)
  821. {
  822. UNREFERENCED(p1) ;
  823. UNREFERENCED(p2) ;
  824. UNREFERENCED(p3) ;
  825. return WN_SUCCESS ;
  826. }
  827. DWORD API GetLastError32(VOID)
  828. {
  829. WORD err ;
  830. DWORD dwErr ;
  831. if (!lpfnGetLastError32)
  832. {
  833. //
  834. // start off as a our code until we get the entry point
  835. //
  836. vLastCall = LAST_CALL_IS_LOCAL ;
  837. //
  838. // get the entry point from 32 bit side
  839. //
  840. err = Get32BitEntryPoints( &lpfnGetLastError32,
  841. USE_KERNEL32_DLL,
  842. "GetLastError" ) ;
  843. if (err)
  844. {
  845. SetLastError(err) ;
  846. return err ;
  847. }
  848. }
  849. //
  850. // note it is no longer an error in our code. and call the API
  851. //
  852. vLastCall = LAST_CALL_IS_WIN32 ;
  853. dwErr = (UINT) CallProc32W((LPVOID)lpfnGetLastError32,
  854. (DWORD)0,
  855. (DWORD)0) ;
  856. return (MapWin32ErrorToWN16(dwErr)) ;
  857. }
  858. /*
  859. * Misc support routines
  860. */
  861. /*******************************************************************
  862. NAME: Get32BitEntryPoints
  863. SYNOPSIS: Get the address of a 32 bit entry point that can
  864. then be passed to CallProv32W. Will load the library
  865. if it has not already been loaded.
  866. ENTRY: lplpfn - used to return the address
  867. dwDll - which dll to use (see locals.h defintions)
  868. lpProcName - proc to load
  869. EXIT:
  870. RETURNS: error code
  871. NOTES:
  872. HISTORY:
  873. ChuckC 25-Mar-93 Created
  874. ********************************************************************/
  875. WORD Get32BitEntryPoints( LPVOID *lplpfn, DWORD dwDll, LPSTR lpProcName )
  876. {
  877. static DWORD hmodKernel32 = NULL ;
  878. static DWORD hmodNTLanman = NULL ;
  879. static DWORD hmodMpr = NULL ;
  880. static DWORD hmodMprUI = NULL ;
  881. static DWORD hmodWinSpool = NULL ;
  882. DWORD hmod = NULL ;
  883. //
  884. // if we havent loaded it appropriate DLL, load it now
  885. //
  886. switch (dwDll)
  887. {
  888. case USE_MPR_DLL:
  889. if (hmodMpr == NULL)
  890. {
  891. hmodMpr = LoadLibraryEx32W(MPR_DLL, NULL, 0) ;
  892. if (hmodMpr == NULL)
  893. return WN_NOT_SUPPORTED ;
  894. }
  895. hmod = hmodMpr ;
  896. break ;
  897. case USE_MPRUI_DLL:
  898. if (hmodMprUI == NULL)
  899. {
  900. hmodMprUI = LoadLibraryEx32W(MPRUI_DLL, NULL, 0) ;
  901. if (hmodMprUI == NULL)
  902. return WN_NOT_SUPPORTED ;
  903. }
  904. hmod = hmodMprUI ;
  905. break ;
  906. case USE_NTLANMAN_DLL:
  907. if (hmodNTLanman == NULL)
  908. {
  909. hmodNTLanman = LoadLibraryEx32W(NTLANMAN_DLL, NULL, 0) ;
  910. if (hmodNTLanman == NULL)
  911. return WN_NOT_SUPPORTED ;
  912. }
  913. hmod = hmodNTLanman ;
  914. break ;
  915. case USE_KERNEL32_DLL:
  916. if (hmodKernel32 == NULL)
  917. {
  918. hmodKernel32 = LoadLibraryEx32W(KERNEL32_DLL, NULL, 0) ;
  919. if (hmodKernel32 == NULL)
  920. return WN_NOT_SUPPORTED ;
  921. }
  922. hmod = hmodKernel32 ;
  923. break ;
  924. case USE_WINSPOOL_DRV:
  925. if (hmodWinSpool == NULL)
  926. {
  927. hmodWinSpool = LoadLibraryEx32W(WINSPOOL_DRV, NULL, 0) ;
  928. if (hmodWinSpool == NULL)
  929. return WN_NOT_SUPPORTED ;
  930. }
  931. hmod = hmodWinSpool ;
  932. break ;
  933. default:
  934. return ERROR_GEN_FAILURE ;
  935. }
  936. //
  937. // get the procedure
  938. //
  939. *lplpfn = (LPVOID) GetProcAddress32W(hmod, lpProcName) ;
  940. if (! *lplpfn )
  941. return WN_NOT_SUPPORTED ;
  942. return WN_SUCCESS ;
  943. }
  944. /*******************************************************************
  945. NAME: MapWNType16To32
  946. SYNOPSIS: map the 16 WNet types for DISK/PRINT, etc
  947. to their 32 bit equivalents
  948. ENTRY: nType - 16 bit type
  949. EXIT:
  950. RETURNS: the 32 bit type
  951. NOTES:
  952. HISTORY:
  953. ChuckC 25-Mar-93 Created
  954. ********************************************************************/
  955. DWORD MapWNType16To32(WORD nType)
  956. {
  957. switch (nType)
  958. {
  959. case WNTYPE_DRIVE :
  960. case WNTYPE_FILE :
  961. return RESOURCETYPE_DISK ;
  962. case WNTYPE_PRINTER :
  963. return RESOURCETYPE_PRINT ;
  964. case WNTYPE_COMM :
  965. default :
  966. return RESOURCETYPE_ERROR ;
  967. }
  968. }
  969. /*******************************************************************
  970. NAME: MapWin32ErrorToWN16
  971. SYNOPSIS: maps a Win 32 error the old style WN_ 16 bit error.
  972. ENTRY: err - Win32 error
  973. EXIT:
  974. RETURNS: Win 16 error
  975. NOTES:
  976. HISTORY:
  977. ChuckC 25-Mar-93 Created
  978. ********************************************************************/
  979. WORD MapWin32ErrorToWN16(DWORD err)
  980. {
  981. switch (err)
  982. {
  983. case ERROR_NOT_SUPPORTED:
  984. return WN_NOT_SUPPORTED ;
  985. case WIN32_WN_CANCEL:
  986. return WN_CANCEL ;
  987. case WIN32_EXTENDED_ERROR :
  988. case ERROR_UNEXP_NET_ERR:
  989. return WN_NET_ERROR ;
  990. case ERROR_MORE_DATA:
  991. return WN_MORE_DATA ;
  992. case ERROR_INVALID_PARAMETER:
  993. return WN_BAD_VALUE ;
  994. case ERROR_INVALID_PASSWORD:
  995. return WN_BAD_PASSWORD ;
  996. case ERROR_ACCESS_DENIED:
  997. return WN_ACCESS_DENIED ;
  998. case ERROR_NETWORK_BUSY:
  999. return WN_FUNCTION_BUSY ;
  1000. case ERROR_NOT_ENOUGH_MEMORY:
  1001. return WN_OUT_OF_MEMORY ;
  1002. case ERROR_BAD_NET_NAME:
  1003. case ERROR_BAD_NETPATH:
  1004. return WN_BAD_NETNAME ;
  1005. case ERROR_INVALID_DRIVE:
  1006. return WN_BAD_LOCALNAME ;
  1007. case ERROR_ALREADY_ASSIGNED:
  1008. return WN_ALREADY_CONNECTED ;
  1009. case ERROR_GEN_FAILURE:
  1010. return WN_DEVICE_ERROR ;
  1011. case NERR_UseNotFound:
  1012. return WN_NOT_CONNECTED ;
  1013. default:
  1014. return ( (WORD) err ) ;
  1015. }
  1016. }
  1017. /*******************************************************************
  1018. NAME: GetAlignedMemory
  1019. SYNOPSIS: global alloc some mem to make sure we have DWORD
  1020. aligned data. non x86 platforms may need this.
  1021. ENTRY: pAligned : used to return pointer to aligned memory allocated
  1022. pHandle : used to return handle of aligned memory allocated
  1023. wSize : bytes required
  1024. EXIT:
  1025. RETURNS: WN_SUCCESS or WN_OUT_OF_MEMORY
  1026. NOTES:
  1027. HISTORY:
  1028. ChuckC 27-Feb-94 Created
  1029. ********************************************************************/
  1030. WORD GetAlignedMemory(LPVOID FAR *pAligned, HANDLE FAR *pHandle, WORD wSize)
  1031. {
  1032. *pAligned = NULL ;
  1033. *pHandle = NULL ;
  1034. if (!(*pHandle = GlobalAlloc(GMEM_ZEROINIT|GMEM_FIXED,wSize)))
  1035. {
  1036. return WN_OUT_OF_MEMORY ;
  1037. }
  1038. if (!(*pAligned = (LPVOID)GlobalLock(*pHandle)))
  1039. {
  1040. (void) GlobalFree(*pHandle) ;
  1041. *pHandle = NULL ;
  1042. return WN_OUT_OF_MEMORY ;
  1043. }
  1044. return WN_SUCCESS ;
  1045. }
  1046. /*******************************************************************
  1047. NAME: FreeAlignedMemory
  1048. SYNOPSIS: free global memory allocated by GetAlignedMemory.
  1049. ENTRY: Handle : handle of aligned memory to be freed
  1050. EXIT:
  1051. RETURNS: none
  1052. NOTES:
  1053. HISTORY:
  1054. ChuckC 27-Feb-94 Created
  1055. ********************************************************************/
  1056. void FreeAlignedMemory(HANDLE handle)
  1057. {
  1058. if (handle)
  1059. {
  1060. (void) GlobalUnlock(handle) ;
  1061. (void) GlobalFree(handle) ;
  1062. }
  1063. }
  1064.