00001 /* 00002 Copyright (c) 2010, The Barbarian Group 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that 00006 the following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, this list of conditions and 00009 the following disclaimer. 00010 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 00011 the following disclaimer in the documentation and/or other materials provided with the distribution. 00012 00013 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 00014 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00015 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00016 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00017 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00018 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00019 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00020 POSSIBILITY OF SUCH DAMAGE. 00021 */ 00022 00023 #pragma once 00024 00025 #include "cinder/Cinder.h" 00026 #include "cinder/Vector.h" 00027 #include "cinder/Surface.h" 00028 #include "cinder/Stream.h" 00029 00030 #include <string> 00031 #include <windows.h> 00032 #include <Objidl.h> 00033 #undef min 00034 #undef max 00035 00036 namespace cinder { namespace msw { 00037 00040 Surface8u convertHBitmap( HBITMAP hbitmap ); 00041 00042 00044 inline Vec2f toVec2f( const ::POINTFX &p ) 00045 { return Vec2f( ( (p.x.value << 16) | p.x.fract ) / 65535.0f, ( (p.y.value << 16) | p.y.fract ) / 65535.0f ); } 00046 00048 void ComDelete( void *p ); 00049 00051 template<typename T> 00052 inline std::shared_ptr<T> makeComShared( T *p ) 00053 { return std::shared_ptr<T>( p, &ComDelete ); } 00054 00056 class ComOStream : public ::IStream 00057 { 00058 public: 00059 ComOStream( cinder::OStreamRef aOStream ) : mOStream( aOStream ), _refcount( 1 ) {} 00060 00061 virtual HRESULT STDMETHODCALLTYPE QueryInterface( REFIID iid, void ** ppvObject ); 00062 virtual ULONG STDMETHODCALLTYPE AddRef(); 00063 virtual ULONG STDMETHODCALLTYPE Release(); 00064 00065 // ISequentialStream Interface 00066 public: 00067 virtual HRESULT STDMETHODCALLTYPE Read( void* pv, ULONG cb, ULONG* pcbRead ) { return E_NOTIMPL; } 00068 virtual HRESULT STDMETHODCALLTYPE Write( void const* pv, ULONG cb, ULONG* pcbWritten ); 00069 // IStream Interface 00070 public: 00071 virtual HRESULT STDMETHODCALLTYPE SetSize( ULARGE_INTEGER ) { return E_NOTIMPL; } 00072 virtual HRESULT STDMETHODCALLTYPE CopyTo( ::IStream*, ULARGE_INTEGER, ULARGE_INTEGER*, ULARGE_INTEGER* ) { return E_NOTIMPL; } 00073 virtual HRESULT STDMETHODCALLTYPE Commit( DWORD ) { return E_NOTIMPL; } 00074 virtual HRESULT STDMETHODCALLTYPE Revert() { return E_NOTIMPL; } 00075 virtual HRESULT STDMETHODCALLTYPE LockRegion( ULARGE_INTEGER, ULARGE_INTEGER, DWORD ) { return E_NOTIMPL; } 00076 virtual HRESULT STDMETHODCALLTYPE UnlockRegion( ULARGE_INTEGER, ULARGE_INTEGER, DWORD ) { return E_NOTIMPL; } 00077 virtual HRESULT STDMETHODCALLTYPE Clone(IStream **) { return E_NOTIMPL; } 00078 virtual HRESULT STDMETHODCALLTYPE Seek( LARGE_INTEGER liDistanceToMove, DWORD dwOrigin, ULARGE_INTEGER* lpNewFilePointer ); 00079 virtual HRESULT STDMETHODCALLTYPE Stat( STATSTG* pStatstg, DWORD grfStatFlag) { return E_NOTIMPL; } 00080 00081 private: 00082 cinder::OStreamRef mOStream; 00083 LONG _refcount; 00084 }; 00085 00087 void initializeCom( DWORD params = COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE ); 00088 00089 } } // namespace cinder::msw