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.

131 lines
2.6 KiB

  1. //
  2. // Microsoft Windows Media Technologies
  3. // Copyright (C) Microsoft Corporation, 1999 - 2001. All rights reserved.
  4. //
  5. //
  6. // This workspace contains two projects -
  7. // 1. ProgHelp which implements the Progress Interface
  8. // 2. The Sample application WmdmApp.
  9. //
  10. // ProgHelp.dll needs to be registered first for the SampleApp to run.
  11. //
  12. // WMDM.cpp: implementation of the CWMDM class.
  13. //
  14. // Includes
  15. //
  16. #include "appPCH.h"
  17. #include "mswmdm_i.c"
  18. #include "sac.h"
  19. #include "SCClient.h"
  20. #include "key.c"
  21. //////////////////////////////////////////////////////////////////////
  22. //
  23. // Construction/Destruction
  24. //
  25. //////////////////////////////////////////////////////////////////////
  26. CWMDM::CWMDM()
  27. {
  28. HRESULT hr;
  29. IComponentAuthenticate *pAuth = NULL;
  30. // Initialize member variables
  31. //
  32. m_pSAC = NULL;
  33. m_pWMDevMgr = NULL;
  34. m_pEnumDevice = NULL;
  35. // Acquire the authentication interface of WMDM
  36. //
  37. hr = CoCreateInstance(
  38. CLSID_MediaDevMgr,
  39. NULL,
  40. CLSCTX_INPROC_SERVER,
  41. IID_IComponentAuthenticate,
  42. (void**)&pAuth
  43. );
  44. ExitOnFail( hr );
  45. // Create the client authentication object
  46. //
  47. m_pSAC = new CSecureChannelClient;
  48. ExitOnNull( m_pSAC );
  49. // Select the cert and the associated private key into the SAC
  50. //
  51. hr = m_pSAC->SetCertificate(
  52. SAC_CERT_V1,
  53. (BYTE *)abCert, sizeof(abCert),
  54. (BYTE *)abPVK, sizeof(abPVK)
  55. );
  56. ExitOnFail( hr );
  57. // Select the authentication interface into the SAC
  58. //
  59. m_pSAC->SetInterface( pAuth );
  60. // Authenticate with the V1 protocol
  61. //
  62. hr = m_pSAC->Authenticate( SAC_PROTOCOL_V1 );
  63. ExitOnFail( hr );
  64. // Authenticated succeeded, so we can use the WMDM functionality.
  65. // Acquire an interface to the top-level WMDM interface.
  66. //
  67. hr = pAuth->QueryInterface( IID_IWMDeviceManager, (void**)&m_pWMDevMgr );
  68. ExitOnFail( hr );
  69. // Get a pointer the the interface to use to enumerate devices
  70. //
  71. hr = m_pWMDevMgr->EnumDevices( &m_pEnumDevice );
  72. ExitOnFail( hr );
  73. hr = S_OK;
  74. lExit:
  75. m_hrInit = hr;
  76. }
  77. CWMDM::~CWMDM()
  78. {
  79. // Release the device enumeration interface
  80. //
  81. if( m_pEnumDevice )
  82. {
  83. m_pEnumDevice->Release();
  84. }
  85. // Release the top-level WMDM interface
  86. //
  87. if( m_pWMDevMgr )
  88. {
  89. m_pWMDevMgr->Release();
  90. }
  91. // Release the SAC
  92. //
  93. if( m_pSAC )
  94. {
  95. delete m_pSAC;
  96. }
  97. }
  98. //////////////////////////////////////////////////////////////////////
  99. //
  100. // Class methods
  101. //
  102. //////////////////////////////////////////////////////////////////////
  103. HRESULT CWMDM::Init( void )
  104. {
  105. return m_hrInit;
  106. }