home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow / Players / PlayWndASF / keyprovider.cpp next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  2.6 KB  |  102 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.  
  11. #include <streams.h>
  12. #include <atlbase.h>
  13. #include <atlimpl.cpp>
  14. #include <stdio.h>
  15.  
  16. #include <dshowasf.h>
  17. #include "keyprovider.h"
  18.  
  19.  
  20. //
  21. // Build warning to remind developers of the dependency on the 
  22. // Windows Media Format SDK libraries, which do not ship with
  23. // the DirectX SDK.
  24. //
  25. #pragma message("NOTE: To link and run this sample, you must install the Windows Media Format SDK.")
  26. #pragma message("After signing a license agreement with Microsoft, you will receive a")
  27. #pragma message("unique version of WMStub.LIB, which should be added to this VC++ project.")
  28. #pragma message("Without this library, you will receive linker errors for the following:")
  29. #pragma message("       WMCreateCertificate")
  30. #pragma message("You must also add WMVCore.LIB to the linker settings to resolve the following:")
  31. #pragma message("       WMCreateProfileManager")
  32.  
  33.  
  34. CKeyProvider::CKeyProvider() : m_cRef(0)
  35. {
  36. }
  37.  
  38. //////////////////////////////////////////////////////////////////////////
  39. //
  40. // IUnknown methods
  41. //
  42. //////////////////////////////////////////////////////////////////////////
  43.  
  44. ULONG CKeyProvider::AddRef()
  45. {
  46.     return ++m_cRef;
  47. }
  48.  
  49. ULONG CKeyProvider::Release()
  50. {
  51.     ASSERT(m_cRef > 0);
  52.  
  53.     m_cRef--;
  54.  
  55.     if(m_cRef == 0)
  56.     {
  57.         delete this;
  58.  
  59.         // don't return m_cRef, because the object doesn't exist anymore
  60.         return((ULONG) 0);
  61.     }
  62.  
  63.     return(m_cRef);
  64. }
  65.  
  66. //
  67. // QueryInterface
  68. //
  69. // We only support IUnknown and IServiceProvider
  70. //
  71. HRESULT CKeyProvider::QueryInterface(REFIID riid, void ** ppv)
  72. {
  73.     if(riid == IID_IServiceProvider || riid == IID_IUnknown)
  74.     {
  75.         *ppv = (void *) static_cast<IServiceProvider *>(this);
  76.         AddRef();
  77.         return NOERROR;
  78.     }
  79.  
  80.     return E_NOINTERFACE;
  81. }
  82.  
  83. STDMETHODIMP CKeyProvider::QueryService(REFIID siid, REFIID riid, void **ppv)
  84. {
  85.     if(siid == __uuidof(IWMReader) && riid == IID_IUnknown)
  86.     {
  87.         IUnknown *punkCert;
  88.  
  89.         HRESULT hr = WMCreateCertificate(&punkCert);
  90.  
  91.         if(SUCCEEDED(hr))
  92.             *ppv = (void *) punkCert;
  93.         else
  94.             printf("CKeyProvider::QueryService failed to create certificate!  hr=0x%x\n", hr);
  95.     
  96.         return hr;
  97.     }
  98.  
  99.     return E_NOINTERFACE;
  100. }
  101.  
  102.