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

Multidevice ASIO output plugin for WinAMP

, 13 Feb 2009 CDDL
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)

Share

About the Author

Domagoj Šarić
Software Developer Little Endian Ltd.
Croatia Croatia
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 13 Feb 2009
Article Copyright 2009 by Domagoj Šarić
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid