home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow / Players / JukeboxASF / keyprovider.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  2.6 KB  |  103 lines

  1. //------------------------------------------------------------------------------
  2. // File: KeyProvider.cpp
  3. //
  4. // Desc: DirectShow sample code - provides a class to unkey Windows Media
  5. //       for use with ASF, WMA, WMV media files.
  6. //
  7. // Copyright (c) 1999-2001 Microsoft Corporation.  All rights reserved.
  8. //------------------------------------------------------------------------------
  9.  
  10. #include "stdafx.h"
  11.  
  12. #include <streams.h>
  13. #include <atlbase.h>
  14. #include <atlimpl.cpp>
  15. #include <stdio.h>
  16.  
  17. #include <dshowasf.h>
  18. #include "keyprovider.h"
  19.  
  20.  
  21. //
  22. // Build warning to remind developers of the dependency on the 
  23. // Windows Media Format SDK libraries, which do not ship with
  24. // the DirectX SDK.
  25. //
  26. #pragma message("NOTE: To link and run this sample, you must install the Windows Media Format SDK.")
  27. #pragma message("After signing a license agreement with Microsoft, you will receive a")
  28. #pragma message("unique version of WMStub.LIB, which should be added to this VC++ project.")
  29. #pragma message("Without this library, you will receive linker errors for the following:")
  30. #pragma message("       WMCreateCertificate")
  31. #pragma message("You must also add WMVCore.LIB to the linker settings to resolve the following:")
  32. #pragma message("       WMCreateProfileManager")
  33.  
  34.  
  35. CKeyProvider::CKeyProvider() : m_cRef(0)
  36. {
  37. }
  38.  
  39. //////////////////////////////////////////////////////////////////////////
  40. //
  41. // IUnknown methods
  42. //
  43. //////////////////////////////////////////////////////////////////////////
  44.  
  45. ULONG CKeyProvider::AddRef()
  46. {
  47.     return ++m_cRef;
  48. }
  49.  
  50. ULONG CKeyProvider::Release()
  51. {
  52.     ASSERT(m_cRef > 0);
  53.  
  54.     m_cRef--;
  55.  
  56.     if(m_cRef == 0)
  57.     {
  58.         delete this;
  59.  
  60.         // don't return m_cRef, because the object doesn't exist anymore
  61.         return((ULONG) 0);
  62.     }
  63.  
  64.     return(m_cRef);
  65. }
  66.  
  67. //
  68. // QueryInterface
  69. //
  70. // We only support IUnknown and IServiceProvider
  71. //
  72. HRESULT CKeyProvider::QueryInterface(REFIID riid, void ** ppv)
  73. {
  74.     if(riid == IID_IServiceProvider || riid == IID_IUnknown)
  75.     {
  76.         *ppv = (void *) static_cast<IServiceProvider *>(this);
  77.         AddRef();
  78.         return NOERROR;
  79.     }
  80.  
  81.     return E_NOINTERFACE;
  82. }
  83.  
  84. STDMETHODIMP CKeyProvider::QueryService(REFIID siid, REFIID riid, void **ppv)
  85. {
  86.     if(siid == __uuidof(IWMReader) && riid == IID_IUnknown)
  87.     {
  88.         IUnknown *punkCert;
  89.  
  90.         HRESULT hr = WMCreateCertificate(&punkCert);
  91.  
  92.         if(SUCCEEDED(hr))
  93.             *ppv = (void *) punkCert;
  94.         else
  95.             printf("CKeyProvider::QueryService failed to create certificate!  hr=0x%x\n", hr);
  96.     
  97.         return hr;
  98.     }
  99.  
  100.     return E_NOINTERFACE;
  101. }
  102.  
  103.