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.

641 lines
15 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : Provider.cpp //
  3. // //
  4. // DESCRIPTION : Header file for the Provider snapin node class. //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Sep 29 1999 yossg Create //
  10. // Jan 31 2000 yossg add the functionality //
  11. // //
  12. // Copyright (C) 1999 - 2000 Microsoft Corporation All Rights Reserved //
  13. /////////////////////////////////////////////////////////////////////////////
  14. #include "StdAfx.h"
  15. #include "snapin.h"
  16. #include "Provider.h"
  17. #include "Providers.h"
  18. #include "ppFaxProviderGeneral.h"
  19. #include "oaidl.h"
  20. #include "Icons.h"
  21. #include "faxmmc.h"
  22. /////////////////////////////////////////////////////////////////////////////
  23. static const GUID CFaxProviderNodeGUID_NODETYPE = FAXSRV_DEVICE_PROVIDER_NODETYPE_GUID;
  24. const GUID* CFaxProviderNode::m_NODETYPE = &CFaxProviderNodeGUID_NODETYPE;
  25. const OLECHAR* CFaxProviderNode::m_SZNODETYPE = FAXSRV_DEVICE_PROVIDER_NODETYPE_GUID_STR;
  26. const CLSID* CFaxProviderNode::m_SNAPIN_CLASSID = &CLSID_Snapin;
  27. CLIPFORMAT CFaxProviderNode::m_CFFspGuid =
  28. (CLIPFORMAT)RegisterClipboardFormat(CF_MSFAXSRV_FSP_GUID);
  29. CLIPFORMAT CFaxProviderNode::m_CFServerName =
  30. (CLIPFORMAT)RegisterClipboardFormat(CF_MSFAXSRV_SERVER_NAME);
  31. /*
  32. - CFaxProviderNode::Init
  33. -
  34. * Purpose:
  35. * Init all members icon etc.
  36. *
  37. * Arguments:
  38. * [in] pProviderConfig - PFAX_DEVICE_PROVIDER_INFO
  39. *
  40. * Return:
  41. * OLE error code
  42. */
  43. HRESULT CFaxProviderNode::Init(PFAX_DEVICE_PROVIDER_INFO pProviderConfig)
  44. {
  45. DEBUG_FUNCTION_NAME( _T("CFaxProviderNode::Init"));
  46. HRESULT hRc = S_OK;
  47. ATLASSERT(pProviderConfig);
  48. hRc = InitMembers( pProviderConfig );
  49. if (FAILED(hRc))
  50. {
  51. DebugPrintEx(
  52. DEBUG_ERR,
  53. _T("Failed to InitMembers"));
  54. //NodeMsgBox done by called func.
  55. goto Exit;
  56. }
  57. ATLASSERT(SUCCEEDED(hRc));
  58. //
  59. // Icon
  60. //
  61. InitIcons();
  62. Exit:
  63. return hRc;
  64. }
  65. /*
  66. - CFaxProviderNode::InitIcons
  67. -
  68. * Purpose:
  69. * Private method that initiate icons
  70. * due to the status member state.
  71. *
  72. * Arguments:
  73. * No.
  74. *
  75. * Return:
  76. * No.
  77. */
  78. void CFaxProviderNode::InitIcons ()
  79. {
  80. DEBUG_FUNCTION_NAME( _T("CFaxProviderNode::InitIcons"));
  81. switch (m_enumStatus)
  82. {
  83. case FAX_PROVIDER_STATUS_SUCCESS:
  84. m_resultDataItem.nImage = IMAGE_FSP;
  85. break;
  86. case FAX_PROVIDER_STATUS_SERVER_ERROR:
  87. case FAX_PROVIDER_STATUS_BAD_GUID:
  88. case FAX_PROVIDER_STATUS_BAD_VERSION:
  89. case FAX_PROVIDER_STATUS_CANT_LOAD:
  90. case FAX_PROVIDER_STATUS_CANT_LINK:
  91. case FAX_PROVIDER_STATUS_CANT_INIT:
  92. m_resultDataItem.nImage = IMAGE_FSP_ERROR;
  93. break;
  94. default:
  95. ATLASSERT(0); // "this enumStatus is not supported "
  96. break; //currently 999
  97. } // endswitch (enumStatus)
  98. return;
  99. }
  100. /*
  101. - CFaxProviderNode::InitMembers
  102. -
  103. * Purpose:
  104. * Private method to initiate members
  105. * Must be called after init of m_pParentNode
  106. *
  107. * Arguments:
  108. * [in] pProviderConfig - PFAX_DEVICE_PROVIDER_INFO structure
  109. *
  110. * Return:
  111. * OLE error code
  112. */
  113. HRESULT CFaxProviderNode::InitMembers(PFAX_DEVICE_PROVIDER_INFO pProviderConfig)
  114. {
  115. DEBUG_FUNCTION_NAME( _T("CFaxProviderNode::InitMembers"));
  116. HRESULT hRc = S_OK;
  117. int iCount;
  118. UINT idsStatus;
  119. CComBSTR bstrChk;
  120. WCHAR lpwszBuff [4*FXS_DWORD_LEN+3/*points*/+1/*NULL*/];
  121. ATLASSERT(pProviderConfig);
  122. //
  123. // status
  124. //
  125. m_enumStatus = pProviderConfig->Status;
  126. //
  127. // status string
  128. //
  129. idsStatus = GetStatusIDS(m_enumStatus);
  130. if ( FXS_IDS_STATUS_ERROR == idsStatus)
  131. {
  132. DebugPrintEx(
  133. DEBUG_ERR,
  134. TEXT("Invalid Status value."));
  135. goto Error;
  136. }
  137. else
  138. {
  139. if (!m_bstrStatus.LoadString(idsStatus))
  140. {
  141. hRc = E_OUTOFMEMORY;
  142. DebugPrintEx(
  143. DEBUG_ERR,
  144. TEXT("Out of memory. Failed to load status string."));
  145. goto Error;
  146. }
  147. }
  148. //
  149. // Provider name
  150. //
  151. m_bstrProviderName = pProviderConfig->lpctstrFriendlyName;
  152. if ( !m_bstrProviderName )
  153. {
  154. hRc = E_OUTOFMEMORY;
  155. goto Error;
  156. }
  157. //
  158. // Provider GUID
  159. //
  160. m_bstrProviderGUID = pProviderConfig->lpctstrGUID;
  161. if (!m_bstrProviderGUID)
  162. {
  163. hRc = E_OUTOFMEMORY;
  164. goto Error;
  165. }
  166. //
  167. // Version
  168. //
  169. m_verProviderVersion = pProviderConfig->Version;
  170. //
  171. // Version string
  172. //
  173. //m_bstrVersion = L"5.0.813.0 (Chk)" or L"5.0.813.0"
  174. iCount = swprintf(
  175. lpwszBuff,
  176. L"%ld.%ld.%ld.%ld",
  177. m_verProviderVersion.wMajorVersion,
  178. m_verProviderVersion.wMinorVersion,
  179. m_verProviderVersion.wMajorBuildNumber,
  180. m_verProviderVersion.wMinorBuildNumber
  181. );
  182. if( iCount <= 0 )
  183. {
  184. DebugPrintEx(
  185. DEBUG_ERR,
  186. TEXT("Fail to read m_verProviderVersion."));
  187. goto Error;
  188. }
  189. m_bstrVersion = lpwszBuff;
  190. if (!m_bstrVersion)
  191. {
  192. DebugPrintEx(
  193. DEBUG_ERR,
  194. TEXT("Null memeber BSTR - m_bstrVersion."));
  195. goto Error;
  196. }
  197. if (m_verProviderVersion.dwFlags & FAX_VER_FLAG_CHECKED)
  198. {
  199. if (!bstrChk.LoadString(IDS_CHK))
  200. {
  201. hRc = E_OUTOFMEMORY;
  202. DebugPrintEx(
  203. DEBUG_ERR,
  204. TEXT("Out of memory. Failed to load string."));
  205. goto Error;
  206. }
  207. m_bstrVersion += bstrChk; //L" (Chk)";
  208. }
  209. //
  210. // Path
  211. //
  212. m_bstrImageName = pProviderConfig->lpctstrImageName;
  213. if ( !m_bstrImageName )
  214. {
  215. hRc = E_OUTOFMEMORY;
  216. goto Error;
  217. }
  218. ATLASSERT(S_OK == hRc);
  219. goto Exit;
  220. Error:
  221. ATLASSERT(S_OK != hRc);
  222. DebugPrintEx(
  223. DEBUG_ERR,
  224. _T("Failed to allocate string - out of memory"));
  225. ATLASSERT(NULL != m_pParentNode);
  226. if (NULL != m_pParentNode)
  227. {
  228. m_pParentNode->NodeMsgBox(IDS_MEMORY);
  229. }
  230. Exit:
  231. return (hRc);
  232. }
  233. /*
  234. - CFaxProviderNode::GetResultPaneColInfo
  235. -
  236. * Purpose:
  237. * Return the text for specific column
  238. * Called for each column in the result pane
  239. *
  240. * Arguments:
  241. * [in] nCol - column number
  242. *
  243. * Return:
  244. * String to be displayed in the specific column
  245. */
  246. LPOLESTR CFaxProviderNode::GetResultPaneColInfo(int nCol)
  247. {
  248. DEBUG_FUNCTION_NAME( _T("CFaxProviderNode::GetResultPaneColInfo"));
  249. HRESULT hRc = S_OK;
  250. switch (nCol)
  251. {
  252. case 0:
  253. //
  254. // Provider Name
  255. //
  256. if (!m_bstrProviderName)
  257. {
  258. DebugPrintEx(
  259. DEBUG_ERR,
  260. TEXT("Null memeber BSTR - m_bstrProviderName."));
  261. goto Error;
  262. }
  263. else
  264. {
  265. return (m_bstrProviderName);
  266. }
  267. case 1:
  268. //
  269. // Status
  270. //
  271. if (!m_bstrStatus)
  272. {
  273. DebugPrintEx(
  274. DEBUG_ERR,
  275. TEXT("Null memeber BSTR - m_bstrStatus."));
  276. goto Error;
  277. }
  278. else
  279. {
  280. return (m_bstrStatus);
  281. }
  282. case 2:
  283. //
  284. // Version
  285. //
  286. if (!m_bstrVersion)
  287. {
  288. DebugPrintEx(
  289. DEBUG_ERR,
  290. TEXT("Null memeber BSTR - m_bstrVersion."));
  291. goto Error;
  292. }
  293. else
  294. {
  295. return (m_bstrVersion);
  296. }
  297. case 3:
  298. //
  299. // Path
  300. //
  301. if (!m_bstrImageName)
  302. {
  303. DebugPrintEx(
  304. DEBUG_ERR,
  305. TEXT("Null memeber BSTR - m_bstrImageName."));
  306. goto Error;
  307. }
  308. else
  309. {
  310. return (m_bstrImageName);
  311. }
  312. default:
  313. ATLASSERT(0); // "this number of column is not supported "
  314. return(L"");
  315. } // endswitch (nCol)
  316. Error:
  317. return(L"???");
  318. }
  319. /*
  320. - CFaxProviderNode::CreatePropertyPages
  321. -
  322. * Purpose:
  323. * Called when creating a property page of the object
  324. *
  325. * Arguments:
  326. * [in] lpProvider - The property sheet
  327. * [in] handle - Handle for routing notification
  328. * [in] pUnk - Pointer to the data object
  329. * [in] type - CCT_* (SCOPE, RESULT, ...)
  330. *
  331. * Return:
  332. * OLE error code
  333. */
  334. HRESULT
  335. CFaxProviderNode::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  336. long handle,
  337. IUnknown *pUnk,
  338. DATA_OBJECT_TYPES type)
  339. {
  340. DEBUG_FUNCTION_NAME( _T("CFaxProviderNode::CreatePropertyPages"));
  341. HRESULT hRc = S_OK;
  342. HPROPSHEETPAGE hPage;
  343. CppFaxProvider * pPropPageProviderGeneral = NULL;
  344. ATLASSERT(lpProvider);
  345. ATLASSERT(type == CCT_RESULT || type == CCT_SCOPE);
  346. //
  347. // General tab
  348. //
  349. pPropPageProviderGeneral = new CppFaxProvider(
  350. handle,
  351. this,
  352. TRUE,
  353. _Module.GetResourceInstance());
  354. if (!pPropPageProviderGeneral)
  355. {
  356. hRc = E_OUTOFMEMORY;
  357. NodeMsgBox(IDS_MEMORY_FAIL_TO_OPEN_PP);
  358. goto Error;
  359. }
  360. hRc = pPropPageProviderGeneral->Init( m_bstrProviderName,
  361. m_bstrStatus,
  362. m_bstrVersion,
  363. m_bstrImageName);
  364. if (FAILED(hRc))
  365. {
  366. NodeMsgBox(IDS_MEMORY_FAIL_TO_OPEN_PP);
  367. goto Error;
  368. }
  369. hPage = pPropPageProviderGeneral->Create();
  370. if ((!hPage))
  371. {
  372. hRc = HRESULT_FROM_WIN32(GetLastError());
  373. DebugPrintEx(
  374. DEBUG_ERR,
  375. TEXT("Fail to Create() property page. (hRc: %08X)"),
  376. hRc);
  377. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  378. goto Error;
  379. }
  380. hRc = lpProvider->AddPage(hPage);
  381. if (FAILED(hRc))
  382. {
  383. DebugPrintEx(
  384. DEBUG_ERR,
  385. TEXT("Fail to add property page for General tab. (hRc: %08X)"),
  386. hRc);
  387. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  388. goto Error;
  389. }
  390. ATLASSERT(S_OK == hRc);
  391. goto Exit;
  392. Error:
  393. ATLASSERT(S_OK != hRc);
  394. if ( NULL != pPropPageProviderGeneral )
  395. {
  396. delete pPropPageProviderGeneral;
  397. pPropPageProviderGeneral = NULL;
  398. }
  399. Exit:
  400. return hRc;
  401. }
  402. /*
  403. - CFaxProviderNode::SetVerbs
  404. -
  405. * Purpose:
  406. * What verbs to enable/disable when this object is selected
  407. *
  408. * Arguments:
  409. * [in] pConsoleVerb - MMC ConsoleVerb interface
  410. *
  411. * Return:
  412. * OLE Error code
  413. */
  414. HRESULT CFaxProviderNode::SetVerbs(IConsoleVerb *pConsoleVerb)
  415. {
  416. HRESULT hRc = S_OK;
  417. //
  418. // Display verbs that we support:
  419. // 1. Properties
  420. //
  421. hRc = pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  422. //
  423. // We want the default verb to be Properties
  424. //
  425. hRc = pConsoleVerb->SetDefaultVerb(MMC_VERB_PROPERTIES);
  426. return hRc;
  427. }
  428. /*
  429. - CFaxProviderNode::GetStatusIDS
  430. -
  431. * Purpose:
  432. * Transslate Status to IDS.
  433. *
  434. * Arguments:
  435. *
  436. * [in] enumStatus - unsigned int with the menu IDM value
  437. *
  438. * Return:
  439. * IDS of related status message
  440. */
  441. UINT CFaxProviderNode::GetStatusIDS(FAX_ENUM_PROVIDER_STATUS enumStatus)
  442. {
  443. DEBUG_FUNCTION_NAME( _T("CFaxProviderNode::GetStatusIDS"));
  444. UINT uiIds;
  445. switch (enumStatus)
  446. {
  447. case FAX_PROVIDER_STATUS_SUCCESS:
  448. // Provider was successfully loaded
  449. uiIds = IDS_STATUS_PROVIDER_SUCCESS;
  450. break;
  451. case FAX_PROVIDER_STATUS_SERVER_ERROR:
  452. // An error occured on the server while loading FSP.
  453. uiIds = IDS_STATUS_PROVIDER_SERVER_ERROR;
  454. break;
  455. case FAX_PROVIDER_STATUS_BAD_GUID:
  456. // Provider's GUID is invalid
  457. uiIds = IDS_STATUS_PROVIDER_BAD_GUID;
  458. break;
  459. case FAX_PROVIDER_STATUS_BAD_VERSION:
  460. // Provider's API version is invalid
  461. uiIds = IDS_STATUS_PROVIDER_BAD_VERSION;
  462. break;
  463. case FAX_PROVIDER_STATUS_CANT_LOAD:
  464. // Can't load provider's DLL
  465. uiIds = IDS_STATUS_PROVIDER_CANT_LOAD;
  466. break;
  467. case FAX_PROVIDER_STATUS_CANT_LINK:
  468. // Can't find required exported function(s) in provider's DLL
  469. uiIds = IDS_STATUS_PROVIDER_CANT_LINK;
  470. break;
  471. case FAX_PROVIDER_STATUS_CANT_INIT:
  472. // Failed while initializing provider
  473. uiIds = IDS_STATUS_PROVIDER_CANT_INIT;
  474. break;
  475. default:
  476. ATLASSERT(0); // "this enumStatus is not supported "
  477. uiIds = FXS_IDS_STATUS_ERROR; //currently 999
  478. break;
  479. } // endswitch (enumStatus)
  480. return uiIds;
  481. }
  482. /*
  483. +
  484. + CFaxProviderNode::OnShowContextHelp
  485. *
  486. * Purpose:
  487. * Overrides CSnapinNode::OnShowContextHelp.
  488. *
  489. * Arguments:
  490. *
  491. * Return:
  492. - OLE error code
  493. -
  494. */
  495. HRESULT CFaxProviderNode::OnShowContextHelp(
  496. IDisplayHelp* pDisplayHelp, LPOLESTR helpFile)
  497. {
  498. return DisplayContextHelp(pDisplayHelp, helpFile, HLP_DEVICES);
  499. }
  500. /*
  501. +
  502. +
  503. *
  504. * CFaxDeviceNode::FillData
  505. *
  506. *
  507. * Override CSnapInItem::FillData for private cliboard formats
  508. *
  509. *
  510. * Parameters
  511. *
  512. * Return Values
  513. *
  514. -
  515. -
  516. */
  517. HRESULT CFaxProviderNode::FillData(CLIPFORMAT cf, LPSTREAM pStream)
  518. {
  519. DEBUG_FUNCTION_NAME( _T("CFaxProviderNode::FillData"));
  520. HRESULT hr = DV_E_CLIPFORMAT;
  521. ULONG uWritten;
  522. if (cf == m_CFFspGuid)
  523. {
  524. hr = pStream->Write((VOID *)(LPWSTR)m_bstrProviderGUID,
  525. sizeof(WCHAR)*(m_bstrProviderGUID.Length()+1),
  526. &uWritten);
  527. return hr;
  528. }
  529. if (cf == m_CFServerName)
  530. {
  531. ATLASSERT(GetRootNode());
  532. CComBSTR bstrServerName = ((CFaxServerNode *)GetRootNode())->GetServerName();
  533. if (!bstrServerName)
  534. {
  535. DebugPrintEx(DEBUG_ERR, TEXT("Out of memory. Failed to load string."));
  536. return E_OUTOFMEMORY;
  537. }
  538. hr = pStream->Write((VOID *)(LPWSTR)bstrServerName, sizeof(WCHAR)*(bstrServerName.Length()+1), &uWritten);
  539. return hr;
  540. }
  541. return CSnapInItemImpl<CFaxProviderNode>::FillData(cf, pStream);
  542. }