3 ==============================================================================
5 This file is part of the mfsample
6 Copyright 2005-11 by Satoshi Fujiwara.
8 mfsample can be redistributed and/or modified under the terms of the
9 GNU General Public License, as published by the Free Software Foundation;
10 either version 2 of the License, or (at your option) any later version.
12 async is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with async; if not, visit www.gnu.org/licenses or write to the
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 Boston, MA 02111-1307 USA
22 ==============================================================================
26 * @author S.F. (Satoshi Fujiwara)
34 template <class COM_SMART_PTR > inline void safe_release(COM_SMART_PTR& ptr)
44 apartment_threaded = 0x2,
45 disable_ole1dde = 0x4,
46 speed_over_memory = 0x8
52 com_initialize(void * reserved ,unsigned int init);
53 com_initialize(){com_initialize(0,multi_threaded);};
56 std::shared_ptr<impl> m_impl;
59 template <typename ComClass,typename ComInterface>
60 boost::intrusive_ptr<ComInterface> create_instance()
62 ComInterface * com_ptr;
63 CoCreateInstance( __uuidof(ComClass), NULL,
64 CLSCTX_ALL, __uuidof(ComInterface),
66 return boost::intrusive_ptr<ComInterface>(com_ptr,false);
69 template <typename COMInterface>
70 struct IUnknownImpl : public COMInterface
72 IUnknownImpl() : ref_(1) {};
73 virtual ~IUnknownImpl() {};
74 ULONG __stdcall AddRef()
76 return InterlockedIncrement(&ref_);
79 ULONG __stdcall Release()
81 ULONG ref = InterlockedDecrement(&ref_);
89 HRESULT __stdcall QueryInterface(REFIID riid, VOID **ppObj)
91 if (IID_IUnknown == riid)
94 *ppObj = (IUnknown*)this;
96 else if (__uuidof(COMInterface) == riid)
99 *ppObj = (COMInterface*)this;
104 return E_NOINTERFACE;