Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C#

Windows Development in C++, COM API Clients

Rate me:
Please Sign up or sign in to vote.
4.98/5 (31 votes)
3 Jan 2015CPOL7 min read 62.8K   1.6K   106  
Using the Facade Pattern to simplify development with COM based APIs
#pragma once
#ifndef __HWINDEF_H__
#define __HWINDEF_H__ 1

#pragma warning(disable:4996)

#define OEMRESOURCE

#include <SDKDDKVer.h>

#define SECURITY_WIN32 
// Windows Header Files:
#include <windows.h>
#include <Windowsx.h>
#include <CommCtrl.h>
#include <Security.h>
#include <d2d1.h>
#include <dwrite.h>
#include <wincodec.h>
#include <Shobjidl.h>
#include <mshtml.h>
#include <OCIdl.h>
#include <OleDlg.h>
#include <CorError.h>

#include <algorithm>
#include <array>
#include <atomic>
#include <string>
#include <utility>
#include <memory>
#include <map>
#include <set>
#include <cmath>
#include <cfloat>
#include <iosfwd>
#include <regex>
#include <complex>
#include <unordered_map>

#include <wchar.h>

#include <boost/signals2/signal.hpp>

#ifdef HARLINNWINDOWS_EXPORTS
#define HWIN_EXPORT __declspec(dllexport)
#else
#define HWIN_EXPORT __declspec(dllimport)
#pragma comment(lib,"HarlinnWindowsLib")
#endif

namespace harlinn
{
    namespace windows
    {
        typedef signed char Int8;
        typedef signed char SByte;
        typedef unsigned char UInt8;
        typedef unsigned char Byte;
        typedef short Int16;
        typedef unsigned short UInt16;
        typedef unsigned short ushort;

        typedef int Int32;
        typedef int Int;
        typedef unsigned int UInt32;
        typedef unsigned int UInt;
        typedef unsigned long ULong32;
        typedef long Long32;
        typedef unsigned int uint;
        typedef unsigned long DWord32;
        typedef unsigned long DWord;

        typedef long long Int64;
        typedef long long Long64;
        typedef long long LongLong;
        typedef unsigned long long UInt64;
        typedef unsigned long long ULong64;
        typedef unsigned long long ULongLong;
        typedef unsigned long DWord64;

        typedef long long SSizeT;
        typedef unsigned long long SizeT;


        const UInt8 MaxUInt8 = ( ( UInt8 )~( ( UInt8 )0 ) );
        const Int8 MaxInt8 = ( ( Int8 )( MaxUInt8 >> 1 ) );
        const Int8 MinInt8 = ( ( Int8 )~MaxInt8 );

        const UInt16 MaxUInt16 = ( ( UInt16 )~( ( UInt16 )0 ) );
        const Int16  MaxInt16 = ( ( Int16 )( MaxUInt16 >> 1 ) );
        const Int16  MinInt16 = ( ( Int16 )~MaxInt16 );

        const UInt32 MaxUInt32 = ( ( UInt32 )~( ( UInt32 )0 ) );
        const Int32  MaxInt32 = ( ( Int32 )( MaxUInt32 >> 1 ) );
        const Int32  MinInt32 = ( ( Int32 )~MaxInt32 );

        const UInt64 MaxUInt64 = ( ( UInt64 )~( ( UInt64 )0 ) );
        const Int64  MaxInt64 = ( ( Int64 )( MaxUInt64 >> 1 ) );
        const Int64  MinInt64 = ( ( Int64 )~MaxInt64 );

        const ULong32 MaxULong32 = ( ( ULong32 )~( ( ULong32 )0 ) );
        const Long32  MaxLong32 = ( ( Long32 )( MaxULong32 >> 1 ) );
        const Long32  MinLong32 = ( ( Long32 )~MaxLong32 );

        const ULong64 MaxULong64 = ( ( ULong64 )~( ( ULong64 )0 ) );
        const Long64 MaxLong64 = ( ( Long64 )( MaxULong64 >> 1 ) );
        const Long64 MinLong64 = ( ( Long64 )~MaxLong64 );

        const ULongLong MaxULongLong = ( ( ULongLong )~( ( ULongLong )0 ) );
        const LongLong MaxLongLong = ( ( LongLong )( MaxULongLong >> 1 ) );
        const LongLong MinLongLong = ( ( LongLong )~MaxLongLong );

        const  SizeT MaxSizeT = ( ( SizeT )~( ( SizeT )0 ) );
        const  SSizeT MaxSSizeT = ( ( SSizeT )( MaxSizeT >> 1 ) );
        const  SSizeT MinSSizeT = ( ( SSizeT )~MaxSSizeT );

        const  UInt MaxUInt = ( ( UInt )~( ( UInt )0 ) );
        const  Int MaxInt = ( ( Int )( MaxUInt >> 1 ) );
        const  Int  MinInt = ( ( Int )~MaxInt );

        const  DWord32 MaxDWord32 = ( ( DWord32 )~( ( DWord32 )0 ) );
        const  DWord64 MaxDWord64 = ( ( DWord64 )~( ( DWord64 )0 ) );

        template<typename T>
        inline bool InRange(const T& value,const T& minvalue, const T& maxValue)
        {
            return value >= minValue && value < maxValue;
        }

        template<typename T>
        inline bool NotInRange(const T& value,const T& minvalue, const T& maxValue)
        {
            return value < minValue && value >= maxValue;
        }


#define HWIN_STRING_IS_WIDE 1

        class WideString;
        class AnsiString;
#ifdef HWIN_STRING_IS_WIDE
        typedef WideString String;
        typedef wchar_t CharType;
#define HWIN_TEXT(quote) L##quote
#else
        typedef AnsiString String;
        typedef char CharType;
#define HWIN_TEXT(quote) quote
#endif

        enum class SeekOrigin
        {
            StartOfFile = 0,
            CurrentPosition = 1,
            EndOfFile = 2
        };

    };
};

#define HWIN_DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE,INTTYPE) \
  inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((INTTYPE) a) | ((INTTYPE) b)); } \
  inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &) (((INTTYPE &) a) |= ((INTTYPE) b)); } \
  inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((INTTYPE) a) & ((INTTYPE) b)); } \
  inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &) (((INTTYPE &) a) &= ((INTTYPE) b)); } \
  inline ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((INTTYPE) a)); } \
  inline ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((INTTYPE) a) ^ ((INTTYPE) b)); } \
  inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &) (((INTTYPE &) a) ^= ((INTTYPE) b)); } 


#endif

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