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.

304 lines
7.0 KiB

  1. #include "stdafx.h"
  2. #include "RoutingMethodProp.h"
  3. #include "RoutingMethodConfig.h"
  4. #include <faxutil.h>
  5. #include <fxsapip.h>
  6. #include <faxreg.h>
  7. #include <faxres.h>
  8. #include <faxuiconstants.h>
  9. #include "Util.h"
  10. DWORD
  11. WriteExtData(
  12. HANDLE hFax,
  13. DWORD dwDeviceId,
  14. LPCWSTR lpcwstrGUID,
  15. LPBYTE lpData,
  16. DWORD dwDataSize,
  17. UINT uTitleId,
  18. HWND hWnd
  19. )
  20. {
  21. DEBUG_FUNCTION_NAME(TEXT("WriteExtData"));
  22. DWORD ec = ERROR_SUCCESS;
  23. if (!FaxSetExtensionData (
  24. hFax, // Connection handle
  25. dwDeviceId, // Global extension data
  26. lpcwstrGUID, // Data GUID
  27. lpData, // Buffer
  28. dwDataSize // Buffer size
  29. ))
  30. {
  31. ec = GetLastError();
  32. DebugPrintEx(
  33. DEBUG_ERR,
  34. TEXT("FaxSetExtensionData() failed for GUID = %s (ec: %ld)"),
  35. lpcwstrGUID,
  36. ec);
  37. DisplayRpcErrorMessage(ec, uTitleId, hWnd);
  38. }
  39. return ec;
  40. } // WriteExtDWORDData
  41. DWORD
  42. ReadExtStringData(
  43. HANDLE hFax,
  44. DWORD dwDeviceId,
  45. LPCWSTR lpcwstrGUID,
  46. CComBSTR &bstrResult,
  47. LPCWSTR lpcwstrDefault,
  48. UINT uTitleId,
  49. HWND hWnd
  50. )
  51. {
  52. DEBUG_FUNCTION_NAME(TEXT("ReadExtStringData"));
  53. DWORD dwDataSize = 0;
  54. DWORD ec = ERROR_SUCCESS;
  55. LPBYTE lpExtData = NULL;
  56. if (!FaxGetExtensionData (
  57. hFax, // Connection handle
  58. dwDeviceId, // Global extension data
  59. lpcwstrGUID, // Data GUID
  60. (PVOID *)&lpExtData, // Buffer
  61. &dwDataSize // Buffer size
  62. ))
  63. {
  64. ec = GetLastError();
  65. lpExtData = NULL;
  66. if (ERROR_FILE_NOT_FOUND == ec)
  67. {
  68. //
  69. // Try to read default values from unassociated data
  70. //
  71. ec = ERROR_SUCCESS;
  72. if (!FaxGetExtensionData (
  73. hFax, // Connection handle
  74. 0, // unassociated extension data
  75. lpcwstrGUID, // Data GUID
  76. (PVOID *)&lpExtData, // Buffer
  77. &dwDataSize // Buffer size
  78. ))
  79. {
  80. ec = GetLastError();
  81. if (ERROR_FILE_NOT_FOUND == ec)
  82. {
  83. DebugPrintEx(
  84. DEBUG_WRN,
  85. TEXT("ROUTINGEXT Data not found for GUID: %s. Using default value (%s)"),
  86. lpcwstrGUID,
  87. lpcwstrDefault);
  88. ec = ERROR_SUCCESS;
  89. bstrResult = lpcwstrDefault;
  90. goto exit;
  91. }
  92. }
  93. }
  94. if (ERROR_SUCCESS != ec &&
  95. ERROR_FILE_NOT_FOUND != ec)
  96. {
  97. DebugPrintEx(
  98. DEBUG_ERR,
  99. TEXT("ROUTINGEXT FaxGetExtensionData() failed for GUID = %s (ec: %ld)"),
  100. lpcwstrGUID,
  101. ec);
  102. DisplayRpcErrorMessage(ec, uTitleId, hWnd);
  103. goto exit;
  104. }
  105. }
  106. bstrResult = (LPCWSTR)lpExtData;
  107. exit:
  108. FaxFreeBuffer(lpExtData);
  109. return ec;
  110. } // ReadExtStringData
  111. HRESULT
  112. GetDWORDFromDataObject(
  113. IDataObject * lpDataObject,
  114. CLIPFORMAT uFormat,
  115. LPDWORD lpdwValue
  116. )
  117. {
  118. DEBUG_FUNCTION_NAME(TEXT("GetDWORDFromDataObject"));
  119. Assert(lpdwValue);
  120. Assert(0 != uFormat);
  121. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  122. FORMATETC formatetc =
  123. {
  124. uFormat,
  125. NULL,
  126. DVASPECT_CONTENT,
  127. -1,
  128. TYMED_HGLOBAL
  129. };
  130. stgmedium.hGlobal = GlobalAlloc(0, sizeof(DWORD));
  131. if (stgmedium.hGlobal == NULL)
  132. {
  133. DebugPrintEx(
  134. DEBUG_ERR,
  135. TEXT("GlobalAlloc() failed. (ec: %ld)"),
  136. GetLastError());
  137. return E_OUTOFMEMORY;
  138. }
  139. HRESULT hr = lpDataObject->GetDataHere(&formatetc, &stgmedium);
  140. if (SUCCEEDED(hr))
  141. {
  142. *lpdwValue = *((LPDWORD)stgmedium.hGlobal);
  143. }
  144. else
  145. {
  146. DebugPrintEx(
  147. DEBUG_ERR,
  148. TEXT("GetDataHere() failed. (hr = 0x%08X)"),
  149. hr);
  150. }
  151. GlobalFree(stgmedium.hGlobal);
  152. return hr;
  153. } // GetDWORDFromDataObject
  154. HRESULT
  155. GetStringFromDataObject(
  156. IDataObject * lpDataObject,
  157. CLIPFORMAT uFormat,
  158. LPWSTR lpwstrBuf,
  159. DWORD dwBufLen
  160. )
  161. {
  162. DEBUG_FUNCTION_NAME(TEXT("GetStringFromDataObject"));
  163. Assert(lpDataObject);
  164. Assert(lpwstrBuf);
  165. Assert(dwBufLen>0);
  166. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  167. FORMATETC formatetc =
  168. {
  169. uFormat,
  170. NULL,
  171. DVASPECT_CONTENT,
  172. -1,
  173. TYMED_HGLOBAL
  174. };
  175. stgmedium.hGlobal = GlobalAlloc(0, dwBufLen*sizeof(WCHAR));
  176. if (stgmedium.hGlobal == NULL)
  177. {
  178. DebugPrintEx(
  179. DEBUG_ERR,
  180. TEXT("GlobalAlloc() failed. (ec: %ld)"),
  181. GetLastError());
  182. return E_OUTOFMEMORY;
  183. }
  184. HRESULT hr = lpDataObject->GetDataHere(&formatetc, &stgmedium);
  185. if (SUCCEEDED(hr))
  186. {
  187. lstrcpyn(lpwstrBuf,(LPWSTR)stgmedium.hGlobal,dwBufLen);
  188. lpwstrBuf[dwBufLen-1]=L'\0';
  189. }
  190. else
  191. {
  192. DebugPrintEx(
  193. DEBUG_ERR,
  194. TEXT("GetDataHere() failed. (hr = 0x%08X)"),
  195. hr);
  196. }
  197. GlobalFree(stgmedium.hGlobal);
  198. return hr;
  199. } // GetStringFromDataObject
  200. void
  201. DisplayRpcErrorMessage(
  202. DWORD ec,
  203. UINT uTitleId,
  204. HWND hWnd
  205. )
  206. {
  207. UINT uMsgId;
  208. uMsgId = GetErrorStringId(ec);
  209. DisplayErrorMessage(uTitleId, uMsgId, TRUE, hWnd); // use the common error messages DLL
  210. } // DisplayRpcErrorMessage
  211. void
  212. DisplayErrorMessage(
  213. UINT uTitleId,
  214. UINT uMsgId,
  215. BOOL bCommon,
  216. HWND hWnd
  217. )
  218. {
  219. static CComBSTR bstrCaption = TEXT("");
  220. CComBSTR bstrMsg;
  221. if (!lstrcmp(bstrCaption.m_str,TEXT("")))
  222. {
  223. bstrCaption.LoadString(uTitleId);
  224. if (!bstrCaption)
  225. {
  226. bstrCaption = TEXT("");
  227. return;
  228. }
  229. }
  230. if (bCommon)
  231. {
  232. bstrMsg.LoadString(_Module.GetResourceInstance(),uMsgId);
  233. }
  234. else
  235. {
  236. bstrMsg.LoadString(uMsgId);
  237. }
  238. if (bstrMsg)
  239. {
  240. AlignedMessageBox(hWnd, bstrMsg, bstrCaption, MB_OK | MB_ICONEXCLAMATION);
  241. }
  242. } // DisplayErrorMessage
  243. DWORD
  244. WinContextHelp(
  245. ULONG_PTR dwHelpId,
  246. HWND hWnd
  247. )
  248. /*++
  249. Routine name : WinContextHelp
  250. Routine description:
  251. Open context sensetive help popup 'tooltip' with WinHelp
  252. Arguments:
  253. dwHelpId [in] - help ID
  254. hWnd [in] - parent window handler
  255. Return Value:
  256. None.
  257. --*/
  258. {
  259. DWORD dwRes = ERROR_SUCCESS;
  260. if (0 == dwHelpId)
  261. {
  262. return dwRes;
  263. }
  264. WinHelp(hWnd,
  265. FXS_ADMIN_HLP_FILE,
  266. HELP_CONTEXTPOPUP,
  267. dwHelpId);
  268. return dwRes;
  269. }