Click here to Skip to main content
15,886,077 members
Articles / Multimedia / DirectX

Rendering Text with Direct2D & DirectWrite

Rate me:
Please Sign up or sign in to vote.
4.94/5 (39 votes)
3 Jan 2015CPOL8 min read 105.9K   2.8K   76  
Direct2D, DirectWrite, Windows API, C++, std::shared_ptr and more
#pragma once
#ifndef __HWINCOMOBJECT_H__
#define __HWINCOMOBJECT_H__

#include "hwinobject.h"
#include "hwinobjimpl.h"
#include "hwinio.h"

namespace harlinn
{
    namespace windows
    {
            

        class ComObject : public ComObjectBase
        {
            friend class Object;
            std::shared_ptr<Object> object;

            IUnknownImpl<ComObject,IUnknown> unknownImpl;
        public:
            typedef ComObjectBase Base;

            ComObject( std::shared_ptr<Object> theObject )
                : object(theObject),
                  unknownImpl(this)
            {

            }

            ~ComObject()
            {
                if(object)
                {
                    object->comObject = nullptr;    
                    object = nullptr;
                }
            }

            template <typename T>
            std::shared_ptr<T> InternalObject() const
            {
                return object->As<T>();
            }

        };


        



        class ComStream : public ComObject 
        {
            IStreamImpl<ComStream> streamImpl;
        public:
            typedef ComObject Base;

            ComStream( std::shared_ptr<harlinn::windows::StreamBase> streamBase )
                : Base(streamBase),
                  streamImpl(this)
            {

            }

            
            virtual HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid,void ** ppvObject)
            {
                auto hr = InternalQueryInterface( riid,ppvObject);
                return hr;
            }

            virtual ULONG STDMETHODCALLTYPE AddRef( )
            {
                auto res = InternalAddRef( );
                return res;
            }

            virtual ULONG STDMETHODCALLTYPE Release( )
            {
                auto res = InternalRelease( );
                return res;
            }


            std::shared_ptr<harlinn::windows::StreamBase> GetStreamBase()
            {
                return InternalObject<harlinn::windows::StreamBase>();
            }


            HWIN_EXPORT HRESULT Read(void *pv,ULONG cb,ULONG *pcbRead);
            HWIN_EXPORT HRESULT Write(const void *pv,ULONG cb,ULONG *pcbWritten);
            HWIN_EXPORT HRESULT Seek(LARGE_INTEGER dlibMove,DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition);
            HWIN_EXPORT HRESULT SetSize(ULARGE_INTEGER libNewSize);
            HWIN_EXPORT HRESULT CopyTo( IStream *pstm,ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten);
            HWIN_EXPORT HRESULT Commit(DWORD grfCommitFlags);
            HWIN_EXPORT HRESULT Revert( void );
            HWIN_EXPORT HRESULT LockRegion( ULARGE_INTEGER libOffset,ULARGE_INTEGER cb,DWORD dwLockType);
            HWIN_EXPORT HRESULT UnlockRegion( ULARGE_INTEGER libOffset,ULARGE_INTEGER cb,DWORD dwLockType);
            HWIN_EXPORT HRESULT Stat( STATSTG *pstatstg,DWORD grfStatFlag );
            HWIN_EXPORT HRESULT Clone( IStream **ppstm );



        };


    };
};

#endif // __HWINCOMOBJECT_H__

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 Code Project Open License (CPOL)


Written By
Architect Sea Surveillance AS
Norway Norway
Chief Architect - Sea Surveillance AS.

Specializing in integrated operations and high performance computing solutions.

I’ve been fooling around with computers since the early eighties, I’ve even done work on CP/M and MP/M.

Wrote my first “real” program on a BBC micro model B based on a series in a magazine at that time. It was fun and I got hooked on this thing called programming ...

A few Highlights:

  • High performance application server development
  • Model Driven Architecture and Code generators
  • Real-Time Distributed Solutions
  • C, C++, C#, Java, TSQL, PL/SQL, Delphi, ActionScript, Perl, Rexx
  • Microsoft SQL Server, Oracle RDBMS, IBM DB2, PostGreSQL
  • AMQP, Apache qpid, RabbitMQ, Microsoft Message Queuing, IBM WebSphereMQ, Oracle TuxidoMQ
  • Oracle WebLogic, IBM WebSphere
  • Corba, COM, DCE, WCF
  • AspenTech InfoPlus.21(IP21), OsiSoft PI


More information about what I do for a living can be found at: harlinn.com or LinkedIn

You can contact me at espen@harlinn.no

Comments and Discussions