www.pudn.com > WMACompressor.zip > Utility.h
// This material has been supplied as part of the Adapt-X Engine Development
// Kit. Under copyright laws, this material may not be duplicated in whole
// or in part, except for personal use, without the express written consent
// of the author. Refer to the license agreement contained with this SDK
// before using any part of this material.
//
// 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.
//
// Email: adaptx@hotmail.com
//
// Copyright (C) 1999-2002 Ianier Munoz. All Rights Reserved.
#pragma once
#define WAVE_FORMAT_IEEE_FLOAT 3
#define ReleaseComObject(x) if (x != NULL) { x->Release(); x = NULL; }
//#include "adaptx30.h"
using namespace System;
//using namespace System::IO;
//using namespace System::Collections;
using namespace System::Runtime::InteropServices;
/*
using namespace System::Drawing;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
namespace AdaptX
{
#define errCantCreateEngine S"Can't create the Adapt-X engine."
#define errBadEngineVersion S"Bad Adapt-X engine version."
#define errCantCreateEnumerator S"Can't create the system enumerator."
#define errCantCreateEditor S"Can't create the engine editor."
public __gc class AdaptXException : public Exception
{
public:
AdaptXException(String* Message) : Exception(Message)
{
}
};
}
*/
template<__nogc class Derived, __nogc class I, __gc class W>
class ManWrapper : public I
{
public:
static void Create(W* wrapped, I** result)
{
Derived* c = new Derived();
c->Init(wrapped);
c->QueryInterface(__uuidof(I), (void**)result);
}
public:
ManWrapper() :
m_RefCount(0), m_IntfHandle(NULL)
{
}
virtual ~ManWrapper()
{
Done();
}
public:
void Init(W* wrapped)
{
if (wrapped != GetIntf())
{
Done();
IntPtr IntfHandle = (IntPtr)GCHandle::Alloc(wrapped);
m_IntfHandle = IntfHandle.ToPointer();
}
}
void Done()
{
if (m_IntfHandle != NULL)
{
GCHandle h = GCHandle::op_Explicit(IntPtr(m_IntfHandle));
if (h.IsAllocated)
h.Free();
m_IntfHandle = NULL;
}
}
W* GetIntf()
{
if (m_IntfHandle != NULL)
{
GCHandle h = GCHandle::op_Explicit(IntPtr(m_IntfHandle));
return static_cast(h.Target);
}
else
return NULL;
}
protected:
void* m_IntfHandle;
public: // IUnknown
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject)
{
if (riid == IID_IUnknown || riid == __uuidof(I))
{
(*ppvObject) = (I*)this;
AddRef();
return S_OK;
}
else return E_NOINTERFACE;
}
virtual ULONG STDMETHODCALLTYPE AddRef(void)
{
return ++m_RefCount;
}
virtual ULONG STDMETHODCALLTYPE Release(void)
{
m_RefCount--;
if (m_RefCount > 0)
return m_RefCount;
else
{
delete this;
return 0;
}
}
private:
ULONG m_RefCount;
};