Click here to Skip to main content
15,892,809 members
Articles / Desktop Programming / WTL

Multidevice ASIO output plugin for WinAMP

Rate me:
Please Sign up or sign in to vote.
4.80/5 (9 votes)
13 Feb 2009CDDL27 min read 48.3K   728   23  
A tiny WinAMP output DLL that uses a C++ replacement of the official ASIO SDK that supports multiple ASIO devices.
//
// COMAutoPtrWrapper module
// ------------------------
//
//  Provides a simple wrapper around various/known COM smart pointers and raw
// interface pointers to provide a single interface.
//  (currently provides only the minimum required for the Wasiona project)
//
////////////////////////////////////////////////////////////////////////////////

#pragma once

#ifdef TINY_ATL
    // (todo) this is duplicated from WTL.h (remove the duplication).
    #define ATLENSURE ATLVERIFY
    #define AtlThrow exit
#endif

#define _WIN32_DCOM // Required to be able to use COM.


// "Native" _com_ptr_t<>.
#include "comip.h"
#include "comdef.h"

// ATL::CComPtr<>.
#include "atlcomcli.h"

#include <type_traits>


////////////////////////////////////////////////////////////////////////////////
//
//  COMAutoPtrWrapper
//  -----------------
//
// (todo) add a "direct" getter for the BaseCOMInterface (which bypasses any
//        BaseCOMPtr checks).
//
////////////////////////////////////////////////////////////////////////////////

template <class BaseCOMPtr, class BaseCOMInterface>
class COMAutoPtrWrapper
{
public:
    COMAutoPtrWrapper() : baseCOMPtr_() {}
    COMAutoPtrWrapper( BaseCOMPtr const * const baseCOMPtr ) : baseCOMPtr_( baseCOMPtr ) { addRefIfNecessary(); }
    COMAutoPtrWrapper( COMAutoPtrWrapper const & source ) : baseCOMPtr_( source.baseCOMPtr_ ) { addRefIfNecessary(); }
    ~COMAutoPtrWrapper() { releaseIfNecessary(); }

    BaseCOMInterface & operator *() const;
    BaseCOMInterface * operator->() const { return &operator*(); }

    COMAutoPtrWrapper & operator=( COMAutoPtrWrapper const & other );

    unsigned long release();

    static COMAutoPtrWrapper createInstance( REFCLSID rclsid, REFIID riid, DWORD dwClsContext = CLSCTX_INPROC_SERVER );

    BaseCOMPtr & base() { return baseCOMPtr_; }

    typedef BaseCOMInterface * (COMAutoPtrWrapper::*unspecified_bool_type)() const;
    operator unspecified_bool_type() const { return baseCOMPtr_ ? &COMAutoPtrWrapper::operator-> : 0; }

private:
    void addRefIfNecessary();
    void releaseIfNecessary();

private:
    BaseCOMPtr baseCOMPtr_;
};


#include "COMSmartPTrWrapper.inl"

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, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Software Developer Little Endian Ltd.
Croatia Croatia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions