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.

397 lines
11 KiB

  1. #include "stdafx.h"
  2. #include "FaxMMCUtils.h"
  3. #include <faxres.h>
  4. /*
  5. - GetFaxServerErrorMsg
  6. -
  7. * Purpose:
  8. * Translate Error Code to IDS.
  9. *
  10. * Arguments:
  11. * dwEc - error code DWORD
  12. *
  13. * Return:
  14. * integer represents the IDS of error message
  15. * for this ec.
  16. *
  17. */
  18. int GetFaxServerErrorMsg(DWORD dwEc)
  19. {
  20. DEBUG_FUNCTION_NAME( _T("GetFaxServerErrorMsg"));
  21. int iIDS = IDS_GENERAL_FAILURE;
  22. if (IsNetworkError(dwEc))
  23. {
  24. iIDS = IDS_NETWORK_PROBLEMS;
  25. }
  26. else
  27. {
  28. switch (dwEc)
  29. {
  30. case ERROR_NOT_ENOUGH_MEMORY:
  31. iIDS = IDS_MEMORY;
  32. break;
  33. case ERROR_INVALID_PARAMETER:
  34. iIDS = IDS_INVALID_PARAMETER;
  35. break;
  36. case ERROR_ACCESS_DENIED:
  37. iIDS = IDS_ACCESS_DENIED;
  38. break;
  39. case ERROR_INVALID_HANDLE:
  40. //
  41. // ERROR_INVALID_HANDLE should not been
  42. // retreived except of FaxOpenPort while
  43. // handle sharing corruption was occoured.
  44. // This case treated without calling this
  45. // function.
  46. //
  47. ATLASSERT(FALSE);
  48. //
  49. // iIDS stays IDS_GENERAL_FAILURE due to
  50. // the fact that we are not going report
  51. // to the user on an invalid handle issue.
  52. // This peace of code here should not been reached
  53. // ever and this is the reason to the assert.
  54. //
  55. break;
  56. case ERROR_BAD_UNIT:
  57. iIDS = IDS_CANNOT_FIND_DEVICE;
  58. break;
  59. case ERROR_DIRECTORY: // The directory name is invalid.
  60. iIDS = IDS_ERROR_DIRECTORY;
  61. break;
  62. case ERROR_BAD_PATHNAME:
  63. iIDS = IDS_ERROR_BAD_PATHNAME;
  64. break;
  65. case ERROR_EAS_NOT_SUPPORTED:
  66. iIDS = IDS_ERROR_EAS_NOT_SUPPORTED;
  67. break;
  68. case ERROR_REGISTRY_CORRUPT:
  69. iIDS = IDS_ERROR_REGISTRY_CORRUPT;
  70. break;
  71. case ERROR_PATH_NOT_FOUND:
  72. iIDS = IDS_ERROR_PATH_NOT_FOUND;
  73. break;
  74. case FAX_ERR_DIRECTORY_IN_USE:
  75. iIDS = IDS_FAX_ERR_DIRECTORY_IN_USE;
  76. break;
  77. case FAX_ERR_RULE_NOT_FOUND:
  78. iIDS = IDS_FAX_ERR_RULE_NOT_FOUND;
  79. break;
  80. case FAX_ERR_BAD_GROUP_CONFIGURATION:
  81. iIDS = IDS_FAX_ERR_BAD_GROUP_CONFIGURATION;
  82. break;
  83. case FAX_ERR_GROUP_NOT_FOUND:
  84. iIDS = IDS_FAX_ERR_GROUP_NOT_FOUND;
  85. break;
  86. case FAX_ERR_SRV_OUTOFMEMORY:
  87. iIDS = IDS_FAX_ERR_SRV_OUTOFMEMORY;
  88. break;
  89. case FAXUI_ERROR_INVALID_CSID:
  90. iIDS = IDS_FAX_ERR_INVALID_CSID;
  91. break;
  92. case FAXUI_ERROR_INVALID_TSID:
  93. iIDS = IDS_FAX_ERR_INVALID_TSID;
  94. break;
  95. default:
  96. break;
  97. }
  98. }
  99. return iIDS;
  100. }
  101. /*
  102. - IsNetworkError
  103. -
  104. * Purpose:
  105. * Verify if Error Code represents a network error.
  106. *
  107. * Arguments:
  108. * dwEc - error code DWORD
  109. *
  110. * Return:
  111. * Boolean TRUE if the dwEc represents a
  112. * network error, and FALSE if not.
  113. *
  114. */
  115. BOOL IsNetworkError(DWORD dwEc)
  116. {
  117. DEBUG_FUNCTION_NAME( _T("IsNetworkError"));
  118. BOOL bIsNetworkError = FALSE;
  119. //Initialized to avoid an option to future mistakes
  120. switch (dwEc)
  121. {
  122. case RPC_S_INVALID_BINDING:
  123. bIsNetworkError = TRUE;
  124. break;
  125. case EPT_S_CANT_PERFORM_OP:
  126. bIsNetworkError = TRUE;
  127. break;
  128. case RPC_S_ADDRESS_ERROR:
  129. bIsNetworkError = TRUE;
  130. break;
  131. case RPC_S_CALL_CANCELLED:
  132. bIsNetworkError = TRUE;
  133. break;
  134. case RPC_S_CALL_FAILED:
  135. bIsNetworkError = TRUE;
  136. break;
  137. case RPC_S_CALL_FAILED_DNE:
  138. bIsNetworkError = TRUE;
  139. break;
  140. case RPC_S_COMM_FAILURE:
  141. bIsNetworkError = TRUE;
  142. break;
  143. case RPC_S_NO_BINDINGS:
  144. bIsNetworkError = TRUE;
  145. break;
  146. case RPC_S_SERVER_TOO_BUSY:
  147. bIsNetworkError = TRUE;
  148. break;
  149. case RPC_S_SERVER_UNAVAILABLE:
  150. bIsNetworkError = TRUE;
  151. break;
  152. default:
  153. bIsNetworkError = FALSE;
  154. break;
  155. }
  156. return (bIsNetworkError);
  157. }
  158. /*
  159. - Routine Description:
  160. -
  161. * Invokes the browse dialog
  162. *
  163. * Arguments:
  164. *
  165. * lpszBrowseItem [in/out] folder path
  166. * dwMaxPath [in] max length of lpszBrowseItem
  167. * lpszBrowseDlgTitle [in] browse dialog title
  168. * ulBrowseFlags [in] browse dialog flags
  169. * pParentWin [in] parent window
  170. *
  171. * Return Value:
  172. *
  173. * TRUE if successful, FALSE if the user presses Cancel
  174. */
  175. BOOL
  176. InvokeBrowseDialog( LPTSTR lpszBrowseItem,
  177. DWORD dwMaxPath,
  178. LPCTSTR lpszBrowseDlgTitle,
  179. unsigned long ulBrowseFlags,
  180. CWindow* pParentWin)
  181. {
  182. DEBUG_FUNCTION_NAME( _T("InvokeBrowseDialog"));
  183. BOOL fResult = FALSE;
  184. BROWSEINFO bi;
  185. LPITEMIDLIST pidl;
  186. LPMALLOC pMalloc;
  187. VOID SHFree(LPVOID);
  188. ATLASSERT( pParentWin != NULL);
  189. //
  190. // Preparing the BROWSEINFO structure.
  191. //
  192. bi.hwndOwner = (HWND)(*pParentWin); //Parents hWndDlg
  193. bi.pidlRoot = NULL;
  194. bi.pszDisplayName = lpszBrowseItem;
  195. bi.lpszTitle = lpszBrowseDlgTitle;
  196. bi.ulFlags = ulBrowseFlags;
  197. bi.lpfn = BrowseCallbackProc;
  198. bi.lParam = (LPARAM) (lpszBrowseItem);
  199. bi.iImage = 0;
  200. //
  201. // Memory check
  202. //
  203. if (FAILED(SHGetMalloc(&pMalloc)))
  204. {
  205. DlgMsgBox(pParentWin, IDS_MEMORY);
  206. return fResult;
  207. }
  208. //
  209. // Calling to the BrowseForFolder dialog
  210. //
  211. if(pidl = SHBrowseForFolder(&bi)) //pidl != NULL
  212. {
  213. TCHAR szPath[MAX_PATH+1] = {0};
  214. //
  215. // Retrieving the New Path
  216. //
  217. if(SHGetPathFromIDList(pidl, szPath))
  218. {
  219. if(wcslen(szPath) >= dwMaxPath)
  220. {
  221. DlgMsgBox(pParentWin, IDS_ERR_DIR_TOO_LONG, MB_OK | MB_ICONERROR);
  222. }
  223. else
  224. {
  225. DebugPrintEx(DEBUG_MSG, _T("Succeeded to Retrieve the path from browse dialog."));
  226. _tcsncpy(lpszBrowseItem, szPath, dwMaxPath);
  227. // Now the path was retreived successfully to
  228. // the back parameter lpszBrowseItem
  229. // and this is the only case in which the calling
  230. // function gets TRUE as return value.
  231. fResult = TRUE;
  232. }
  233. }
  234. //
  235. // Free using shell allocator
  236. //
  237. pMalloc->Free(pidl);
  238. pMalloc->Release();
  239. }
  240. return fResult;
  241. }
  242. /*++
  243. Routine Description:
  244. Callback function for the folder browser
  245. Arguments:
  246. hwnd : Handle to the browse dialog box. The callback function can
  247. send the following messages to this window:
  248. BFFM_ENABLEOK Enables the OK button if the wParam parameter
  249. is nonzero or disables it if wParam is zero.
  250. BFFM_SETSELECTION Selects the specified folder. The lParam
  251. parameter is the PIDL of the folder to select
  252. if wParam is FALSE, or it is the path of the
  253. folder otherwise.
  254. BFFM_SETSTATUSTEXT Sets the status text to the null-terminated
  255. string specified by the lParam parameter.
  256. uMsg : Value identifying the event. This parameter can be one of the
  257. following values:
  258. 0 Initialize dir path. lParam is the path.
  259. BFFM_INITIALIZED The browse dialog box has finished
  260. initializing. lpData is NULL.
  261. BFFM_SELCHANGED The selection has changed. lpData
  262. is a pointer to the item identifier list for
  263. the newly selected folder.
  264. lParam : Message-specific value. For more information, see the
  265. description of uMsg.
  266. lpData : Application-defined value that was specified in the lParam
  267. member of the BROWSEINFO structure.
  268. Return Value:
  269. 0 (1)
  270. --*/
  271. int CALLBACK BrowseCallbackProc(
  272. HWND hWnd,
  273. UINT uMsg,
  274. LPARAM lParam,
  275. LPARAM lpData)
  276. {
  277. int iRet = 0;
  278. switch(uMsg)
  279. {
  280. case BFFM_INITIALIZED:
  281. // LParam is TRUE since you are passing a path.
  282. // It would be FALSE if you were passing a pidl.
  283. // the lpData points to the folder path.
  284. // It must contain a path.
  285. // ASSERT(lpData && _T('\0') != *((LPTSTR)lpData));
  286. SendMessage(hWnd, BFFM_SETSELECTION, (WPARAM)TRUE, lpData);
  287. break;
  288. case BFFM_SELCHANGED:
  289. {
  290. BOOL bFolderIsOK = FALSE;
  291. TCHAR szPath [MAX_PATH + 1] = {0};
  292. if (SHGetPathFromIDList ((LPITEMIDLIST) lParam, szPath))
  293. {
  294. DWORD dwFileAttr = GetFileAttributes(szPath);
  295. ::SendMessage(hWnd, BFFM_SETSTATUSTEXT, TRUE, (LPARAM)szPath);
  296. if (-1 != dwFileAttr && (dwFileAttr & FILE_ATTRIBUTE_DIRECTORY))
  297. {
  298. //
  299. // The directory exists - enable the 'Ok' button
  300. //
  301. bFolderIsOK = TRUE;
  302. }
  303. }
  304. //
  305. // Enable / disable the 'ok' button
  306. //
  307. ::SendMessage(hWnd, BFFM_ENABLEOK , 0, (LPARAM)bFolderIsOK);
  308. break;
  309. }
  310. break;
  311. case BFFM_VALIDATEFAILED:
  312. break;
  313. default:
  314. ATLTRACE2(atlTraceWindowing, 0, _T("Unknown message received in CFolderDialogImpl::BrowseCallbackProc\n"));
  315. break;
  316. }
  317. return iRet;
  318. }