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.

180 lines
4.3 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. UnsolicitedRC.cpp
  5. Abstract:
  6. SAFRemoteDesktopConnection Object
  7. Revision History:
  8. Kalyani Narlanka (kalyanin) 09/29/'00
  9. Created
  10. ********************************************************************/
  11. // SAFRemoteDesktopConnection.cpp : Implementation of CSAFRemoteDesktopConnection
  12. #include "stdafx.h"
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CSAFRemoteDesktopConnection
  15. /////////////////////////////////////////////////////////////////////////////
  16. // construction / destruction
  17. // **************************************************************************
  18. CSAFRemoteDesktopConnection::CSAFRemoteDesktopConnection()
  19. {
  20. }
  21. // **************************************************************************
  22. CSAFRemoteDesktopConnection::~CSAFRemoteDesktopConnection()
  23. {
  24. Cleanup();
  25. }
  26. // **************************************************************************
  27. void CSAFRemoteDesktopConnection::Cleanup(void)
  28. {
  29. }
  30. static HRESULT Error(UINT nID, const REFIID riid, HRESULT hRes)
  31. {
  32. __MPC_FUNC_ENTRY( COMMONID, "CSAFRemoteDesktopConnection::ConnectRemoteDesktop" );
  33. CComPtr<ICreateErrorInfo> pCrErrInfo = 0;
  34. CComPtr<IErrorInfo> pErrorInfo;
  35. HRESULT hr;
  36. CComBSTR bstrDescription;
  37. //Step1 initialize the error
  38. __MPC_EXIT_IF_METHOD_FAILS(hr, CreateErrorInfo(&pCrErrInfo));
  39. __MPC_EXIT_IF_METHOD_FAILS(hr, pCrErrInfo->SetGUID(riid));
  40. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::LocalizeString( IDS_NOPOLICY, bstrDescription, /*fMUI*/true ));
  41. __MPC_EXIT_IF_METHOD_FAILS(hr, pCrErrInfo->SetDescription(bstrDescription));
  42. //Step2 throw the error
  43. __MPC_EXIT_IF_METHOD_FAILS(hr, pCrErrInfo->QueryInterface(IID_IErrorInfo, (void**)&pErrorInfo));
  44. __MPC_EXIT_IF_METHOD_FAILS(hr, SetErrorInfo(0, pErrorInfo));
  45. hr = hRes;
  46. __MPC_FUNC_CLEANUP;
  47. if(pCrErrInfo)
  48. {
  49. pCrErrInfo.Release();
  50. }
  51. if(pErrorInfo)
  52. {
  53. pErrorInfo.Release();
  54. }
  55. __MPC_FUNC_EXIT(hr);
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CSAFRemoteDesktopConnection properties
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CSAFRemoteDesktopConnection Methods
  61. STDMETHODIMP CSAFRemoteDesktopConnection::InterfaceSupportsErrorInfo(REFIID riid)
  62. {
  63. static const IID* arr[] =
  64. {
  65. &IID_ISAFRemoteDesktopConnection
  66. };
  67. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  68. {
  69. if (InlineIsEqualGUID(*arr[i],riid))
  70. return S_OK;
  71. }
  72. return S_FALSE;
  73. }
  74. STDMETHODIMP CSAFRemoteDesktopConnection::ConnectRemoteDesktop( /*[in]*/ BSTR bstrServerName, /*[out]*/ ISAFRemoteConnectionData* *ppRCD )
  75. {
  76. __MPC_FUNC_ENTRY( COMMONID, "CSAFRemoteDesktopConnection::ConnectRemoteDesktop" );
  77. HRESULT hr;
  78. CComPtr<CSAFRemoteConnectionData> pRCD;
  79. DWORD dwSessions;
  80. __MPC_PARAMCHECK_BEGIN(hr)
  81. __MPC_PARAMCHECK_POINTER_AND_SET(ppRCD,NULL);
  82. __MPC_PARAMCHECK_END();
  83. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pRCD ));
  84. // Invoke the GetUserSessionInfo to populate the Users and Sessions information.
  85. hr = pRCD->InitUserSessionsInfo( bstrServerName );
  86. if(hr == HRESULT_FROM_WIN32( ERROR_ACCESS_DISABLED_BY_POLICY ))
  87. {
  88. // Populate the error description.
  89. // This Error() method sets up the IErrorInfo interface to provide error information to the client.
  90. // To call the Error method, the object must implement the ISupportErrorInfo interface.
  91. __MPC_EXIT_IF_METHOD_FAILS(hr, Error(IDS_NOPOLICY,IID_ISAFRemoteDesktopConnection,hr));
  92. }
  93. else
  94. {
  95. if(FAILED(hr))
  96. {
  97. // return the hr
  98. __MPC_EXIT_IF_METHOD_FAILS(hr, hr);
  99. }
  100. }
  101. // Return the RemoteConnectionData Interface to the caller
  102. __MPC_EXIT_IF_METHOD_FAILS(hr, pRCD.QueryInterface( ppRCD ));
  103. hr = S_OK;
  104. __MPC_FUNC_CLEANUP;
  105. __MPC_FUNC_EXIT(hr);
  106. }