Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Windows Media Audio compressor

, 8 Apr 2004
Managed C++ Windows Media Audio (WMA) compressor.
//
//  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
//  PURPOSE. IT CAN BE DISTRIBUTED FREE OF CHARGE AS LONG AS THIS HEADER 
//  REMAINS UNCHANGED.
//
//  Email:  yetiicb@hotmail.com
//
//  Copyright (C) 2002-2004 Idael Cardoso. 
//
#pragma once

#include <wmsdk.h>
using namespace System;
using namespace System::Runtime::InteropServices;

[uuid("9F85F1F2-9589-414E-AA38-036ADB561651")]
__gc __interface IManBuffer
{
  HRESULT GetLength(/* [out] */ DWORD *pdwLength);
  HRESULT SetLength(/* [in] */ DWORD dwLength);
  HRESULT GetMaxLength(/* [out] */ DWORD *pdwLength);
  HRESULT GetBuffer(/* [out] */ BYTE **ppdwBuffer);
  HRESULT GetBufferAndLength(/* [out] */ BYTE **ppdwBuffer,/* [out] */ DWORD *pdwLength);
  __property Byte get_Buffer()[];
  __property DWORD get_UsedLength();
};



[uuid("5B67D2FC-7E66-4849-A50C-77E755EAEB2F")]
__nogc __interface IManBufferRef : IUnknown
{
  HRESULT STDMETHODCALLTYPE GetManBuffer( /* [out] */ void** ppBuffer);
};

__nogc class CBuffer : public ManWrapper<CBuffer, INSSBuffer, IManBuffer>, public IManBufferRef
{
public:
  CBuffer()
  {
  }

  ~CBuffer(void)
  {
  }
public: //ImanBufferRef
 virtual HRESULT STDMETHODCALLTYPE GetManBuffer( /* [out] */ void ** ppBuffer)
 {
   if (ppBuffer != NULL)
   {
     *ppBuffer = m_IntfHandle;
     return S_OK;
   }
   else
   {
     return E_INVALIDARG;
   }
 } 
public: //INSSBuffer
  virtual HRESULT STDMETHODCALLTYPE GetLength(/* [out] */ DWORD *pdwLength)
  {
    IManBuffer* pB = GetIntf();
    return pB->GetLength(pdwLength);
  }
  virtual HRESULT STDMETHODCALLTYPE SetLength(/* [in] */ DWORD dwLength)
  {
    IManBuffer* pB = GetIntf();
    return pB->SetLength(dwLength);
  }
  virtual HRESULT STDMETHODCALLTYPE GetMaxLength(/* [out] */ DWORD *pdwLength)
  {
    IManBuffer* pB = GetIntf();
    return pB->GetMaxLength(pdwLength);
  }
  virtual HRESULT STDMETHODCALLTYPE GetBuffer(/* [out] */ BYTE **ppdwBuffer)
  {
    IManBuffer* pB = GetIntf();
    return pB->GetBuffer(ppdwBuffer);
  }
  virtual HRESULT STDMETHODCALLTYPE GetBufferAndLength(/* [out] */ BYTE **ppdwBuffer,/* [out] */ DWORD *pdwLength)
  {
    IManBuffer* pB = GetIntf();
    return pB->GetBufferAndLength(ppdwBuffer, pdwLength);
  }
public: //IUnknown
  virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) 
	{ 
		if (riid == __uuidof(IManBufferRef)) 
		{ 
			(*ppvObject) = (IManBufferRef*)this; 
			AddRef(); 
			return S_OK; 
		} 
    else return ManWrapper<CBuffer, INSSBuffer, IManBuffer>::QueryInterface(riid, ppvObject); 
	}

  virtual ULONG STDMETHODCALLTYPE AddRef(void) 
	{ 
    return ManWrapper<CBuffer, INSSBuffer, IManBuffer>::AddRef(); 
	} 
	virtual ULONG STDMETHODCALLTYPE Release(void) 
	{ 
    return ManWrapper<CBuffer, INSSBuffer, IManBuffer>::Release();
	} 
};

__gc class ManBuffer : public IManBuffer
{
private:
  Byte m_Buffer[];
  GCHandle m_BufferHandle;
  DWORD m_BufferSize;
  DWORD m_UsedSize;
  static int gCount = 0;
public:
  int m_Count;
  ManBuffer(DWORD size)
  {
    m_BufferSize = size;
    m_UsedSize = size;
    m_Buffer = NULL;
    m_Count = gCount++;
  }
  ManBuffer(Byte Buff[])
  {
    m_Buffer = Buff;
    m_BufferHandle = GCHandle::Alloc(m_Buffer, GCHandleType::Pinned);
    m_BufferSize = m_Buffer->Length;
    m_UsedSize = m_BufferSize;
    m_Count = gCount++;
  }
  ~ManBuffer()
  {
    if (m_BufferHandle.IsAllocated)
    {
      m_BufferHandle.Free();
    }
    m_Buffer = NULL;
  }
public: //IManBuffer
  HRESULT GetLength(/* [out] */ DWORD *pdwLength)
  {
    if (pdwLength != NULL)
    {
      *pdwLength = m_UsedSize;
      return S_OK;
    }
    else
    {
      return E_POINTER;
    }
  }
  HRESULT SetLength(/* [in] */ DWORD dwLength)
  {
    if ( dwLength <= m_BufferSize)
    {
      m_UsedSize = dwLength;
      return S_OK;
    }
    else
    {
      return E_INVALIDARG;
    }
  }
  HRESULT GetMaxLength(/* [out] */ DWORD *pdwLength)
  {
    if ( pdwLength != NULL)
    {
      *pdwLength = m_BufferSize;
      return S_OK;
    }
    else
    {
      return E_POINTER;
    }
  }
  HRESULT GetBuffer(/* [out] */ BYTE **ppdwBuffer)
  {
    if (ppdwBuffer != NULL)
    {
      if (m_Buffer == NULL)
      {
        try
        {
          m_Buffer = new Byte[m_BufferSize];
          m_BufferHandle = GCHandle::Alloc(m_Buffer, GCHandleType::Pinned);
        }
        catch(...)
        {
          m_Buffer = NULL;
          return E_OUTOFMEMORY;
        }
      }
      try
      {
        *ppdwBuffer = (BYTE*)m_BufferHandle.AddrOfPinnedObject().ToPointer();
        return S_OK;
      }
      catch(...)
      {
        return E_FAIL;
      }
    }
    else
    {
      return E_POINTER;
    }
  }
  HRESULT GetBufferAndLength(/* [out] */ BYTE **ppdwBuffer,/* [out] */ DWORD *pdwLength)
  {
    if ( (ppdwBuffer != NULL) && (pdwLength != NULL) )
    {
      *pdwLength = m_UsedSize;
      return GetBuffer(ppdwBuffer);
    }
    else
    {
      return E_POINTER;
    }
  }
  __property Byte get_Buffer()[]
  {
    return m_Buffer;
  }
  __property DWORD get_UsedLength()
  {
    return m_UsedSize;
  }
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Idael Cardoso
Web Developer
France France
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 9 Apr 2004
Article Copyright 2004 by Idael Cardoso
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid