From 15a336b668b71504d21892c836af0c810c7a6c83 Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Sun, 23 Nov 2014 17:53:53 +0000 Subject: [PATCH] Add ATL header files from https://github.com/michaellukashov/Far-NetBox --- src/main/headers/atlalloc.h | 767 ++++ src/main/headers/atlbase.h | 6534 ++++++++++++++++++++++++++++++++ src/main/headers/atlbase.inl | 475 +++ src/main/headers/atlchecked.h | 398 ++ src/main/headers/atlcomcli.h | 3210 ++++++++++++++++ src/main/headers/atlconv.h | 1485 ++++++++ src/main/headers/atlcore.h | 601 +++ src/main/headers/atldef.h | 712 ++++ src/main/headers/atlexcept.h | 120 + src/main/headers/atliface.h | 2794 ++++++++++++++ src/main/headers/atlrc.h | 27 + src/main/headers/atlsimpcoll.h | 525 +++ src/main/headers/atltrace.h | 60 + src/main/headers/nbglobals.h | 208 + src/main/headers/statreg.h | 1609 ++++++++ 15 files changed, 19525 insertions(+) create mode 100644 src/main/headers/atlalloc.h create mode 100644 src/main/headers/atlbase.h create mode 100644 src/main/headers/atlbase.inl create mode 100644 src/main/headers/atlchecked.h create mode 100644 src/main/headers/atlcomcli.h create mode 100644 src/main/headers/atlconv.h create mode 100644 src/main/headers/atlcore.h create mode 100644 src/main/headers/atldef.h create mode 100644 src/main/headers/atlexcept.h create mode 100644 src/main/headers/atliface.h create mode 100644 src/main/headers/atlrc.h create mode 100644 src/main/headers/atlsimpcoll.h create mode 100644 src/main/headers/atltrace.h create mode 100644 src/main/headers/nbglobals.h create mode 100644 src/main/headers/statreg.h diff --git a/src/main/headers/atlalloc.h b/src/main/headers/atlalloc.h new file mode 100644 index 0000000..133109a --- /dev/null +++ b/src/main/headers/atlalloc.h @@ -0,0 +1,767 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#pragma once +#ifndef __ATLALLOC_H__ +#define __ATLALLOC_H__ +#endif + +#include +#include +#include + +#pragma pack(push,_ATL_PACKING) +namespace ATL +{ + +/* +This is more than a little unsatisfying. /Wp64 warns when we convert a size_t to an int +because it knows such a conversion won't port. +But, when we have overloaded templates, there may well exist both conversions and we need +to fool the warning into not firing on 32 bit builds +*/ +#if !defined(_ATL_W64) +#if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) +#define _ATL_W64 __w64 +#else +#define _ATL_W64 +#endif +#endif + +/* Can't use ::std::numeric_limits here because we don't want to introduce a new + deprendency of this code on SCL +*/ + +template +class AtlLimits; + +template<> +class AtlLimits +{ +public: + static const int _Min=INT_MIN; + static const int _Max=INT_MAX; +}; + +template<> +class AtlLimits +{ +public: + static const unsigned int _Min=0; + static const unsigned int _Max=UINT_MAX; +}; + +template<> +class AtlLimits +{ +public: + static const long _Min=LONG_MIN; + static const long _Max=LONG_MAX; +}; + +template<> +class AtlLimits +{ +public: + static const unsigned long _Min=0; + static const unsigned long _Max=ULONG_MAX; +}; + +template<> +class AtlLimits +{ +public: + static const long long _Min=LLONG_MIN; + static const long long _Max=LLONG_MAX; +}; + +template<> +class AtlLimits +{ +public: + static const unsigned long long _Min=0; + static const unsigned long long _Max=ULLONG_MAX; +}; + +/* generic version */ +template +inline HRESULT AtlAdd( + _Out_ T* ptResult, + _In_ T tLeft, + _In_ T tRight) +{ + if(::ATL::AtlLimits::_Max-tLeft < tRight) + { + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); + } + *ptResult= tLeft + tRight; + return S_OK; +} + +/* generic but compariatively slow version */ +template +inline HRESULT AtlMultiply( + _Out_ T* ptResult, + _In_ T tLeft, + _In_ T tRight) +{ + /* avoid divide 0 */ + if(tLeft==0) + { + *ptResult=0; + return S_OK; + } + if(::ATL::AtlLimits::_Max/tLeft < tRight) + { + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); + } + *ptResult= tLeft * tRight; + return S_OK; +} + +/* fast version for 32 bit integers */ +template<> +inline HRESULT AtlMultiply( + _Out_ int _ATL_W64 *piResult, + _In_ int _ATL_W64 iLeft, + _In_ int _ATL_W64 iRight) +{ + __int64 i64Result=static_cast<__int64>(iLeft) * static_cast<__int64>(iRight); + if(i64Result>INT_MAX || i64Result < INT_MIN) + { + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); + } + *piResult=static_cast(i64Result); + return S_OK; +} + +template<> +inline HRESULT AtlMultiply( + _Out_ unsigned int _ATL_W64 *piResult, + _In_ unsigned int _ATL_W64 iLeft, + _In_ unsigned int _ATL_W64 iRight) +{ + unsigned __int64 i64Result=static_cast(iLeft) * static_cast(iRight); + if(i64Result>UINT_MAX) + { + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); + } + *piResult=static_cast(i64Result); + return S_OK; +} + +template<> +inline HRESULT AtlMultiply( + _Out_ long _ATL_W64 *piResult, + _In_ long _ATL_W64 iLeft, + _In_ long _ATL_W64 iRight) +{ + __int64 i64Result=static_cast<__int64>(iLeft) * static_cast<__int64>(iRight); + if(i64Result>LONG_MAX || i64Result < LONG_MIN) + { + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); + } + *piResult=static_cast(i64Result); + return S_OK; +} + +template<> +inline HRESULT AtlMultiply( + _Out_ unsigned long _ATL_W64 *piResult, + _In_ unsigned long _ATL_W64 iLeft, + _In_ unsigned long _ATL_W64 iRight) +{ + unsigned __int64 i64Result=static_cast(iLeft) * static_cast(iRight); + if(i64Result>ULONG_MAX) + { + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); + } + *piResult=static_cast(i64Result); + return S_OK; +} + +template +inline T AtlMultiplyThrow( + _In_ T tLeft, + _In_ T tRight) +{ + T tResult; + HRESULT hr=AtlMultiply(&tResult, tLeft, tRight); + if(FAILED(hr)) + { + AtlThrow(hr); + } + return tResult; +} + +template +inline T AtlAddThrow( + _In_ T tLeft, + _In_ T tRight) +{ + T tResult; + HRESULT hr=AtlAdd(&tResult, tLeft, tRight); + if(FAILED(hr)) + { + AtlThrow(hr); + } + return tResult; +} + +_Ret_opt_bytecount_x_(nCount * nSize) inline LPVOID AtlCoTaskMemCAlloc( + _In_ ULONG nCount, + _In_ ULONG nSize) +{ + HRESULT hr; + ULONG nBytes=0; + if( FAILED(hr=::ATL::AtlMultiply(&nBytes, nCount, nSize))) + { + return NULL; + } + return ::CoTaskMemAlloc(nBytes); +} + +_Ret_opt_bytecount_x_(nCount * nSize) inline LPVOID AtlCoTaskMemRecalloc( + _In_opt_ void *pvMemory, + _In_ ULONG nCount, + _In_ ULONG nSize) +{ + HRESULT hr; + ULONG nBytes=0; + if( FAILED(hr=::ATL::AtlMultiply(&nBytes, nCount, nSize))) + { + return NULL; + } + return ::CoTaskMemRealloc(pvMemory, nBytes); +} + +} // namespace ATL +#pragma pack(pop) + +#pragma pack(push,8) +namespace ATL +{ +// forward declaration of Checked::memcpy_s + +namespace Checked +{ + void __cdecl memcpy_s( + _Out_bytecap_post_bytecount_(_S1max,_N) void *s1, + _In_ size_t _S1max, + _In_bytecount_(_N) const void *s2, + _In_ size_t _N); +} + +///////////////////////////////////////////////////////////////////////////// +// Allocation helpers + +class CCRTAllocator +{ +public: + _Ret_opt_bytecap_(nBytes) static void* Reallocate( + _In_ void* p, + _In_ size_t nBytes) throw() + { + return nb_realloc(p, nBytes); + } + + _Ret_opt_bytecap_(nBytes) static void* Allocate(_In_ size_t nBytes) throw() + { + return nb_malloc(nBytes); + } + + static void Free(_In_ void* p) throw() + { + nb_free(p); + } +}; + +class CLocalAllocator +{ +public: + _Ret_opt_bytecap_(nBytes) static void* Allocate(_In_ size_t nBytes) throw() + { + return ::LocalAlloc(LMEM_FIXED, nBytes); + } + _Ret_opt_bytecap_(nBytes) static void* Reallocate( + _In_ void* p, + _In_ size_t nBytes) throw() + { + if (p==NULL){ + return ( Allocate(nBytes) ); + + } + if (nBytes==0){ + Free(p); + return NULL; + } + return ::LocalReAlloc(p, nBytes, 0); + } + static void Free(_In_ void* p) throw() + { + ::LocalFree(p); + } +}; + +class CGlobalAllocator +{ +public: + _Ret_opt_bytecap_(nBytes) static void* Allocate(_In_ size_t nBytes) throw() + { + return ::GlobalAlloc(GMEM_FIXED, nBytes); + } + _Ret_opt_bytecap_(nBytes) static void* Reallocate( + _In_ void* p, + _In_ size_t nBytes) throw() + { + if (p==NULL){ + return ( Allocate(nBytes) ); + + } + if (nBytes==0){ + Free(p); + return NULL; + } + return ::GlobalReAlloc(p, nBytes, 0); + } + static void Free(_In_ void* p) throw() + { + ::GlobalFree(p); + } +}; + +template +class CHeapPtrBase +{ +protected: + CHeapPtrBase() throw() : + m_pData(NULL) + { + } + CHeapPtrBase(_Inout_ CHeapPtrBase& p) throw() + { + m_pData = p.Detach(); // Transfer ownership + } + explicit CHeapPtrBase(_In_ T* pData) throw() : + m_pData(pData) + { + } + +public: + ~CHeapPtrBase() throw() + { + Free(); + } + +protected: + CHeapPtrBase& operator=(_Inout_ CHeapPtrBase& p) throw() + { + if(m_pData != p.m_pData) + Attach(p.Detach()); // Transfer ownership + return *this; + } + +public: + operator T*() const throw() + { + return m_pData; + } + + T* operator->() const throw() + { + ATLASSERT(m_pData != NULL); + return m_pData; + } + + T** operator&() throw() + { + ATLASSUME(m_pData == NULL); + return &m_pData; + } + + // Allocate a buffer with the given number of bytes + bool AllocateBytes(_In_ size_t nBytes) throw() + { + ATLASSERT(m_pData == NULL); + m_pData = static_cast(Allocator::Allocate(nBytes)); + if (m_pData == NULL) + return false; + + return true; + } + + // Attach to an existing pointer (takes ownership) + void Attach(_In_ T* pData) throw() + { + Allocator::Free(m_pData); + m_pData = pData; + } + + // Detach the pointer (releases ownership) + T* Detach() throw() + { + T* pTemp = m_pData; + m_pData = NULL; + return pTemp; + } + + // Free the memory pointed to, and set the pointer to NULL + void Free() throw() + { + Allocator::Free(m_pData); + m_pData = NULL; + } + + // Reallocate the buffer to hold a given number of bytes + bool ReallocateBytes(_In_ size_t nBytes) throw() + { + T* pNew; + + pNew = static_cast(Allocator::Reallocate(m_pData, nBytes)); + if (pNew == NULL) + return false; + m_pData = pNew; + + return true; + } + +public: + T* m_pData; +}; + +template +class CHeapPtr : + public CHeapPtrBase +{ +public: + CHeapPtr() throw() + { + } + CHeapPtr(_Inout_ CHeapPtr& p) throw() : + CHeapPtrBase(p) + { + } + explicit CHeapPtr(_In_ T* p) throw() : + CHeapPtrBase(p) + { + } + + CHeapPtr& operator=(_Inout_ CHeapPtr& p) throw() + { + CHeapPtrBase::operator=(p); + + return *this; + } + + // Allocate a buffer with the given number of elements + bool Allocate(_In_ size_t nElements = 1) throw() + { + size_t nBytes=0; + if(FAILED(::ATL::AtlMultiply(&nBytes, nElements, sizeof(T)))) + { + return false; + } + return this->AllocateBytes(nBytes); + } + + // Reallocate the buffer to hold a given number of elements + bool Reallocate(_In_ size_t nElements) throw() + { + size_t nBytes=0; + if(FAILED(::ATL::AtlMultiply(&nBytes, nElements, sizeof(T)))) + { + return false; + } + return this->ReallocateBytes(nBytes); + } +}; + +template< typename T, int t_nFixedBytes = 128, class Allocator = CCRTAllocator > +class CTempBuffer +{ +public: + CTempBuffer() throw() : + m_p( NULL ) + { + } + CTempBuffer(_In_ size_t nElements) throw() : + m_p( NULL ) + { + Allocate( nElements ); + } + + ~CTempBuffer() throw() + { + if( m_p != reinterpret_cast< T* >( m_abFixedBuffer ) ) + { + FreeHeap(); + } + } + + operator T*() const throw() + { + return( m_p ); + } + T* operator->() const throw() + { + ATLASSERT( m_p != NULL ); + return( m_p ); + } + + _Ret_opt_bytecap_x_(nElements * sizeof(T)) T* Allocate(_In_ size_t nElements) throw() + { + return( this->AllocateBytes( ::ATL::AtlMultiplyThrow(nElements,sizeof( T )) ) ); + } + + _Ret_opt_bytecap_x_(nElements * sizeof(T)) T* Reallocate(_In_ size_t nElements) throw() + { + ATLENSURE(nElements < size_t(-1)/sizeof(T) ); + size_t nNewSize = nElements*sizeof( T ) ; + + if (m_p == NULL) + return this->AllocateBytes(nNewSize); + + if (nNewSize > t_nFixedBytes) + { + if( m_p == reinterpret_cast< T* >( m_abFixedBuffer ) ) + { + // We have to allocate from the heap and copy the contents into the new buffer + AllocateHeap(nNewSize); + Checked::memcpy_s(m_p, nNewSize, m_abFixedBuffer, t_nFixedBytes); + } + else + { + ReAllocateHeap( nNewSize ); + } + } + else + { + if (m_p != reinterpret_cast< T* >( m_abFixedBuffer )) + { + Checked::memcpy_s(m_abFixedBuffer, t_nFixedBytes, m_p, nNewSize); + FreeHeap(); + } + m_p = reinterpret_cast< T* >( m_abFixedBuffer ); + } + + return m_p; + } + + _Ret_opt_bytecap_(nBytes) T* AllocateBytes(_In_ size_t nBytes) + { + ATLASSERT( m_p == NULL ); + if( nBytes > t_nFixedBytes ) + { + AllocateHeap( nBytes ); + } + else + { + m_p = reinterpret_cast< T* >( m_abFixedBuffer ); + } + + return( m_p ); + } + +private: + void AllocateHeap(_In_ size_t nBytes) + { + T* p = static_cast< T* >( Allocator::Allocate( nBytes ) ); + if( p == NULL ) + { + AtlThrow( E_OUTOFMEMORY ); + } + m_p = p; + } + + void ReAllocateHeap(_In_ size_t nNewSize) + { + T* p = static_cast< T* >( Allocator::Reallocate(m_p, nNewSize) ); + if ( p == NULL ) + { + AtlThrow( E_OUTOFMEMORY ); + } + m_p = p; + } + + void FreeHeap() throw() + { + Allocator::Free( m_p ); + } + +private: + T* m_p; + BYTE m_abFixedBuffer[t_nFixedBytes]; +}; + + +// Allocating memory on the stack without causing stack overflow. +// Only use these through the _ATL_SAFE_ALLOCA_* macros +namespace _ATL_SAFE_ALLOCA_IMPL +{ + +#ifndef _ATL_STACK_MARGIN +#if defined(_M_IX86) +#define _ATL_STACK_MARGIN 0x2000 // Minimum stack available after call to _ATL_SAFE_ALLOCA +#else //_M_AMD64 _M_IA64 +#define _ATL_STACK_MARGIN 0x4000 +#endif +#endif //_ATL_STACK_MARGIN + +//Verifies if sufficient space is available on the stack. +//Note: This function should never be inlined, because the stack allocation +//may not be freed until the end of the calling function (instead of the end of _AtlVerifyStackAvailable). +__declspec(noinline) inline bool _AtlVerifyStackAvailable(_In_ SIZE_T Size) +{ + bool bStackAvailable = true; + +#if !defined(__MINGW32__) + __try +#else + try +#endif + { + SIZE_T size=0; + HRESULT hrAdd=::ATL::AtlAdd(&size, Size, static_cast(_ATL_STACK_MARGIN)); + if(FAILED(hrAdd)) + { + ATLASSERT(FALSE); + bStackAvailable = false; + } + else + { + PVOID p = _alloca(size); + (p); + } + } +#if !defined(__MINGW32__) + __except ((EXCEPTION_STACK_OVERFLOW == GetExceptionCode()) ? + EXCEPTION_EXECUTE_HANDLER : + EXCEPTION_CONTINUE_SEARCH) + { + bStackAvailable = false; + _resetstkoflw(); + } +#else + catch (...) + { + bStackAvailable = false; + _resetstkoflw(); + } +#endif + return bStackAvailable; +} + + +// Helper Classes to manage heap buffers for _ATL_SAFE_ALLOCA +template < class Allocator> +class CAtlSafeAllocBufferManager +{ +private : + struct CAtlSafeAllocBufferNode + { + CAtlSafeAllocBufferNode* m_pNext; +#if defined(_M_IX86) + BYTE _pad[4]; +#elif defined(_M_IA64) + BYTE _pad[8]; +#elif defined(_M_AMD64) + BYTE _pad[8]; +#else + #error Only supported for X86, AMD64 and IA64 +#endif + void* GetData() + { + return (this + 1); + } + }; + + CAtlSafeAllocBufferNode* m_pHead; +public : + + CAtlSafeAllocBufferManager() : m_pHead(NULL) + { + } + _Ret_opt_bytecap_(nRequestedSize) void* Allocate(_In_ SIZE_T nRequestedSize) + { + CAtlSafeAllocBufferNode *p = (CAtlSafeAllocBufferNode*)Allocator::Allocate(::ATL::AtlAddThrow(nRequestedSize, static_cast(sizeof(CAtlSafeAllocBufferNode)))); + if (p == NULL) + return NULL; + + // Add buffer to the list + p->m_pNext = m_pHead; + m_pHead = p; + + return p->GetData(); + } + ~CAtlSafeAllocBufferManager() + { + // Walk the list and free the buffers + while (m_pHead != NULL) + { + CAtlSafeAllocBufferNode* p = m_pHead; + m_pHead = m_pHead->m_pNext; + Allocator::Free(p); + } + } +}; + +} // namespace _ATL_SAFE_ALLOCA_IMPL + +} // namespace ATL + #pragma pack(pop) + +// Use one of the following macros before using _ATL_SAFE_ALLOCA +// EX version allows specifying a different heap allocator +#define USES_ATL_SAFE_ALLOCA_EX(x) ATL::_ATL_SAFE_ALLOCA_IMPL::CAtlSafeAllocBufferManager _AtlSafeAllocaManager + +#ifndef USES_ATL_SAFE_ALLOCA +#define USES_ATL_SAFE_ALLOCA USES_ATL_SAFE_ALLOCA_EX(ATL::CCRTAllocator) +#endif + +// nRequestedSize - requested size in bytes +// nThreshold - size in bytes beyond which memory is allocated from the heap. + +// Defining _ATL_SAFE_ALLOCA_ALWAYS_ALLOCATE_THRESHOLD_SIZE always allocates the size specified +// for threshold if the stack space is available irrespective of requested size. +// This available for testing purposes. It will help determine the max stack usage due to _alloca's +// Disable _alloca not within try-except prefast warning since we verify stack space is available before. +#ifdef _ATL_SAFE_ALLOCA_ALWAYS_ALLOCATE_THRESHOLD_SIZE +#define _ATL_SAFE_ALLOCA(nRequestedSize, nThreshold) \ + __pragma(warning(push))\ + __pragma(warning(disable:4616))\ + __pragma(warning(disable:6255))\ + ((nRequestedSize <= nThreshold && ATL::_ATL_SAFE_ALLOCA_IMPL::_AtlVerifyStackAvailable(nThreshold) ) ? \ + _alloca(nThreshold) : \ + ((ATL::_ATL_SAFE_ALLOCA_IMPL::_AtlVerifyStackAvailable(nThreshold)) ? _alloca(nThreshold) : 0), \ + _AtlSafeAllocaManager.Allocate(nRequestedSize))\ + __pragma(warning(pop)) +#else +#if !defined(__MINGW32__) +#define _ATL_SAFE_ALLOCA(nRequestedSize, nThreshold) \ + __pragma(warning(push))\ + __pragma(warning(disable:4616))\ + __pragma(warning(disable:6255))\ + ((nRequestedSize <= nThreshold && ATL::_ATL_SAFE_ALLOCA_IMPL::_AtlVerifyStackAvailable(nRequestedSize) ) ? \ + _alloca(nRequestedSize) : \ + _AtlSafeAllocaManager.Allocate(nRequestedSize))\ + __pragma(warning(pop)) +#else +#define _ATL_SAFE_ALLOCA(nRequestedSize, nThreshold) \ + ((nRequestedSize <= nThreshold && ATL::_ATL_SAFE_ALLOCA_IMPL::_AtlVerifyStackAvailable(nRequestedSize) ) ? \ + _alloca(nRequestedSize) : \ + _AtlSafeAllocaManager.Allocate(nRequestedSize)) +#endif + +#endif + +// Use 1024 bytes as the default threshold in ATL +#ifndef _ATL_SAFE_ALLOCA_DEF_THRESHOLD +#define _ATL_SAFE_ALLOCA_DEF_THRESHOLD 1024 +#endif diff --git a/src/main/headers/atlbase.h b/src/main/headers/atlbase.h new file mode 100644 index 0000000..03680aa --- /dev/null +++ b/src/main/headers/atlbase.h @@ -0,0 +1,6534 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#ifndef __ATLBASE_H__ +#define __ATLBASE_H__ + +#pragma once + +// Warnings outside of the push/pop sequence will be disabled for all user +// projects. The only warnings that should be disabled outside the push/pop +// are warnings that are a) benign and b) will show up in user projects +// without being directly caused by the user + +#pragma warning(disable: 4505) // unreferenced local function has been removed +#pragma warning(disable: 4710) // function couldn't be inlined +#pragma warning(disable: 4514) // unreferenced inlines are common + +// These two warnings will occur in any class that contains or derives from a +// class with a private copy constructor or copy assignment operator. +#pragma warning(disable: 4511) // copy constructor could not be generated +#pragma warning(disable: 4512) // assignment operator could not be generated + +// This is a very common pattern for us +#pragma warning(disable: 4355) // 'this' : used in base member initializer list + +#ifdef _ATL_ALL_WARNINGS +#pragma warning( push ) +#endif + +#pragma warning(disable : 4668) // is not defined as a preprocessor macro, replacing with '0' for '#if/#elif +#pragma warning(disable : 4820) // padding added after member +#pragma warning(disable : 4917) // a GUID can only be associated with a class, interface or namespace + +#pragma warning(disable : 4217) // member template functions cannot be used for copy-assignment or copy-construction + +#pragma warning(disable: 4127) // constant expression +#pragma warning(disable: 4097) // typedef name used as synonym for class-name +#pragma warning(disable: 4786) // identifier was truncated in the debug information +#pragma warning(disable: 4291) // allow placement new +#pragma warning(disable: 4201) // nameless unions are part of C++ +#pragma warning(disable: 4103) // pragma pack +#pragma warning(disable: 4268) // const static/global data initialized to zeros + +#pragma warning (push) +// Warning 4702 is generated based on compiler backend data flow analysis. This means that for +// some specific instantiations of a template it can be generated even when the code branch is +// required for other instantiations. In future we should find a way to be more selective about this +#pragma warning(disable: 4702) // Unreachable code +#pragma warning(disable: 4571) //catch(...) blocks compiled with /EHs do NOT catch or re-throw Structured Exceptions +#ifndef __cplusplus + #error ATL requires C++ compilation (use a .cpp suffix) +#endif +#ifndef ATL_NO_LEAN_AND_MEAN +#define ATL_NO_LEAN_AND_MEAN +#endif + +#include + +#ifndef _WINSOCKAPI_ +#include +#endif + +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#include +#include // for _beginthreadex, _endthreadex + +#include +#include + +#include +#include +#include +#include +#include + +#define _ATL_TYPELIB_INDEX_LENGTH 10 +#define _ATL_QUOTES_SPACE 2 + +#pragma pack(push, _ATL_PACKING) + +#ifndef _ATL_NO_DEFAULT_LIBS + +#if defined(_ATL_DLL) + #pragma comment(lib, "atl.lib") + +#endif // _ATL_DLL + +#ifdef _DEBUG + #pragma comment(lib, "atlsd.lib") +#else + #pragma comment(lib, "atls.lib") +#endif + +#ifdef _ATL_MIN_CRT + #pragma message("_ATL_MIN_CRT is no longer supported. Please see documentation for more information.") +#endif + + +#endif // !_ATL_NO_DEFAULT_LIBS + +extern "C" const __declspec(selectany) GUID LIBID_ATLLib = {0x44EC0535,0x400F,0x11D0,{0x9D,0xCD,0x00,0xA0,0xC9,0x03,0x91,0xD3}}; +extern "C" const __declspec(selectany) CLSID CLSID_Registrar = {0x44EC053A,0x400F,0x11D0,{0x9D,0xCD,0x00,0xA0,0xC9,0x03,0x91,0xD3}}; +extern "C" const __declspec(selectany) IID IID_IRegistrar = {0x44EC053B,0x400F,0x11D0,{0x9D,0xCD,0x00,0xA0,0xC9,0x03,0x91,0xD3}}; +extern "C" const __declspec(selectany) IID IID_IAxWinHostWindow = {0xb6ea2050,0x048a,0x11d1,{0x82,0xb9,0x00,0xc0,0x4f,0xb9,0x94,0x2e}}; +extern "C" const __declspec(selectany) IID IID_IAxWinAmbientDispatch = {0xb6ea2051,0x048a,0x11d1,{0x82,0xb9,0x00,0xc0,0x4f,0xb9,0x94,0x2e}}; +extern "C" const __declspec(selectany) IID IID_IInternalConnection = {0x72AD0770,0x6A9F,0x11d1,{0xBC,0xEC,0x00,0x60,0x08,0x8F,0x44,0x4E}}; +extern "C" const __declspec(selectany) IID IID_IDocHostUIHandlerDispatch = {0x425B5AF0,0x65F1,0x11d1,{0x96,0x11,0x00,0x00,0xF8,0x1E,0x0D,0x0D}}; +extern "C" const __declspec(selectany) IID IID_IAxWinHostWindowLic = {0x3935BDA8,0x4ED9,0x495c,{0x86,0x50,0xE0,0x1F,0xC1,0xE3,0x8A,0x4B}}; +extern "C" const __declspec(selectany) IID IID_IAxWinAmbientDispatchEx = {0xB2D0778B,0xAC99,0x4c58,{0xA5,0xC8,0xE7,0x72,0x4E,0x53,0x16,0xB5}}; + + +#ifndef _delayimp_h +extern "C" IMAGE_DOS_HEADER __ImageBase; +#endif + +#ifdef _AFX +void AFXAPI AfxOleLockApp(); +void AFXAPI AfxOleUnlockApp(); +#endif // _AFX + +// Support Windows SDK v5.0 +#ifndef LSTATUS +#if !defined(__MINGW32__) +typedef __success(return==ERROR_SUCCESS) LONG LSTATUS; +#else +typedef LONG LSTATUS; +#endif +#endif + +namespace ATL +{ + +struct _ATL_CATMAP_ENTRY +{ + int iType; + const CATID* pcatid; +}; + +#define _ATL_CATMAP_ENTRY_END 0 +#define _ATL_CATMAP_ENTRY_IMPLEMENTED 1 +#define _ATL_CATMAP_ENTRY_REQUIRED 2 + +typedef HRESULT (WINAPI _ATL_CREATORFUNC)( + _In_opt_ void* pv, + _In_ REFIID riid, + _Deref_out_ LPVOID* ppv); +typedef HRESULT (WINAPI _ATL_CREATORARGFUNC)( + _In_opt_ void* pv, + _In_ REFIID riid, + _Deref_out_ LPVOID* ppv, + _In_ DWORD_PTR dw); +typedef HRESULT (WINAPI _ATL_MODULEFUNC)(_In_ DWORD_PTR dw); +typedef LPCTSTR (WINAPI _ATL_DESCRIPTIONFUNC)(); +typedef const struct _ATL_CATMAP_ENTRY* (_ATL_CATMAPFUNC)(); +typedef void (__stdcall _ATL_TERMFUNC)(_In_ DWORD_PTR dw); + +struct _ATL_TERMFUNC_ELEM +{ + _ATL_TERMFUNC* pFunc; + DWORD_PTR dw; + _ATL_TERMFUNC_ELEM* pNext; +}; + +// Can't inherit from _ATL_OBJMAP_ENTRY20 +// because it messes up the OBJECT_MAP macros +struct _ATL_OBJMAP_ENTRY30 +{ + const CLSID* pclsid; + HRESULT (WINAPI *pfnUpdateRegistry)(_In_ BOOL bRegister); + _ATL_CREATORFUNC* pfnGetClassObject; + _ATL_CREATORFUNC* pfnCreateInstance; + IUnknown* pCF; + DWORD dwRegister; + _ATL_DESCRIPTIONFUNC* pfnGetObjectDescription; + _ATL_CATMAPFUNC* pfnGetCategoryMap; + HRESULT WINAPI RevokeClassObject() + { + if (dwRegister == 0) + return S_OK; + return CoRevokeClassObject(dwRegister); + } + HRESULT WINAPI RegisterClassObject( + _In_ DWORD dwClsContext, + _In_ DWORD dwFlags) + { + IUnknown* p = NULL; + if (pfnGetClassObject == NULL) + return S_OK; + HRESULT hRes = 0; // pfnGetClassObject(pfnCreateInstance, __uuidof(IUnknown), (LPVOID*) &p); + if (SUCCEEDED(hRes)) + hRes = CoRegisterClassObject(*pclsid, p, dwClsContext, dwFlags, &dwRegister); + if (p != NULL) + p->Release(); + return hRes; + } +// Added in ATL 3.0 + void (WINAPI *pfnObjectMain)(_In_ bool bStarting); +}; + +typedef _ATL_OBJMAP_ENTRY30 _ATL_OBJMAP_ENTRY; + +// Auto Object Map + +#pragma section("ATL$__a", read) +#pragma section("ATL$__z", read) +#pragma section("ATL$__m", read) +extern "C" +{ +__declspec(selectany) __declspec(allocate("ATL$__a")) _ATL_OBJMAP_ENTRY* __pobjMapEntryFirst = NULL; +__declspec(selectany) __declspec(allocate("ATL$__z")) _ATL_OBJMAP_ENTRY* __pobjMapEntryLast = NULL; +} + +#if !defined(_M_IA64) +#pragma comment(linker, "/merge:ATL=.rdata") +#endif + +struct _ATL_REGMAP_ENTRY +{ + LPCOLESTR szKey; + LPCOLESTR szData; +}; + +struct _AtlCreateWndData +{ + void* m_pThis; + DWORD m_dwThreadID; + _AtlCreateWndData* m_pNext; +}; + + +// perfmon registration/unregistration function definitions +typedef HRESULT (*_ATL_PERFREGFUNC)(_In_ HINSTANCE hDllInstance); +typedef HRESULT (*_ATL_PERFUNREGFUNC)(); +__declspec(selectany) _ATL_PERFREGFUNC _pPerfRegFunc = NULL; +__declspec(selectany) _ATL_PERFUNREGFUNC _pPerfUnRegFunc = NULL; + +bool __declspec(selectany) _AtlRegisterPerUser = false; + +///////////////////////////////////////////////////////////////////////////// +// Threading Model Support + +template< class TLock > +class CComCritSecLock +{ +public: + CComCritSecLock( + _Inout_ TLock& cs, + _In_ bool bInitialLock = true ); + ~CComCritSecLock() throw(); + + HRESULT Lock() throw(); + void Unlock() throw(); + +// Implementation +private: + TLock& m_cs; + bool m_bLocked; + +// Private to avoid accidental use + CComCritSecLock(_In_ const CComCritSecLock&) throw(); + CComCritSecLock& operator=(_In_ const CComCritSecLock&) throw(); +}; + +template< class TLock > +inline CComCritSecLock< TLock >::CComCritSecLock( + _Inout_ TLock& cs, + _In_ bool bInitialLock) : + m_cs( cs ), + m_bLocked( false ) +{ + if( bInitialLock ) + { + HRESULT hr; + + hr = Lock(); + if( FAILED( hr ) ) + { + AtlThrow( hr ); + } + } +} + +template< class TLock > +inline CComCritSecLock< TLock >::~CComCritSecLock() throw() +{ + if( m_bLocked ) + { + Unlock(); + } +} + +template< class TLock > +inline HRESULT CComCritSecLock< TLock >::Lock() throw() +{ + HRESULT hr; + + ATLASSERT( !m_bLocked ); + hr = m_cs.Lock(); + if( FAILED( hr ) ) + { + return( hr ); + } + m_bLocked = true; + + return( S_OK ); +} + +template< class TLock > +inline void CComCritSecLock< TLock >::Unlock() throw() +{ + ATLASSUME( m_bLocked ); + m_cs.Unlock(); + m_bLocked = false; +} + +class CComMultiThreadModelNoCS +{ +public: + static ULONG WINAPI Increment(_Inout_ LPLONG p) throw() + { + return InterlockedIncrement(p); + } + static ULONG WINAPI Decrement(_Inout_ LPLONG p) throw() + { + return InterlockedDecrement(p); + } + typedef CComFakeCriticalSection AutoCriticalSection; + typedef CComFakeCriticalSection AutoDeleteCriticalSection; + typedef CComFakeCriticalSection CriticalSection; + typedef CComMultiThreadModelNoCS ThreadModelNoCS; +}; + +class CComMultiThreadModel +{ +public: + static ULONG WINAPI Increment(_Inout_ LPLONG p) throw() + { + return InterlockedIncrement(p); + } + static ULONG WINAPI Decrement(_Inout_ LPLONG p) throw() + { + return InterlockedDecrement(p); + } + typedef CComAutoCriticalSection AutoCriticalSection; + typedef CComAutoDeleteCriticalSection AutoDeleteCriticalSection; + typedef CComCriticalSection CriticalSection; + typedef CComMultiThreadModelNoCS ThreadModelNoCS; +}; + +class CComSingleThreadModel +{ +public: + static ULONG WINAPI Increment(_Inout_ LPLONG p) throw() + { + return ++(*p); + } + static ULONG WINAPI Decrement(_Inout_ LPLONG p) throw() + { + return --(*p); + } + typedef CComFakeCriticalSection AutoCriticalSection; + typedef CComFakeCriticalSection AutoDeleteCriticalSection; + typedef CComFakeCriticalSection CriticalSection; + typedef CComSingleThreadModel ThreadModelNoCS; +}; + +#if defined(_ATL_SINGLE_THREADED) + +#if defined(_ATL_APARTMENT_THREADED) || defined(_ATL_FREE_THREADED) +#pragma message ("More than one global threading model defined.") +#endif + + typedef CComSingleThreadModel CComObjectThreadModel; + typedef CComSingleThreadModel CComGlobalsThreadModel; + +#elif defined(_ATL_APARTMENT_THREADED) + +#if defined(_ATL_SINGLE_THREADED) || defined(_ATL_FREE_THREADED) +#pragma message ("More than one global threading model defined.") +#endif + + typedef CComSingleThreadModel CComObjectThreadModel; + typedef CComMultiThreadModel CComGlobalsThreadModel; + +#elif defined(_ATL_FREE_THREADED) + +#if defined(_ATL_SINGLE_THREADED) || defined(_ATL_APARTMENT_THREADED) +#pragma message ("More than one global threading model defined.") +#endif + + typedef CComMultiThreadModel CComObjectThreadModel; + typedef CComMultiThreadModel CComGlobalsThreadModel; + +#else +#pragma message ("No global threading model defined") +#endif + +///////////////////////////////////////////////////////////////////////////// +// Module + + +// Used by COM related code in ATL +struct _ATL_COM_MODULE70 +{ + UINT cbSize; + HINSTANCE m_hInstTypeLib; + _ATL_OBJMAP_ENTRY** m_ppAutoObjMapFirst; + _ATL_OBJMAP_ENTRY** m_ppAutoObjMapLast; + CComCriticalSection m_csObjMap; +}; +typedef _ATL_COM_MODULE70 _ATL_COM_MODULE; + + +// Used by Windowing code in ATL +struct _ATL_WIN_MODULE70 +{ + UINT cbSize; + CComCriticalSection m_csWindowCreate; + _AtlCreateWndData* m_pCreateWndList; + CSimpleArray m_rgWindowClassAtoms; +}; +typedef _ATL_WIN_MODULE70 _ATL_WIN_MODULE; + + +struct _ATL_MODULE70 +{ + UINT cbSize; + LONG m_nLockCnt; + _ATL_TERMFUNC_ELEM* m_pTermFuncs; + CComCriticalSection m_csStaticDataInitAndTypeInfo; +}; +typedef _ATL_MODULE70 _ATL_MODULE; + + +///////////////////////////////////////////////////////////////////////////// +//This define makes debugging asserts easier. +#define _ATL_SIMPLEMAPENTRY ((ATL::_ATL_CREATORARGFUNC*)1) + +struct _ATL_INTMAP_ENTRY +{ + const IID* piid; // the interface id (IID) + DWORD_PTR dw; + _ATL_CREATORARGFUNC* pFunc; //NULL:end, 1:offset, n:ptr +}; + +///////////////////////////////////////////////////////////////////////////// +// Global Functions + +///////////////////////////////////////////////////////////////////////////// +// QI Support + +ATLAPI AtlInternalQueryInterface( + _Inout_ void* pThis, + _In_ const _ATL_INTMAP_ENTRY* pEntries, + _In_ REFIID iid, + _Deref_out_ void** ppvObject); + +///////////////////////////////////////////////////////////////////////////// +// Inproc Marshaling helpers + +ATLAPI AtlFreeMarshalStream(_Inout_ IStream* pStream); + +ATLAPI AtlMarshalPtrInProc( + _Inout_ IUnknown* pUnk, + _In_ const IID& iid, + _Deref_out_ IStream** ppStream); + +ATLAPI AtlUnmarshalPtr( + _Inout_ IStream* pStream, + _In_ const IID& iid, + _Deref_out_ IUnknown** ppUnk); + +ATLAPI_(BOOL) AtlWaitWithMessageLoop(_In_ HANDLE hEvent); + +///////////////////////////////////////////////////////////////////////////// +// Connection Point Helpers + +ATLAPI AtlAdvise( + _Inout_ IUnknown* pUnkCP, + _Inout_opt_ IUnknown* pUnk, + _In_ const IID& iid, + _Out_ LPDWORD pdw); + +ATLAPI AtlUnadvise( + _Inout_ IUnknown* pUnkCP, + _In_ const IID& iid, + _In_ DWORD dw); + +///////////////////////////////////////////////////////////////////////////// +// IDispatch Error handling + +ATLAPI AtlSetErrorInfo( + _In_ const CLSID& clsid, + _In_z_ LPCOLESTR lpszDesc, + _In_ DWORD dwHelpID, + _In_opt_z_ LPCOLESTR lpszHelpFile, + _In_ const IID& iid, + _In_ HRESULT hRes, + _In_opt_ HINSTANCE hInst); + +///////////////////////////////////////////////////////////////////////////// +// Module + +ATLAPI AtlComModuleRegisterClassObjects( + _Inout_ _ATL_COM_MODULE* pComModule, + _In_ DWORD dwClsContext, + _In_ DWORD dwFlags); + +ATLAPI AtlComModuleRevokeClassObjects( + _Inout_ _ATL_COM_MODULE* pComModule); + +ATLAPI AtlComModuleGetClassObject( + _Inout_ _ATL_COM_MODULE* pComModule, + _In_ REFCLSID rclsid, + _In_ REFIID riid, + _Deref_out_ LPVOID* ppv); + +ATLAPI AtlRegisterClassCategoriesHelper( + _In_ REFCLSID clsid, + _In_opt_ const struct _ATL_CATMAP_ENTRY* pCatMap, + _In_ BOOL bRegister); + +ATLAPI AtlUpdateRegistryFromResourceD( + _In_ HINSTANCE hInst, + _In_z_ LPCOLESTR lpszRes, + _In_ BOOL bRegister, + _In_opt_ struct _ATL_REGMAP_ENTRY* pMapEntries, + _In_opt_ IRegistrar* pReg = NULL); + +ATLAPI AtlSetPerUserRegistration(_In_ bool bEnable); +ATLAPI AtlGetPerUserRegistration(_Out_ bool* pbEnabled); + +ATLAPI AtlLoadTypeLib( + _In_ HINSTANCE hInstTypeLib, + _In_opt_z_ LPCOLESTR lpszIndex, + _Deref_out_z_ BSTR* pbstrPath, + _Deref_out_ ITypeLib** ppTypeLib); + +ATLAPI_(DWORD) AtlGetVersion(_In_opt_ void* pReserved); + +ATLAPI AtlModuleAddTermFunc( + _Inout_ _ATL_MODULE* pModule, + _In_ _ATL_TERMFUNC* pFunc, + _In_ DWORD_PTR dw); + +ATLAPI_(void) AtlCallTermFunc(_Inout_ _ATL_MODULE* pModule); + +ATLAPI AtlWinModuleInit(_Inout_ _ATL_WIN_MODULE* pWinModule); + +ATLAPIINL AtlWinModuleTerm( + _Inout_ _ATL_WIN_MODULE* pWinModule, + _In_ HINSTANCE hInst); + +ATLAPI_(void) AtlWinModuleAddCreateWndData( + _Inout_ _ATL_WIN_MODULE* pWinModule, + _Inout_ _AtlCreateWndData* pData, + _In_ void* pObject); + +ATLAPI_(void*) AtlWinModuleExtractCreateWndData( + _Inout_opt_ _ATL_WIN_MODULE* pWinModule); + +///////////////////////////////////////////////////////////////////////////// + +ATLAPIINL AtlComModuleRegisterServer( + _Inout_ _ATL_COM_MODULE* pComModule, + _In_ BOOL bRegTypeLib, + _In_opt_ const CLSID* pCLSID = NULL); + +ATLAPIINL AtlComModuleUnregisterServer( + _Inout_ _ATL_COM_MODULE* pComModule, + _In_ BOOL bUnRegTypeLib, + _In_opt_ const CLSID* pCLSID = NULL); + +ATLAPIINL AtlRegisterTypeLib( + _In_ HINSTANCE hInstTypeLib, + _In_opt_z_ LPCOLESTR lpszIndex); + +ATLAPIINL AtlUnRegisterTypeLib( + _In_ HINSTANCE hInstTypeLib, + _In_opt_z_ LPCOLESTR lpszIndex); + +///////////////////////////////////////////////////////////////////////////// +// Get Registrar object from ATL DLL. + +#if !defined(_ATL_STATIC_REGISTRY) +#ifdef _ATL_DLL_IMPL +extern "C" HRESULT __stdcall AtlCreateRegistrar(_Deref_out_ IRegistrar** ppReg); +#else +extern "C" __declspec(dllimport) HRESULT __stdcall AtlCreateRegistrar(_Deref_out_ IRegistrar** ppReg); +#endif +#endif + +///////////////////////////////////////////////////////////////////////////// +// GUID comparison +inline BOOL WINAPI InlineIsEqualUnknown(_In_ REFGUID rguid1) +{ + return ( + ((PLONG) &rguid1)[0] == 0 && + ((PLONG) &rguid1)[1] == 0 && +#ifdef _ATL_BYTESWAP + ((PLONG) &rguid1)[2] == 0xC0000000 && + ((PLONG) &rguid1)[3] == 0x00000046); +#else + ((PLONG) &rguid1)[2] == 0x000000C0 && + ((PLONG) &rguid1)[3] == 0x46000000); +#endif +} + +template +LPCTSTR AtlDebugGetClassName(_In_opt_ T*) +{ +#ifdef _DEBUG + const _ATL_INTMAP_ENTRY* pEntries = T::_GetEntries(); + return (LPCTSTR)pEntries[-1].dw; +#else + return NULL; +#endif +} + +// Validation macro for OUT pointer +// Used in QI and CreateInstance +#define _ATL_VALIDATE_OUT_POINTER(x)\ + do { \ + ATLASSERT(x != NULL); \ + if (x == NULL) \ + return E_POINTER; \ + *x = NULL; \ + } while(0) + +///////////////////////////////////////////////////////////////////////////// +// Win32 libraries + +#ifndef _ATL_NO_DEFAULT_LIBS +#pragma comment(lib, "kernel32.lib") +#pragma comment(lib, "user32.lib") +#pragma comment(lib, "advapi32.lib") +// #pragma comment(lib, "ole32.lib") +// #pragma comment(lib, "shell32.lib") +// #pragma comment(lib, "oleaut32.lib") +// #pragma comment(lib, "uuid.lib") +// #pragma comment(lib, "shlwapi.lib") +#endif // !_ATL_NO_DEFAULT_LIBS + +template< typename T > +class CAutoVectorPtr +{ +public: + CAutoVectorPtr() throw() : + m_p( NULL ) + { + } + CAutoVectorPtr(_Inout_ CAutoVectorPtr< T >& p) throw() + { + m_p = p.Detach(); // Transfer ownership + } + explicit CAutoVectorPtr(_In_ T* p) throw() : + m_p( p ) + { + } + ~CAutoVectorPtr() throw() + { + Free(); + } + + operator T*() const throw() + { + return( m_p ); + } + + CAutoVectorPtr< T >& operator=(_Inout_ CAutoVectorPtr< T >& p) throw() + { + if(*this==p) + { + if(m_p == NULL) + { + // This branch means both two pointers are NULL, do nothing. + } + else if(this!=&p) + { + // If this assert fires, it means you attempted to assign one CAutoVectorPtr to another when they both contained + // a pointer to the same underlying vector. This means a bug in your code, since your vector will get + // double-deleted. + ATLASSERT(FALSE); + + // For safety, we are going to detach the other CAutoVectorPtr to avoid a double-free. Your code still + // has a bug, though. + p.Detach(); + } + else + { + // Alternatively, this branch means that you are assigning a CAutoVectorPtr to itself, which is + // pointless but permissible + + // nothing to do + } + } + else + { + Free(); + Attach( p.Detach() ); // Transfer ownership + } + return( *this ); + } + + // basic comparison operators + bool operator!=(_In_ CAutoVectorPtr& p) const + { + return !operator==(p); + } + + bool operator==(_In_ CAutoVectorPtr& p) const + { + return m_p==p.m_p; + } + + // Allocate the vector + bool Allocate(_In_ size_t nElements) throw() + { + ATLASSUME( m_p == NULL ); + ATLTRY( m_p = new T[nElements] ); + if( m_p == NULL ) + { + return( false ); + } + + return( true ); + } + // Attach to an existing pointer (takes ownership) + void Attach(_In_ T* p) throw() + { + ATLASSUME( m_p == NULL ); + m_p = p; + } + // Detach the pointer (releases ownership) + T* Detach() throw() + { + T* p; + + p = m_p; + m_p = NULL; + + return( p ); + } + // Delete the vector pointed to, and set the pointer to NULL + void Free() throw() + { + delete[] m_p; + m_p = NULL; + } + +public: + T* m_p; +}; + +template< typename T > +class CAutoPtr +{ +public: + CAutoPtr() throw() : + m_p( NULL ) + { + } + template< typename TSrc > + CAutoPtr(_Inout_ CAutoPtr< TSrc >& p) throw() + { + m_p = p.Detach(); // Transfer ownership + } + CAutoPtr(_Inout_ CAutoPtr< T >& p) throw() + { + m_p = p.Detach(); // Transfer ownership + } + explicit CAutoPtr(_In_ T* p) throw() : + m_p( p ) + { + } + ~CAutoPtr() throw() + { + Free(); + } + + // Templated version to allow pBase = pDerived + template< typename TSrc > + CAutoPtr< T >& operator=(_Inout_ CAutoPtr< TSrc >& p) throw() + { + if(m_p==p.m_p) + { + // This means that two CAutoPtrs of two different types had the same m_p in them + // which is never correct + ATLASSERT(FALSE); + } + else + { + Free(); + Attach( p.Detach() ); // Transfer ownership + } + return( *this ); + } + CAutoPtr< T >& operator=(_Inout_ CAutoPtr< T >& p) throw() + { + if(*this==p) + { + if(this!=&p) + { + // If this assert fires, it means you attempted to assign one CAutoPtr to another when they both contained + // a pointer to the same underlying object. This means a bug in your code, since your object will get + // double-deleted. +#ifdef ATL_AUTOPTR_ASSIGNMENT_ASSERT + ATLASSERT(FALSE); +#endif + + // For safety, we are going to detach the other CAutoPtr to avoid a double-free. Your code still + // has a bug, though. + p.Detach(); + } + else + { + // Alternatively, this branch means that you are assigning a CAutoPtr to itself, which is + // pointless but permissible + + // nothing to do + } + } + else + { + Free(); + Attach( p.Detach() ); // Transfer ownership + } + return( *this ); + } + + // basic comparison operators + bool operator!=(_In_ CAutoPtr& p) const + { + return !operator==(p); + } + + bool operator==(_In_ CAutoPtr& p) const + { + return m_p==p.m_p; + } + + operator T*() const throw() + { + return( m_p ); + } + T* operator->() const throw() + { + ATLASSUME( m_p != NULL ); + return( m_p ); + } + + // Attach to an existing pointer (takes ownership) + void Attach(_In_opt_ T* p) throw() + { + ATLASSUME( m_p == NULL ); + m_p = p; + } + // Detach the pointer (releases ownership) + T* Detach() throw() + { + T* p; + + p = m_p; + m_p = NULL; + + return( p ); + } + // Delete the object pointed to, and set the pointer to NULL + void Free() throw() + { + delete m_p; + m_p = NULL; + } + +public: + T* m_p; +}; + +/* Automatic cleanup for _malloca objects */ +template< typename T > +class CAutoStackPtr +{ +public: + CAutoStackPtr() throw() : + m_p( NULL ) + { + } + template< typename TSrc > + CAutoStackPtr(_Inout_ CAutoStackPtr< TSrc >& p) throw() + { + m_p = p.Detach(); // Transfer ownership + } + CAutoStackPtr(_Inout_ CAutoStackPtr< T >& p) throw() + { + m_p = p.Detach(); // Transfer ownership + } + explicit CAutoStackPtr(_In_opt_ T* p) throw() : + m_p( p ) + { + } + ~CAutoStackPtr() throw() + { + Free(); + } + + // Templated version to allow pBase = pDerived + template< typename TSrc > + CAutoStackPtr< T >& operator=(_Inout_ CAutoStackPtr< TSrc >& p) throw() + { + if(m_p==p.m_p) + { + // This means that two CAutoPtrs of two different types had the same m_p in them + // which is never correct + ATLASSERT(FALSE); + } + else + { + Free(); + Attach( p.Detach() ); // Transfer ownership + } + return( *this ); + } + CAutoStackPtr< T >& operator=(_Inout_ CAutoStackPtr< T >& p) throw() + { + if(*this==p) + { + if(this!=&p) + { + // If this assert fires, it means you attempted to assign one CAutoPtr to another when they both contained + // a pointer to the same underlying object. This means a bug in your code, since your object will get + // double-deleted. + ATLASSERT(FALSE); + + // For safety, we are going to detach the other CAutoPtr to avoid a double-free. Your code still + // has a bug, though. + p.Detach(); + } + else + { + // Alternatively, this branch means that you are assigning a CAutoPtr to itself, which is + // pointless but permissible + + // nothing to do + } + } + else + { + Free(); + Attach( p.Detach() ); // Transfer ownership + } + return( *this ); + } + + // basic comparison operators + bool operator!=(_In_ CAutoStackPtr& p) const + { + return !operator==(p); + } + + bool operator==(_In_ CAutoStackPtr& p) const + { + return m_p==p.m_p; + } + + operator T*() const throw() + { + return( m_p ); + } + T* operator->() const throw() + { + ATLASSUME( m_p != NULL ); + return( m_p ); + } + + // Attach to an existing pointer (takes ownership) + void Attach(_In_opt_ T* p) throw() + { + ATLASSUME( m_p == NULL ); + m_p = p; + } + // Detach the pointer (releases ownership) + T* Detach() throw() + { + T* p; + + p = m_p; + m_p = NULL; + + return( p ); + } + // Delete the object pointed to, and set the pointer to NULL + void Free() throw() + { + /* Note: _freea only actually does anything if m_p was heap allocated + If m_p was from the stack, it wouldn't be possible to actually free it here + [wrong function] unless we got inlined. But really all we do if m_p is + stack-based is ignore it and let its alloca storage disappear at the end + of the outer function. + */ + _freea(m_p); + m_p = NULL; + } + +public: + T* m_p; +}; + +// static_cast_auto template functions. Used like static_cast, only they work on CAutoPtr objects +template< class Dest, class Src > +Dest* static_cast_auto(_In_ const CAutoPtr< Src >& pSrc) throw() +{ + return( static_cast< Dest* >( static_cast< Src* >( pSrc ) ) ); +} + + +class CComAllocator +{ +public: + static void* Reallocate( + _In_opt_ void* p, + _In_ size_t nBytes) throw() + { +#ifdef _WIN64 + if( nBytes > INT_MAX ) + { + return( NULL ); + } +#endif + return ::CoTaskMemRealloc(p, ULONG(nBytes)); + } + static void* Allocate(_In_ size_t nBytes) throw() + { +#ifdef _WIN64 + if( nBytes > INT_MAX ) + { + return( NULL ); + } +#endif + return ::CoTaskMemAlloc(ULONG(nBytes)); + } + static void Free(_In_opt_ void* p) throw() + { + ::CoTaskMemFree(p); + } +}; + +template +class CComHeapPtr : + public CHeapPtr +{ +public: + CComHeapPtr() throw() + { + } + + explicit CComHeapPtr(_In_ T* pData) throw() : + CHeapPtr(pData) + { + } +}; + +template +_Ret_opt_count_(cEls) T* AtlSafeRealloc( + _In_opt_ T* pT, + _In_ size_t cEls) throw() +{ + T* pTemp; + + size_t nBytes=0; + if(FAILED(::ATL::AtlMultiply(&nBytes, cEls, sizeof(T)))) + { + return NULL; + } + pTemp = static_cast(Reallocator::Reallocate(pT, nBytes)); + if (pTemp == NULL) + { + Reallocator::Free(pT); + return NULL; + } + pT = pTemp; + return pTemp; +} + +class CHandle +{ +public: + CHandle() throw(); + CHandle(_Inout_ CHandle& h) throw(); + explicit CHandle(_In_ HANDLE h) throw(); + ~CHandle() throw(); + + CHandle& operator=(_Inout_ CHandle& h) throw(); + + operator HANDLE() const throw(); + + // Attach to an existing handle (takes ownership). + void Attach(_In_ HANDLE h) throw(); + // Detach the handle from the object (releases ownership). + HANDLE Detach() throw(); + + // Close the handle. + void Close() throw(); + +public: + HANDLE m_h; +}; + +inline CHandle::CHandle() throw() : + m_h( NULL ) +{ +} + +inline CHandle::CHandle(_Inout_ CHandle& h) throw() : + m_h( NULL ) +{ + Attach( h.Detach() ); +} + +inline CHandle::CHandle(_In_ HANDLE h) throw() : + m_h( h ) +{ +} + +inline CHandle::~CHandle() throw() +{ + if( m_h != NULL ) + { + Close(); + } +} + +inline CHandle& CHandle::operator=(_Inout_ CHandle& h) throw() +{ + if( this != &h ) + { + if( m_h != NULL ) + { + Close(); + } + Attach( h.Detach() ); + } + + return( *this ); +} + +inline CHandle::operator HANDLE() const throw() +{ + return( m_h ); +} + +inline void CHandle::Attach(_In_ HANDLE h) throw() +{ + ATLASSUME( m_h == NULL ); + m_h = h; // Take ownership +} + +inline HANDLE CHandle::Detach() throw() +{ + HANDLE h; + + h = m_h; // Release ownership + m_h = NULL; + + return( h ); +} + +inline void CHandle::Close() throw() +{ + if( m_h != NULL ) + { + ::CloseHandle( m_h ); + m_h = NULL; + } +} + +class CCritSecLock +{ +public: + CCritSecLock( + _Inout_ CRITICAL_SECTION& cs, + _In_ bool bInitialLock = true); + ~CCritSecLock() throw(); + + void Lock(); + void Unlock() throw(); + +// Implementation +private: + CRITICAL_SECTION& m_cs; + bool m_bLocked; + +// Private to avoid accidental use + CCritSecLock(_In_ const CCritSecLock&) throw(); + CCritSecLock& operator=(_In_ const CCritSecLock&) throw(); +}; + +inline CCritSecLock::CCritSecLock( + _Inout_ CRITICAL_SECTION& cs, + _In_ bool bInitialLock) : + m_cs( cs ), + m_bLocked( false ) +{ + if( bInitialLock ) + { + Lock(); + } +} + +inline CCritSecLock::~CCritSecLock() throw() +{ + if( m_bLocked ) + { + Unlock(); + } +} + +inline void CCritSecLock::Lock() +{ + ATLASSERT( !m_bLocked ); + + ::EnterCriticalSection( &m_cs ); + m_bLocked = true; +} + +inline void CCritSecLock::Unlock() throw() +{ + ATLASSUME( m_bLocked ); + ::LeaveCriticalSection( &m_cs ); + m_bLocked = false; +} + +///////////////////////////////////////////////////////////////////////////// +// Interface debugging +#if defined(_ATL_DEBUG_INTERFACES) || defined(_ATL_DEBUG_QI) +HRESULT WINAPI AtlDumpIID( + _In_ REFIID iid, + _In_z_ LPCTSTR pszClassName, + _In_ HRESULT hr) throw(); +#endif // _ATL_DEBUG_INTERFACES || _ATL_DEBUG_QI + +#ifdef _ATL_DEBUG_INTERFACES + +struct _QIThunk +{ + STDMETHOD(QueryInterface)( + _In_ REFIID iid, + _Deref_out_ void** pp) + { + ATLASSUME(m_dwRef >= 0); + ATLASSUME(m_pUnk != NULL); + return m_pUnk->QueryInterface(iid, pp); + } + STDMETHOD_(ULONG, AddRef)() + { + ATLASSUME(m_pUnk != NULL); + if (m_bBreak) + DebugBreak(); + m_pUnk->AddRef(); + return InternalAddRef(); + } + ULONG InternalAddRef() + { + ATLASSUME(m_pUnk != NULL); + if (m_bBreak) + DebugBreak(); + ATLASSUME(m_dwRef >= 0); + long l = InterlockedIncrement(&m_dwRef); + + TCHAR buf[512+1]; + _stprintf_s(buf, _countof(buf), _T("QIThunk - %-10d\tAddRef :\tObject = 0x%p\tRefcount = %d\t"), + m_nIndex, m_pUnk, m_dwRef); + buf[_countof(buf)-1] = 0; + OutputDebugString(buf); + AtlDumpIID(m_iid, m_lpszClassName, S_OK); + + if (l > m_dwMaxRef) + m_dwMaxRef = l; + return l; + } + STDMETHOD_(ULONG, Release)(); + + STDMETHOD(f3)(); + STDMETHOD(f4)(); + STDMETHOD(f5)(); + STDMETHOD(f6)(); + STDMETHOD(f7)(); + STDMETHOD(f8)(); + STDMETHOD(f9)(); + STDMETHOD(f10)(); + STDMETHOD(f11)(); + STDMETHOD(f12)(); + STDMETHOD(f13)(); + STDMETHOD(f14)(); + STDMETHOD(f15)(); + STDMETHOD(f16)(); + STDMETHOD(f17)(); + STDMETHOD(f18)(); + STDMETHOD(f19)(); + STDMETHOD(f20)(); + STDMETHOD(f21)(); + STDMETHOD(f22)(); + STDMETHOD(f23)(); + STDMETHOD(f24)(); + STDMETHOD(f25)(); + STDMETHOD(f26)(); + STDMETHOD(f27)(); + STDMETHOD(f28)(); + STDMETHOD(f29)(); + STDMETHOD(f30)(); + STDMETHOD(f31)(); + STDMETHOD(f32)(); + STDMETHOD(f33)(); + STDMETHOD(f34)(); + STDMETHOD(f35)(); + STDMETHOD(f36)(); + STDMETHOD(f37)(); + STDMETHOD(f38)(); + STDMETHOD(f39)(); + STDMETHOD(f40)(); + STDMETHOD(f41)(); + STDMETHOD(f42)(); + STDMETHOD(f43)(); + STDMETHOD(f44)(); + STDMETHOD(f45)(); + STDMETHOD(f46)(); + STDMETHOD(f47)(); + STDMETHOD(f48)(); + STDMETHOD(f49)(); + STDMETHOD(f50)(); + STDMETHOD(f51)(); + STDMETHOD(f52)(); + STDMETHOD(f53)(); + STDMETHOD(f54)(); + STDMETHOD(f55)(); + STDMETHOD(f56)(); + STDMETHOD(f57)(); + STDMETHOD(f58)(); + STDMETHOD(f59)(); + STDMETHOD(f60)(); + STDMETHOD(f61)(); + STDMETHOD(f62)(); + STDMETHOD(f63)(); + STDMETHOD(f64)(); + STDMETHOD(f65)(); + STDMETHOD(f66)(); + STDMETHOD(f67)(); + STDMETHOD(f68)(); + STDMETHOD(f69)(); + STDMETHOD(f70)(); + STDMETHOD(f71)(); + STDMETHOD(f72)(); + STDMETHOD(f73)(); + STDMETHOD(f74)(); + STDMETHOD(f75)(); + STDMETHOD(f76)(); + STDMETHOD(f77)(); + STDMETHOD(f78)(); + STDMETHOD(f79)(); + STDMETHOD(f80)(); + STDMETHOD(f81)(); + STDMETHOD(f82)(); + STDMETHOD(f83)(); + STDMETHOD(f84)(); + STDMETHOD(f85)(); + STDMETHOD(f86)(); + STDMETHOD(f87)(); + STDMETHOD(f88)(); + STDMETHOD(f89)(); + STDMETHOD(f90)(); + STDMETHOD(f91)(); + STDMETHOD(f92)(); + STDMETHOD(f93)(); + STDMETHOD(f94)(); + STDMETHOD(f95)(); + STDMETHOD(f96)(); + STDMETHOD(f97)(); + STDMETHOD(f98)(); + STDMETHOD(f99)(); + STDMETHOD(f100)(); + STDMETHOD(f101)(); + STDMETHOD(f102)(); + STDMETHOD(f103)(); + STDMETHOD(f104)(); + STDMETHOD(f105)(); + STDMETHOD(f106)(); + STDMETHOD(f107)(); + STDMETHOD(f108)(); + STDMETHOD(f109)(); + STDMETHOD(f110)(); + STDMETHOD(f111)(); + STDMETHOD(f112)(); + STDMETHOD(f113)(); + STDMETHOD(f114)(); + STDMETHOD(f115)(); + STDMETHOD(f116)(); + STDMETHOD(f117)(); + STDMETHOD(f118)(); + STDMETHOD(f119)(); + STDMETHOD(f120)(); + STDMETHOD(f121)(); + STDMETHOD(f122)(); + STDMETHOD(f123)(); + STDMETHOD(f124)(); + STDMETHOD(f125)(); + STDMETHOD(f126)(); + STDMETHOD(f127)(); + STDMETHOD(f128)(); + STDMETHOD(f129)(); + STDMETHOD(f130)(); + STDMETHOD(f131)(); + STDMETHOD(f132)(); + STDMETHOD(f133)(); + STDMETHOD(f134)(); + STDMETHOD(f135)(); + STDMETHOD(f136)(); + STDMETHOD(f137)(); + STDMETHOD(f138)(); + STDMETHOD(f139)(); + STDMETHOD(f140)(); + STDMETHOD(f141)(); + STDMETHOD(f142)(); + STDMETHOD(f143)(); + STDMETHOD(f144)(); + STDMETHOD(f145)(); + STDMETHOD(f146)(); + STDMETHOD(f147)(); + STDMETHOD(f148)(); + STDMETHOD(f149)(); + STDMETHOD(f150)(); + STDMETHOD(f151)(); + STDMETHOD(f152)(); + STDMETHOD(f153)(); + STDMETHOD(f154)(); + STDMETHOD(f155)(); + STDMETHOD(f156)(); + STDMETHOD(f157)(); + STDMETHOD(f158)(); + STDMETHOD(f159)(); + STDMETHOD(f160)(); + STDMETHOD(f161)(); + STDMETHOD(f162)(); + STDMETHOD(f163)(); + STDMETHOD(f164)(); + STDMETHOD(f165)(); + STDMETHOD(f166)(); + STDMETHOD(f167)(); + STDMETHOD(f168)(); + STDMETHOD(f169)(); + STDMETHOD(f170)(); + STDMETHOD(f171)(); + STDMETHOD(f172)(); + STDMETHOD(f173)(); + STDMETHOD(f174)(); + STDMETHOD(f175)(); + STDMETHOD(f176)(); + STDMETHOD(f177)(); + STDMETHOD(f178)(); + STDMETHOD(f179)(); + STDMETHOD(f180)(); + STDMETHOD(f181)(); + STDMETHOD(f182)(); + STDMETHOD(f183)(); + STDMETHOD(f184)(); + STDMETHOD(f185)(); + STDMETHOD(f186)(); + STDMETHOD(f187)(); + STDMETHOD(f188)(); + STDMETHOD(f189)(); + STDMETHOD(f190)(); + STDMETHOD(f191)(); + STDMETHOD(f192)(); + STDMETHOD(f193)(); + STDMETHOD(f194)(); + STDMETHOD(f195)(); + STDMETHOD(f196)(); + STDMETHOD(f197)(); + STDMETHOD(f198)(); + STDMETHOD(f199)(); + STDMETHOD(f200)(); + STDMETHOD(f201)(); + STDMETHOD(f202)(); + STDMETHOD(f203)(); + STDMETHOD(f204)(); + STDMETHOD(f205)(); + STDMETHOD(f206)(); + STDMETHOD(f207)(); + STDMETHOD(f208)(); + STDMETHOD(f209)(); + STDMETHOD(f210)(); + STDMETHOD(f211)(); + STDMETHOD(f212)(); + STDMETHOD(f213)(); + STDMETHOD(f214)(); + STDMETHOD(f215)(); + STDMETHOD(f216)(); + STDMETHOD(f217)(); + STDMETHOD(f218)(); + STDMETHOD(f219)(); + STDMETHOD(f220)(); + STDMETHOD(f221)(); + STDMETHOD(f222)(); + STDMETHOD(f223)(); + STDMETHOD(f224)(); + STDMETHOD(f225)(); + STDMETHOD(f226)(); + STDMETHOD(f227)(); + STDMETHOD(f228)(); + STDMETHOD(f229)(); + STDMETHOD(f230)(); + STDMETHOD(f231)(); + STDMETHOD(f232)(); + STDMETHOD(f233)(); + STDMETHOD(f234)(); + STDMETHOD(f235)(); + STDMETHOD(f236)(); + STDMETHOD(f237)(); + STDMETHOD(f238)(); + STDMETHOD(f239)(); + STDMETHOD(f240)(); + STDMETHOD(f241)(); + STDMETHOD(f242)(); + STDMETHOD(f243)(); + STDMETHOD(f244)(); + STDMETHOD(f245)(); + STDMETHOD(f246)(); + STDMETHOD(f247)(); + STDMETHOD(f248)(); + STDMETHOD(f249)(); + STDMETHOD(f250)(); + STDMETHOD(f251)(); + STDMETHOD(f252)(); + STDMETHOD(f253)(); + STDMETHOD(f254)(); + STDMETHOD(f255)(); + STDMETHOD(f256)(); + STDMETHOD(f257)(); + STDMETHOD(f258)(); + STDMETHOD(f259)(); + STDMETHOD(f260)(); + STDMETHOD(f261)(); + STDMETHOD(f262)(); + STDMETHOD(f263)(); + STDMETHOD(f264)(); + STDMETHOD(f265)(); + STDMETHOD(f266)(); + STDMETHOD(f267)(); + STDMETHOD(f268)(); + STDMETHOD(f269)(); + STDMETHOD(f270)(); + STDMETHOD(f271)(); + STDMETHOD(f272)(); + STDMETHOD(f273)(); + STDMETHOD(f274)(); + STDMETHOD(f275)(); + STDMETHOD(f276)(); + STDMETHOD(f277)(); + STDMETHOD(f278)(); + STDMETHOD(f279)(); + STDMETHOD(f280)(); + STDMETHOD(f281)(); + STDMETHOD(f282)(); + STDMETHOD(f283)(); + STDMETHOD(f284)(); + STDMETHOD(f285)(); + STDMETHOD(f286)(); + STDMETHOD(f287)(); + STDMETHOD(f288)(); + STDMETHOD(f289)(); + STDMETHOD(f290)(); + STDMETHOD(f291)(); + STDMETHOD(f292)(); + STDMETHOD(f293)(); + STDMETHOD(f294)(); + STDMETHOD(f295)(); + STDMETHOD(f296)(); + STDMETHOD(f297)(); + STDMETHOD(f298)(); + STDMETHOD(f299)(); + STDMETHOD(f300)(); + STDMETHOD(f301)(); + STDMETHOD(f302)(); + STDMETHOD(f303)(); + STDMETHOD(f304)(); + STDMETHOD(f305)(); + STDMETHOD(f306)(); + STDMETHOD(f307)(); + STDMETHOD(f308)(); + STDMETHOD(f309)(); + STDMETHOD(f310)(); + STDMETHOD(f311)(); + STDMETHOD(f312)(); + STDMETHOD(f313)(); + STDMETHOD(f314)(); + STDMETHOD(f315)(); + STDMETHOD(f316)(); + STDMETHOD(f317)(); + STDMETHOD(f318)(); + STDMETHOD(f319)(); + STDMETHOD(f320)(); + STDMETHOD(f321)(); + STDMETHOD(f322)(); + STDMETHOD(f323)(); + STDMETHOD(f324)(); + STDMETHOD(f325)(); + STDMETHOD(f326)(); + STDMETHOD(f327)(); + STDMETHOD(f328)(); + STDMETHOD(f329)(); + STDMETHOD(f330)(); + STDMETHOD(f331)(); + STDMETHOD(f332)(); + STDMETHOD(f333)(); + STDMETHOD(f334)(); + STDMETHOD(f335)(); + STDMETHOD(f336)(); + STDMETHOD(f337)(); + STDMETHOD(f338)(); + STDMETHOD(f339)(); + STDMETHOD(f340)(); + STDMETHOD(f341)(); + STDMETHOD(f342)(); + STDMETHOD(f343)(); + STDMETHOD(f344)(); + STDMETHOD(f345)(); + STDMETHOD(f346)(); + STDMETHOD(f347)(); + STDMETHOD(f348)(); + STDMETHOD(f349)(); + STDMETHOD(f350)(); + STDMETHOD(f351)(); + STDMETHOD(f352)(); + STDMETHOD(f353)(); + STDMETHOD(f354)(); + STDMETHOD(f355)(); + STDMETHOD(f356)(); + STDMETHOD(f357)(); + STDMETHOD(f358)(); + STDMETHOD(f359)(); + STDMETHOD(f360)(); + STDMETHOD(f361)(); + STDMETHOD(f362)(); + STDMETHOD(f363)(); + STDMETHOD(f364)(); + STDMETHOD(f365)(); + STDMETHOD(f366)(); + STDMETHOD(f367)(); + STDMETHOD(f368)(); + STDMETHOD(f369)(); + STDMETHOD(f370)(); + STDMETHOD(f371)(); + STDMETHOD(f372)(); + STDMETHOD(f373)(); + STDMETHOD(f374)(); + STDMETHOD(f375)(); + STDMETHOD(f376)(); + STDMETHOD(f377)(); + STDMETHOD(f378)(); + STDMETHOD(f379)(); + STDMETHOD(f380)(); + STDMETHOD(f381)(); + STDMETHOD(f382)(); + STDMETHOD(f383)(); + STDMETHOD(f384)(); + STDMETHOD(f385)(); + STDMETHOD(f386)(); + STDMETHOD(f387)(); + STDMETHOD(f388)(); + STDMETHOD(f389)(); + STDMETHOD(f390)(); + STDMETHOD(f391)(); + STDMETHOD(f392)(); + STDMETHOD(f393)(); + STDMETHOD(f394)(); + STDMETHOD(f395)(); + STDMETHOD(f396)(); + STDMETHOD(f397)(); + STDMETHOD(f398)(); + STDMETHOD(f399)(); + STDMETHOD(f400)(); + STDMETHOD(f401)(); + STDMETHOD(f402)(); + STDMETHOD(f403)(); + STDMETHOD(f404)(); + STDMETHOD(f405)(); + STDMETHOD(f406)(); + STDMETHOD(f407)(); + STDMETHOD(f408)(); + STDMETHOD(f409)(); + STDMETHOD(f410)(); + STDMETHOD(f411)(); + STDMETHOD(f412)(); + STDMETHOD(f413)(); + STDMETHOD(f414)(); + STDMETHOD(f415)(); + STDMETHOD(f416)(); + STDMETHOD(f417)(); + STDMETHOD(f418)(); + STDMETHOD(f419)(); + STDMETHOD(f420)(); + STDMETHOD(f421)(); + STDMETHOD(f422)(); + STDMETHOD(f423)(); + STDMETHOD(f424)(); + STDMETHOD(f425)(); + STDMETHOD(f426)(); + STDMETHOD(f427)(); + STDMETHOD(f428)(); + STDMETHOD(f429)(); + STDMETHOD(f430)(); + STDMETHOD(f431)(); + STDMETHOD(f432)(); + STDMETHOD(f433)(); + STDMETHOD(f434)(); + STDMETHOD(f435)(); + STDMETHOD(f436)(); + STDMETHOD(f437)(); + STDMETHOD(f438)(); + STDMETHOD(f439)(); + STDMETHOD(f440)(); + STDMETHOD(f441)(); + STDMETHOD(f442)(); + STDMETHOD(f443)(); + STDMETHOD(f444)(); + STDMETHOD(f445)(); + STDMETHOD(f446)(); + STDMETHOD(f447)(); + STDMETHOD(f448)(); + STDMETHOD(f449)(); + STDMETHOD(f450)(); + STDMETHOD(f451)(); + STDMETHOD(f452)(); + STDMETHOD(f453)(); + STDMETHOD(f454)(); + STDMETHOD(f455)(); + STDMETHOD(f456)(); + STDMETHOD(f457)(); + STDMETHOD(f458)(); + STDMETHOD(f459)(); + STDMETHOD(f460)(); + STDMETHOD(f461)(); + STDMETHOD(f462)(); + STDMETHOD(f463)(); + STDMETHOD(f464)(); + STDMETHOD(f465)(); + STDMETHOD(f466)(); + STDMETHOD(f467)(); + STDMETHOD(f468)(); + STDMETHOD(f469)(); + STDMETHOD(f470)(); + STDMETHOD(f471)(); + STDMETHOD(f472)(); + STDMETHOD(f473)(); + STDMETHOD(f474)(); + STDMETHOD(f475)(); + STDMETHOD(f476)(); + STDMETHOD(f477)(); + STDMETHOD(f478)(); + STDMETHOD(f479)(); + STDMETHOD(f480)(); + STDMETHOD(f481)(); + STDMETHOD(f482)(); + STDMETHOD(f483)(); + STDMETHOD(f484)(); + STDMETHOD(f485)(); + STDMETHOD(f486)(); + STDMETHOD(f487)(); + STDMETHOD(f488)(); + STDMETHOD(f489)(); + STDMETHOD(f490)(); + STDMETHOD(f491)(); + STDMETHOD(f492)(); + STDMETHOD(f493)(); + STDMETHOD(f494)(); + STDMETHOD(f495)(); + STDMETHOD(f496)(); + STDMETHOD(f497)(); + STDMETHOD(f498)(); + STDMETHOD(f499)(); + STDMETHOD(f500)(); + STDMETHOD(f501)(); + STDMETHOD(f502)(); + STDMETHOD(f503)(); + STDMETHOD(f504)(); + STDMETHOD(f505)(); + STDMETHOD(f506)(); + STDMETHOD(f507)(); + STDMETHOD(f508)(); + STDMETHOD(f509)(); + STDMETHOD(f510)(); + STDMETHOD(f511)(); + STDMETHOD(f512)(); + STDMETHOD(f513)(); + STDMETHOD(f514)(); + STDMETHOD(f515)(); + STDMETHOD(f516)(); + STDMETHOD(f517)(); + STDMETHOD(f518)(); + STDMETHOD(f519)(); + STDMETHOD(f520)(); + STDMETHOD(f521)(); + STDMETHOD(f522)(); + STDMETHOD(f523)(); + STDMETHOD(f524)(); + STDMETHOD(f525)(); + STDMETHOD(f526)(); + STDMETHOD(f527)(); + STDMETHOD(f528)(); + STDMETHOD(f529)(); + STDMETHOD(f530)(); + STDMETHOD(f531)(); + STDMETHOD(f532)(); + STDMETHOD(f533)(); + STDMETHOD(f534)(); + STDMETHOD(f535)(); + STDMETHOD(f536)(); + STDMETHOD(f537)(); + STDMETHOD(f538)(); + STDMETHOD(f539)(); + STDMETHOD(f540)(); + STDMETHOD(f541)(); + STDMETHOD(f542)(); + STDMETHOD(f543)(); + STDMETHOD(f544)(); + STDMETHOD(f545)(); + STDMETHOD(f546)(); + STDMETHOD(f547)(); + STDMETHOD(f548)(); + STDMETHOD(f549)(); + STDMETHOD(f550)(); + STDMETHOD(f551)(); + STDMETHOD(f552)(); + STDMETHOD(f553)(); + STDMETHOD(f554)(); + STDMETHOD(f555)(); + STDMETHOD(f556)(); + STDMETHOD(f557)(); + STDMETHOD(f558)(); + STDMETHOD(f559)(); + STDMETHOD(f560)(); + STDMETHOD(f561)(); + STDMETHOD(f562)(); + STDMETHOD(f563)(); + STDMETHOD(f564)(); + STDMETHOD(f565)(); + STDMETHOD(f566)(); + STDMETHOD(f567)(); + STDMETHOD(f568)(); + STDMETHOD(f569)(); + STDMETHOD(f570)(); + STDMETHOD(f571)(); + STDMETHOD(f572)(); + STDMETHOD(f573)(); + STDMETHOD(f574)(); + STDMETHOD(f575)(); + STDMETHOD(f576)(); + STDMETHOD(f577)(); + STDMETHOD(f578)(); + STDMETHOD(f579)(); + STDMETHOD(f580)(); + STDMETHOD(f581)(); + STDMETHOD(f582)(); + STDMETHOD(f583)(); + STDMETHOD(f584)(); + STDMETHOD(f585)(); + STDMETHOD(f586)(); + STDMETHOD(f587)(); + STDMETHOD(f588)(); + STDMETHOD(f589)(); + STDMETHOD(f590)(); + STDMETHOD(f591)(); + STDMETHOD(f592)(); + STDMETHOD(f593)(); + STDMETHOD(f594)(); + STDMETHOD(f595)(); + STDMETHOD(f596)(); + STDMETHOD(f597)(); + STDMETHOD(f598)(); + STDMETHOD(f599)(); + STDMETHOD(f600)(); + STDMETHOD(f601)(); + STDMETHOD(f602)(); + STDMETHOD(f603)(); + STDMETHOD(f604)(); + STDMETHOD(f605)(); + STDMETHOD(f606)(); + STDMETHOD(f607)(); + STDMETHOD(f608)(); + STDMETHOD(f609)(); + STDMETHOD(f610)(); + STDMETHOD(f611)(); + STDMETHOD(f612)(); + STDMETHOD(f613)(); + STDMETHOD(f614)(); + STDMETHOD(f615)(); + STDMETHOD(f616)(); + STDMETHOD(f617)(); + STDMETHOD(f618)(); + STDMETHOD(f619)(); + STDMETHOD(f620)(); + STDMETHOD(f621)(); + STDMETHOD(f622)(); + STDMETHOD(f623)(); + STDMETHOD(f624)(); + STDMETHOD(f625)(); + STDMETHOD(f626)(); + STDMETHOD(f627)(); + STDMETHOD(f628)(); + STDMETHOD(f629)(); + STDMETHOD(f630)(); + STDMETHOD(f631)(); + STDMETHOD(f632)(); + STDMETHOD(f633)(); + STDMETHOD(f634)(); + STDMETHOD(f635)(); + STDMETHOD(f636)(); + STDMETHOD(f637)(); + STDMETHOD(f638)(); + STDMETHOD(f639)(); + STDMETHOD(f640)(); + STDMETHOD(f641)(); + STDMETHOD(f642)(); + STDMETHOD(f643)(); + STDMETHOD(f644)(); + STDMETHOD(f645)(); + STDMETHOD(f646)(); + STDMETHOD(f647)(); + STDMETHOD(f648)(); + STDMETHOD(f649)(); + STDMETHOD(f650)(); + STDMETHOD(f651)(); + STDMETHOD(f652)(); + STDMETHOD(f653)(); + STDMETHOD(f654)(); + STDMETHOD(f655)(); + STDMETHOD(f656)(); + STDMETHOD(f657)(); + STDMETHOD(f658)(); + STDMETHOD(f659)(); + STDMETHOD(f660)(); + STDMETHOD(f661)(); + STDMETHOD(f662)(); + STDMETHOD(f663)(); + STDMETHOD(f664)(); + STDMETHOD(f665)(); + STDMETHOD(f666)(); + STDMETHOD(f667)(); + STDMETHOD(f668)(); + STDMETHOD(f669)(); + STDMETHOD(f670)(); + STDMETHOD(f671)(); + STDMETHOD(f672)(); + STDMETHOD(f673)(); + STDMETHOD(f674)(); + STDMETHOD(f675)(); + STDMETHOD(f676)(); + STDMETHOD(f677)(); + STDMETHOD(f678)(); + STDMETHOD(f679)(); + STDMETHOD(f680)(); + STDMETHOD(f681)(); + STDMETHOD(f682)(); + STDMETHOD(f683)(); + STDMETHOD(f684)(); + STDMETHOD(f685)(); + STDMETHOD(f686)(); + STDMETHOD(f687)(); + STDMETHOD(f688)(); + STDMETHOD(f689)(); + STDMETHOD(f690)(); + STDMETHOD(f691)(); + STDMETHOD(f692)(); + STDMETHOD(f693)(); + STDMETHOD(f694)(); + STDMETHOD(f695)(); + STDMETHOD(f696)(); + STDMETHOD(f697)(); + STDMETHOD(f698)(); + STDMETHOD(f699)(); + STDMETHOD(f700)(); + STDMETHOD(f701)(); + STDMETHOD(f702)(); + STDMETHOD(f703)(); + STDMETHOD(f704)(); + STDMETHOD(f705)(); + STDMETHOD(f706)(); + STDMETHOD(f707)(); + STDMETHOD(f708)(); + STDMETHOD(f709)(); + STDMETHOD(f710)(); + STDMETHOD(f711)(); + STDMETHOD(f712)(); + STDMETHOD(f713)(); + STDMETHOD(f714)(); + STDMETHOD(f715)(); + STDMETHOD(f716)(); + STDMETHOD(f717)(); + STDMETHOD(f718)(); + STDMETHOD(f719)(); + STDMETHOD(f720)(); + STDMETHOD(f721)(); + STDMETHOD(f722)(); + STDMETHOD(f723)(); + STDMETHOD(f724)(); + STDMETHOD(f725)(); + STDMETHOD(f726)(); + STDMETHOD(f727)(); + STDMETHOD(f728)(); + STDMETHOD(f729)(); + STDMETHOD(f730)(); + STDMETHOD(f731)(); + STDMETHOD(f732)(); + STDMETHOD(f733)(); + STDMETHOD(f734)(); + STDMETHOD(f735)(); + STDMETHOD(f736)(); + STDMETHOD(f737)(); + STDMETHOD(f738)(); + STDMETHOD(f739)(); + STDMETHOD(f740)(); + STDMETHOD(f741)(); + STDMETHOD(f742)(); + STDMETHOD(f743)(); + STDMETHOD(f744)(); + STDMETHOD(f745)(); + STDMETHOD(f746)(); + STDMETHOD(f747)(); + STDMETHOD(f748)(); + STDMETHOD(f749)(); + STDMETHOD(f750)(); + STDMETHOD(f751)(); + STDMETHOD(f752)(); + STDMETHOD(f753)(); + STDMETHOD(f754)(); + STDMETHOD(f755)(); + STDMETHOD(f756)(); + STDMETHOD(f757)(); + STDMETHOD(f758)(); + STDMETHOD(f759)(); + STDMETHOD(f760)(); + STDMETHOD(f761)(); + STDMETHOD(f762)(); + STDMETHOD(f763)(); + STDMETHOD(f764)(); + STDMETHOD(f765)(); + STDMETHOD(f766)(); + STDMETHOD(f767)(); + STDMETHOD(f768)(); + STDMETHOD(f769)(); + STDMETHOD(f770)(); + STDMETHOD(f771)(); + STDMETHOD(f772)(); + STDMETHOD(f773)(); + STDMETHOD(f774)(); + STDMETHOD(f775)(); + STDMETHOD(f776)(); + STDMETHOD(f777)(); + STDMETHOD(f778)(); + STDMETHOD(f779)(); + STDMETHOD(f780)(); + STDMETHOD(f781)(); + STDMETHOD(f782)(); + STDMETHOD(f783)(); + STDMETHOD(f784)(); + STDMETHOD(f785)(); + STDMETHOD(f786)(); + STDMETHOD(f787)(); + STDMETHOD(f788)(); + STDMETHOD(f789)(); + STDMETHOD(f790)(); + STDMETHOD(f791)(); + STDMETHOD(f792)(); + STDMETHOD(f793)(); + STDMETHOD(f794)(); + STDMETHOD(f795)(); + STDMETHOD(f796)(); + STDMETHOD(f797)(); + STDMETHOD(f798)(); + STDMETHOD(f799)(); + STDMETHOD(f800)(); + STDMETHOD(f801)(); + STDMETHOD(f802)(); + STDMETHOD(f803)(); + STDMETHOD(f804)(); + STDMETHOD(f805)(); + STDMETHOD(f806)(); + STDMETHOD(f807)(); + STDMETHOD(f808)(); + STDMETHOD(f809)(); + STDMETHOD(f810)(); + STDMETHOD(f811)(); + STDMETHOD(f812)(); + STDMETHOD(f813)(); + STDMETHOD(f814)(); + STDMETHOD(f815)(); + STDMETHOD(f816)(); + STDMETHOD(f817)(); + STDMETHOD(f818)(); + STDMETHOD(f819)(); + STDMETHOD(f820)(); + STDMETHOD(f821)(); + STDMETHOD(f822)(); + STDMETHOD(f823)(); + STDMETHOD(f824)(); + STDMETHOD(f825)(); + STDMETHOD(f826)(); + STDMETHOD(f827)(); + STDMETHOD(f828)(); + STDMETHOD(f829)(); + STDMETHOD(f830)(); + STDMETHOD(f831)(); + STDMETHOD(f832)(); + STDMETHOD(f833)(); + STDMETHOD(f834)(); + STDMETHOD(f835)(); + STDMETHOD(f836)(); + STDMETHOD(f837)(); + STDMETHOD(f838)(); + STDMETHOD(f839)(); + STDMETHOD(f840)(); + STDMETHOD(f841)(); + STDMETHOD(f842)(); + STDMETHOD(f843)(); + STDMETHOD(f844)(); + STDMETHOD(f845)(); + STDMETHOD(f846)(); + STDMETHOD(f847)(); + STDMETHOD(f848)(); + STDMETHOD(f849)(); + STDMETHOD(f850)(); + STDMETHOD(f851)(); + STDMETHOD(f852)(); + STDMETHOD(f853)(); + STDMETHOD(f854)(); + STDMETHOD(f855)(); + STDMETHOD(f856)(); + STDMETHOD(f857)(); + STDMETHOD(f858)(); + STDMETHOD(f859)(); + STDMETHOD(f860)(); + STDMETHOD(f861)(); + STDMETHOD(f862)(); + STDMETHOD(f863)(); + STDMETHOD(f864)(); + STDMETHOD(f865)(); + STDMETHOD(f866)(); + STDMETHOD(f867)(); + STDMETHOD(f868)(); + STDMETHOD(f869)(); + STDMETHOD(f870)(); + STDMETHOD(f871)(); + STDMETHOD(f872)(); + STDMETHOD(f873)(); + STDMETHOD(f874)(); + STDMETHOD(f875)(); + STDMETHOD(f876)(); + STDMETHOD(f877)(); + STDMETHOD(f878)(); + STDMETHOD(f879)(); + STDMETHOD(f880)(); + STDMETHOD(f881)(); + STDMETHOD(f882)(); + STDMETHOD(f883)(); + STDMETHOD(f884)(); + STDMETHOD(f885)(); + STDMETHOD(f886)(); + STDMETHOD(f887)(); + STDMETHOD(f888)(); + STDMETHOD(f889)(); + STDMETHOD(f890)(); + STDMETHOD(f891)(); + STDMETHOD(f892)(); + STDMETHOD(f893)(); + STDMETHOD(f894)(); + STDMETHOD(f895)(); + STDMETHOD(f896)(); + STDMETHOD(f897)(); + STDMETHOD(f898)(); + STDMETHOD(f899)(); + STDMETHOD(f900)(); + STDMETHOD(f901)(); + STDMETHOD(f902)(); + STDMETHOD(f903)(); + STDMETHOD(f904)(); + STDMETHOD(f905)(); + STDMETHOD(f906)(); + STDMETHOD(f907)(); + STDMETHOD(f908)(); + STDMETHOD(f909)(); + STDMETHOD(f910)(); + STDMETHOD(f911)(); + STDMETHOD(f912)(); + STDMETHOD(f913)(); + STDMETHOD(f914)(); + STDMETHOD(f915)(); + STDMETHOD(f916)(); + STDMETHOD(f917)(); + STDMETHOD(f918)(); + STDMETHOD(f919)(); + STDMETHOD(f920)(); + STDMETHOD(f921)(); + STDMETHOD(f922)(); + STDMETHOD(f923)(); + STDMETHOD(f924)(); + STDMETHOD(f925)(); + STDMETHOD(f926)(); + STDMETHOD(f927)(); + STDMETHOD(f928)(); + STDMETHOD(f929)(); + STDMETHOD(f930)(); + STDMETHOD(f931)(); + STDMETHOD(f932)(); + STDMETHOD(f933)(); + STDMETHOD(f934)(); + STDMETHOD(f935)(); + STDMETHOD(f936)(); + STDMETHOD(f937)(); + STDMETHOD(f938)(); + STDMETHOD(f939)(); + STDMETHOD(f940)(); + STDMETHOD(f941)(); + STDMETHOD(f942)(); + STDMETHOD(f943)(); + STDMETHOD(f944)(); + STDMETHOD(f945)(); + STDMETHOD(f946)(); + STDMETHOD(f947)(); + STDMETHOD(f948)(); + STDMETHOD(f949)(); + STDMETHOD(f950)(); + STDMETHOD(f951)(); + STDMETHOD(f952)(); + STDMETHOD(f953)(); + STDMETHOD(f954)(); + STDMETHOD(f955)(); + STDMETHOD(f956)(); + STDMETHOD(f957)(); + STDMETHOD(f958)(); + STDMETHOD(f959)(); + STDMETHOD(f960)(); + STDMETHOD(f961)(); + STDMETHOD(f962)(); + STDMETHOD(f963)(); + STDMETHOD(f964)(); + STDMETHOD(f965)(); + STDMETHOD(f966)(); + STDMETHOD(f967)(); + STDMETHOD(f968)(); + STDMETHOD(f969)(); + STDMETHOD(f970)(); + STDMETHOD(f971)(); + STDMETHOD(f972)(); + STDMETHOD(f973)(); + STDMETHOD(f974)(); + STDMETHOD(f975)(); + STDMETHOD(f976)(); + STDMETHOD(f977)(); + STDMETHOD(f978)(); + STDMETHOD(f979)(); + STDMETHOD(f980)(); + STDMETHOD(f981)(); + STDMETHOD(f982)(); + STDMETHOD(f983)(); + STDMETHOD(f984)(); + STDMETHOD(f985)(); + STDMETHOD(f986)(); + STDMETHOD(f987)(); + STDMETHOD(f988)(); + STDMETHOD(f989)(); + STDMETHOD(f990)(); + STDMETHOD(f991)(); + STDMETHOD(f992)(); + STDMETHOD(f993)(); + STDMETHOD(f994)(); + STDMETHOD(f995)(); + STDMETHOD(f996)(); + STDMETHOD(f997)(); + STDMETHOD(f998)(); + STDMETHOD(f999)(); + STDMETHOD(f1000)(); + STDMETHOD(f1001)(); + STDMETHOD(f1002)(); + STDMETHOD(f1003)(); + STDMETHOD(f1004)(); + STDMETHOD(f1005)(); + STDMETHOD(f1006)(); + STDMETHOD(f1007)(); + STDMETHOD(f1008)(); + STDMETHOD(f1009)(); + STDMETHOD(f1010)(); + STDMETHOD(f1011)(); + STDMETHOD(f1012)(); + STDMETHOD(f1013)(); + STDMETHOD(f1014)(); + STDMETHOD(f1015)(); + STDMETHOD(f1016)(); + STDMETHOD(f1017)(); + STDMETHOD(f1018)(); + STDMETHOD(f1019)(); + STDMETHOD(f1020)(); + STDMETHOD(f1021)(); + STDMETHOD(f1022)(); + STDMETHOD(f1023)(); + + _QIThunk( + _In_ IUnknown* pOrig, + _In_z_ LPCTSTR p, + _In_ const IID& i, + _In_ UINT n, + _In_ bool b) + { + m_lpszClassName = p; + m_iid = i; + m_nIndex = n; + m_dwRef = 0; + m_dwMaxRef = 0; + ATLENSURE(pOrig); + m_pUnk = pOrig; + m_bBreak = b; + m_bNonAddRefThunk = false; + } + IUnknown* m_pUnk; + long m_dwRef; + long m_dwMaxRef; + LPCTSTR m_lpszClassName; + IID m_iid; + UINT m_nIndex; + bool m_bBreak; + bool m_bNonAddRefThunk; + void Dump() throw(); +}; + +#endif + +///////////////////////////////////////////////////////////////////////////// +// Module Classes + + +#ifdef _ATL_STATIC_REGISTRY +#define UpdateRegistryFromResource UpdateRegistryFromResourceS +#else +#define UpdateRegistryFromResource UpdateRegistryFromResourceD +#endif // _ATL_STATIC_REGISTRY + + +class CAtlComModule : + public _ATL_COM_MODULE +{ +public: + + CAtlComModule() throw() + { + cbSize = 0; + + m_hInstTypeLib = reinterpret_cast(&__ImageBase); + + m_ppAutoObjMapFirst = &__pobjMapEntryFirst + 1; + m_ppAutoObjMapLast = &__pobjMapEntryLast; + + if (FAILED(m_csObjMap.Init())) + { + ATLASSERT(0); + CAtlBaseModule::m_bInitFailed = true; + return; + } + // Set cbSize on success. + cbSize = sizeof(_ATL_COM_MODULE); + } + + ~CAtlComModule() + { + Term(); + } + + // Called from ~CAtlComModule or from ~CAtlExeModule. + void Term() + { + if (cbSize == 0) + return; + + for (_ATL_OBJMAP_ENTRY** ppEntry = m_ppAutoObjMapFirst; ppEntry < m_ppAutoObjMapLast; ppEntry++) + { + if (*ppEntry != NULL) + { + _ATL_OBJMAP_ENTRY* pEntry = *ppEntry; + if (pEntry->pCF != NULL) + pEntry->pCF->Release(); + pEntry->pCF = NULL; + } + } + m_csObjMap.Term(); + // Set to 0 to indicate that this function has been called + // At this point no one should be concerned about cbsize + // having the correct value + cbSize = 0; + } + + // Registry support (helpers) + HRESULT RegisterTypeLib() + { + return AtlRegisterTypeLib(m_hInstTypeLib, NULL); + } + HRESULT RegisterTypeLib(_In_opt_z_ LPCTSTR lpszIndex) + { + USES_CONVERSION_EX; + LPCOLESTR pwszTemp = NULL; + if( lpszIndex != NULL ) + { + pwszTemp = T2COLE_EX(lpszIndex, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if( pwszTemp == NULL ) + return E_OUTOFMEMORY; +#endif + } + return AtlRegisterTypeLib(m_hInstTypeLib, pwszTemp); + } + HRESULT UnRegisterTypeLib() + { + return AtlUnRegisterTypeLib(m_hInstTypeLib, NULL); + } + HRESULT UnRegisterTypeLib(_In_opt_z_ LPCTSTR lpszIndex) + { + USES_CONVERSION_EX; + LPCOLESTR pwszTemp = NULL; + if( lpszIndex != NULL ) + { + pwszTemp = T2COLE_EX(lpszIndex, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if( pwszTemp == NULL ) + return E_OUTOFMEMORY; +#endif + } + return AtlUnRegisterTypeLib(m_hInstTypeLib, pwszTemp); + } + + // RegisterServer walks the ATL Autogenerated object map and registers each object in the map + // If pCLSID is not NULL then only the object referred to by pCLSID is registered (The default case) + // otherwise all the objects are registered + HRESULT RegisterServer( + _In_ BOOL bRegTypeLib = FALSE, + _In_opt_ const CLSID* pCLSID = NULL) + { + return AtlComModuleRegisterServer(this, bRegTypeLib, pCLSID); + } + + // UnregisterServer walks the ATL Autogenerated object map and unregisters each object in the map + // If pCLSID is not NULL then only the object referred to by pCLSID is unregistered (The default case) + // otherwise all the objects are unregistered. + HRESULT UnregisterServer( + _In_ BOOL bRegTypeLib = FALSE, + _In_opt_ const CLSID* pCLSID = NULL) + { + return AtlComModuleUnregisterServer(this, bRegTypeLib, pCLSID); + } + + // Implementation + + // Call ObjectMain for all the objects. + void ExecuteObjectMain(_In_ bool bStarting) + { + for (_ATL_OBJMAP_ENTRY** ppEntry = m_ppAutoObjMapFirst; ppEntry < m_ppAutoObjMapLast; ppEntry++) + { + if (*ppEntry != NULL) + (*ppEntry)->pfnObjectMain(bStarting); + } + } +}; + +extern CAtlComModule _AtlComModule; + +#ifdef _ATL_DEBUG_INTERFACES + +class CAtlDebugInterfacesModule +{ +public: + CAtlDebugInterfacesModule() throw() : + m_nIndexQI( 0 ), + m_nIndexBreakAt( 0 ) + { + if (FAILED(m_cs.Init())) + { + ATLASSERT(0); + CAtlBaseModule::m_bInitFailed = true; + } + } + ~CAtlDebugInterfacesModule() throw() + { + // Release all class factories. + _AtlComModule.Term(); + DumpLeakedThunks(); + } + + HRESULT AddThunk( + _Inout_ _Deref_pre_valid_ _Deref_post_valid_ IUnknown** pp, + _In_z_ LPCTSTR lpsz, + _In_ REFIID iid) throw() + { + if ((pp == NULL) || (*pp == NULL)) + return E_POINTER; + IUnknown* p = *pp; + _QIThunk* pThunk = NULL; + CComCritSecLock lock(m_cs, false); + HRESULT hr = lock.Lock(); + if (FAILED(hr)) + { + ATLASSERT(0); + return hr; + } + + // Check if exists for identity + if (InlineIsEqualUnknown(iid)) + { + for (int i = 0; i < m_aThunks.GetSize(); i++) + { + if (m_aThunks[i]->m_pUnk == p && InlineIsEqualGUID(m_aThunks[i]->m_iid, iid)) + { + m_aThunks[i]->InternalAddRef(); + pThunk = m_aThunks[i]; + break; + } + } + } + if (pThunk == NULL) + { + ++m_nIndexQI; + if (m_nIndexBreakAt == m_nIndexQI) + DebugBreak(); + ATLTRY(pThunk = new _QIThunk(p, lpsz, iid, m_nIndexQI, (m_nIndexBreakAt == m_nIndexQI))); + if (pThunk == NULL) + { + return E_OUTOFMEMORY; + } + pThunk->InternalAddRef(); + m_aThunks.Add(pThunk); + } + *pp = (IUnknown*)pThunk; + return S_OK; + } + HRESULT AddNonAddRefThunk( + _In_ IUnknown* p, + _In_z_ LPCTSTR lpsz, + _Deref_out_ IUnknown** ppThunkRet) throw() + { + if (ppThunkRet == NULL) + return E_POINTER; + *ppThunkRet = NULL; + + _QIThunk* pThunk = NULL; + CComCritSecLock lock(m_cs, false); + HRESULT hr = lock.Lock(); + if (FAILED(hr)) + { + ATLASSERT(0); + return hr; + } + + // Check if exists already for identity + for (int i = 0; i < m_aThunks.GetSize(); i++) + { + if (m_aThunks[i]->m_pUnk == p) + { + m_aThunks[i]->m_bNonAddRefThunk = true; + pThunk = m_aThunks[i]; + break; + } + } + if (pThunk == NULL) + { + ++m_nIndexQI; + if (m_nIndexBreakAt == m_nIndexQI) + DebugBreak(); + ATLTRY(pThunk = new _QIThunk(p, lpsz, __uuidof(IUnknown), m_nIndexQI, (m_nIndexBreakAt == m_nIndexQI))); + if (pThunk == NULL) + { + return E_OUTOFMEMORY; + } + pThunk->m_bNonAddRefThunk = true; + m_aThunks.Add(pThunk); + } + *ppThunkRet = (IUnknown*)pThunk; + return S_OK;; + } + void DeleteNonAddRefThunk(_In_ IUnknown* pUnk) throw() + { + CComCritSecLock lock(m_cs, false); + HRESULT hr = lock.Lock(); + if (FAILED(hr)) + { + ATLASSERT(0); + return; + } + + for (int i = 0; i < m_aThunks.GetSize(); i++) + { + if (m_aThunks[i]->m_bNonAddRefThunk && m_aThunks[i]->m_pUnk == pUnk) + { + delete m_aThunks[i]; + m_aThunks.RemoveAt(i); + break; + } + } + } + void DeleteThunk(_In_ _QIThunk* p) throw() + { + CComCritSecLock lock(m_cs, false); + HRESULT hr = lock.Lock(); + if (FAILED(hr)) + { + ATLASSERT(0); + return; + } + + int nIndex = m_aThunks.Find(p); + if (nIndex != -1) + { + m_aThunks[nIndex]->m_pUnk = NULL; + delete m_aThunks[nIndex]; + m_aThunks.RemoveAt(nIndex); + } + } + bool DumpLeakedThunks() + { + bool b = false; + for (int i = 0; i < m_aThunks.GetSize(); i++) + { + b = true; + m_aThunks[i]->Dump(); + delete m_aThunks[i]; + } + m_aThunks.RemoveAll(); + return b; + } + +public: + UINT m_nIndexQI; + UINT m_nIndexBreakAt; + CSimpleArray<_QIThunk*> m_aThunks; + CComAutoDeleteCriticalSection m_cs; +}; + +extern CAtlDebugInterfacesModule _AtlDebugInterfacesModule; + +#ifndef _ATL_STATIC_LIB_IMPL +// Should not be pulled into the static lib +__declspec (selectany) CAtlDebugInterfacesModule _AtlDebugInterfacesModule; +#endif + +inline ULONG _QIThunk::Release() +{ + ATLASSUME(m_pUnk != NULL); + if (m_bBreak) + DebugBreak(); + ATLASSUME(m_dwRef > 0); + + // save copies of member variables we wish to use after the InterlockedDecrement + UINT nIndex = m_nIndex; + IUnknown* pUnk = m_pUnk; + IID iid = m_iid; + LPCTSTR lpszClassName = m_lpszClassName; + bool bNonAddRefThunk = m_bNonAddRefThunk; + + ULONG l = InterlockedDecrement(&m_dwRef); + + TCHAR buf[512+1]; + _stprintf_s(buf, _countof(buf), _T("QIThunk - %-10d\tRelease :\tObject = 0x%p\tRefcount = %d\t"), nIndex, pUnk, l); + buf[_countof(buf)-1] = 0; + OutputDebugString(buf); + AtlDumpIID(iid, lpszClassName, S_OK); + + bool bDeleteThunk = (l == 0 && !bNonAddRefThunk); + pUnk->Release(); + if (bDeleteThunk) + _AtlDebugInterfacesModule.DeleteThunk(this); + return l; +} + +#endif // _ATL_DEBUG_INTERFACES + + +class CAtlWinModule : + public _ATL_WIN_MODULE +{ +public: + CAtlWinModule() + { + cbSize = sizeof(_ATL_WIN_MODULE); + HRESULT hr = AtlWinModuleInit(this); + if (FAILED(hr)) + { + ATLASSERT(0); + CAtlBaseModule::m_bInitFailed = true; + cbSize = 0; + return; + } + } + + ~CAtlWinModule() + { + Term(); + } + + void Term() + { + } + + void AddCreateWndData(_Inout_ _AtlCreateWndData* pData, _In_ void* pObject) + { + AtlWinModuleAddCreateWndData(this, pData, pObject); + } + + void* ExtractCreateWndData() + { + return AtlWinModuleExtractCreateWndData(this); + } +}; + +extern CAtlWinModule _AtlWinModule; + +class CAtlModule; +__declspec(selectany) CAtlModule* _pAtlModule = NULL; + +#if defined(_M_CEE) && !defined(_ATL_MIXED) + +// This small class takes care of releasing the class factories at managed +// shutdown when we are compiling /clr. We can't wait to call _AtlComModule.Term() +// in _AtlComModule destructor, since _AtlComModule is a native global object, and it +// will be destructed after the managed runtime has been shutdown. + +// Notice that if the user defines _ATL_MIXED, he/she will need to take care +// of releasing the eventual managed class factories at the right time. + +class CAtlReleaseManagedClassFactories +{ +public: + CAtlReleaseManagedClassFactories() { } + ~CAtlReleaseManagedClassFactories() + { + _AtlComModule.Term(); + } +}; + +__declspec (selectany) CAtlReleaseManagedClassFactories _AtlReleaseManagedClassFactories; + +extern "C" +{ +__declspec (selectany) void *_pAtlReleaseManagedClassFactories = &_AtlReleaseManagedClassFactories; +} +#if defined(_M_IX86) + #pragma comment(linker, "/include:__pAtlReleaseManagedClassFactories") +#else + #pragma comment(linker, "/include:_pAtlReleaseManagedClassFactories") +#endif + +#endif + +class ATL_NO_VTABLE CAtlModule : + public _ATL_MODULE +{ +public : + static GUID m_libid; + IGlobalInterfaceTable* m_pGIT; + + CAtlModule() throw() + { + // Should have only one instance of a class + // derived from CAtlModule in a project. + ATLASSERT(_pAtlModule == NULL); + cbSize = 0; + m_pTermFuncs = NULL; + + m_nLockCnt = 0; + _pAtlModule = this; + m_pGIT = NULL; + + if (FAILED(m_csStaticDataInitAndTypeInfo.Init())) + { + ATLASSERT(0); + CAtlBaseModule::m_bInitFailed = true; + return; + } + + // Set cbSize on success. + cbSize = sizeof(_ATL_MODULE); + } + + void Term() throw() + { + // cbSize == 0 indicates that Term has already been called + if (cbSize == 0) + return; + + // Call term functions + if (m_pTermFuncs != NULL) + { + AtlCallTermFunc(this); + m_pTermFuncs = NULL; + } + + if (m_pGIT != NULL) + m_pGIT->Release(); + + m_csStaticDataInitAndTypeInfo.Term(); + + cbSize = 0; + } + + virtual ~CAtlModule() throw() + { + Term(); + } + + virtual LONG Lock() throw() + { + return CComGlobalsThreadModel::Increment(&m_nLockCnt); + } + + virtual LONG Unlock() throw() + { + return CComGlobalsThreadModel::Decrement(&m_nLockCnt); + } + + virtual LONG GetLockCount() throw() + { + return m_nLockCnt; + } + + HRESULT AddTermFunc( + _In_ _ATL_TERMFUNC* pFunc, + _In_ DWORD_PTR dw) throw() + { + return AtlModuleAddTermFunc(this, pFunc, dw); + } + + virtual HRESULT GetGITPtr(_Deref_out_ IGlobalInterfaceTable** ppGIT) throw() + { + ATLASSERT(ppGIT != NULL); + + if (ppGIT == NULL) + return E_POINTER; + + HRESULT hr = S_OK; + if (m_pGIT == NULL) + { + hr = ::CoCreateInstance(CLSID_StdGlobalInterfaceTable, NULL, CLSCTX_INPROC_SERVER, + __uuidof(IGlobalInterfaceTable), (void**)&m_pGIT); + } + + if (SUCCEEDED(hr)) + { + ATLASSUME(m_pGIT != NULL); + *ppGIT = m_pGIT; + m_pGIT->AddRef(); + } + return hr; + } + + virtual HRESULT AddCommonRGSReplacements(_Inout_ IRegistrarBase* /*pRegistrar*/) throw() = 0; + + // Resource-based Registration +#ifdef _ATL_STATIC_REGISTRY + // Statically linking to Registry Ponent + HRESULT WINAPI UpdateRegistryFromResourceS( + _In_z_ LPCTSTR lpszRes, + _In_ BOOL bRegister, + _In_opt_ struct _ATL_REGMAP_ENTRY* pMapEntries = NULL) throw(); + HRESULT WINAPI UpdateRegistryFromResourceS( + _In_ UINT nResID, + _In_ BOOL bRegister, + _In_opt_ struct _ATL_REGMAP_ENTRY* pMapEntries = NULL) throw(); +#else + HRESULT WINAPI UpdateRegistryFromResourceD( + _In_z_ LPCTSTR lpszRes, + _In_ BOOL bRegister, + _In_opt_ struct _ATL_REGMAP_ENTRY* pMapEntries = NULL) throw() + { + if(lpszRes == NULL) + return E_INVALIDARG; + + USES_CONVERSION_EX; + LPCOLESTR pwszTemp = T2COLE_EX(lpszRes, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); + ATLASSUME(pwszTemp != NULL); +#ifdef _UNICODE + if(pwszTemp == NULL) + return E_OUTOFMEMORY; +#endif + return UpdateRegistryFromResourceDHelper(pwszTemp, bRegister, pMapEntries); + } + HRESULT WINAPI UpdateRegistryFromResourceD( + _In_ UINT nResID, + _In_ BOOL bRegister, + _In_opt_ struct _ATL_REGMAP_ENTRY* pMapEntries = NULL) throw() + { + return UpdateRegistryFromResourceDHelper((LPCOLESTR)MAKEINTRESOURCE(nResID), bRegister, pMapEntries); + } +#endif + + // Implementation +#if !defined(_ATL_STATIC_REGISTRY) + inline HRESULT WINAPI UpdateRegistryFromResourceDHelper( + _In_z_ LPCOLESTR lpszRes, + _In_ BOOL bRegister, + _In_opt_ struct _ATL_REGMAP_ENTRY* pMapEntries = NULL) throw() + { + CComPtr spRegistrar; + HRESULT hr = AtlCreateRegistrar(&spRegistrar); + if (FAILED(hr)) + return hr; + + if (NULL != pMapEntries) + { + while (NULL != pMapEntries->szKey) + { + ATLASSERT(NULL != pMapEntries->szData); + spRegistrar->AddReplacement(pMapEntries->szKey, pMapEntries->szData); + pMapEntries++; + } + } + + hr = AddCommonRGSReplacements(spRegistrar); + if (FAILED(hr)) + return hr; + + } +#endif + + static void EscapeSingleQuote( + _Out_z_cap_(destSizeInChars) LPOLESTR lpDest, + _In_ size_t destSizeInChars, + _In_z_ LPCOLESTR lp) throw() + { + if (destSizeInChars == 0) + { + return; + } + UINT i = 0; + // copy charecters to the destination buffer but leave the last char to be NULL. + for (i=0; i < destSizeInChars-1 && *lp; i++) + { + *lpDest++ = *lp; + // make sure we won't promote lpDest behind the buffer limit. + if (*lp == '\'' && ++i < destSizeInChars-1) + *lpDest++ = *lp; + lp++; + } + *lpDest = '\0'; + } + + ATL_DEPRECATED("CAtlModule::EscapeSingleQuote(dest, src) is unsafe. Instead, use CAtlModule::EscapeSingleQuote(dest, size, src)") + static void EscapeSingleQuote( + _Out_ _Post_z_ LPOLESTR lpDest, + _In_z_ LPCOLESTR lp) throw() + { +ATLPREFAST_SUPPRESS(6386) + EscapeSingleQuote(lpDest, SIZE_MAX/sizeof(OLECHAR), lp); +ATLPREFAST_UNSUPPRESS() + } + + // search for an occurence of string p2 in string p1 + static LPCTSTR FindOneOf( + _In_z_ LPCTSTR p1, + _In_z_ LPCTSTR p2) throw() + { + while (p1 != NULL && *p1 != _T('\0')) + { + LPCTSTR p = p2; + while (p != NULL && *p != _T('\0')) + { + if (*p1 == *p) + return CharNext(p1); + p = CharNext(p); + } + p1 = CharNext(p1); + } + return NULL; + } +#pragma warning(push) +#pragma warning(disable : 4302) // 'type cast' : truncation from 'LPSTR' to 'TCHAR' + + static int WordCmpI( + _In_z_ LPCTSTR psz1, + _In_z_ LPCTSTR psz2) throw() + { + TCHAR c1 = (TCHAR)CharUpper((LPTSTR)*psz1); + TCHAR c2 = (TCHAR)CharUpper((LPTSTR)*psz2); + while (c1 != _T('\0') && c1 == c2 && c1 != ' ' && c1 != '\t') + { + psz1 = CharNext(psz1); + psz2 = CharNext(psz2); + c1 = (TCHAR)CharUpper((LPTSTR)*psz1); + c2 = (TCHAR)CharUpper((LPTSTR)*psz2); + } + if ((c1 == _T('\0') || c1 == ' ' || c1 == '\t') && (c2 == _T('\0') || c2 == ' ' || c2 == '\t')) + return 0; + + return (c1 < c2) ? -1 : 1; + } + +#pragma warning (pop) +}; + +__declspec(selectany) GUID CAtlModule::m_libid = {0x0, 0x0, 0x0, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} }; + +#define DECLARE_LIBID(libid) \ + static void InitLibId() throw() \ + { \ + ATL::CAtlModule::m_libid = libid; \ + } + +#define DECLARE_REGISTRY_APPID_RESOURCEID(resid, appid) \ + static LPCOLESTR GetAppId() throw() \ + { \ + return OLESTR(appid); \ + } \ + static TCHAR* GetAppIdT() throw() \ + { \ + return _T(appid); \ + } \ + static HRESULT WINAPI UpdateRegistryAppId(_In_ BOOL bRegister) throw() \ + { \ + ATL::_ATL_REGMAP_ENTRY aMapEntries [] = \ + { \ + { OLESTR("APPID"), GetAppId() }, \ + { NULL, NULL } \ + }; \ + return ATL::_pAtlModule->UpdateRegistryFromResource(resid, bRegister, aMapEntries); \ + } + +inline HRESULT AtlGetGITPtr(_Deref_out_ IGlobalInterfaceTable** ppGIT) throw() +{ + if (ppGIT == NULL) + return E_POINTER; + + if (_pAtlModule == NULL) + { + return CoCreateInstance(CLSID_StdGlobalInterfaceTable, NULL, CLSCTX_INPROC_SERVER, + __uuidof(IGlobalInterfaceTable), (void**)ppGIT); + } + else + { + return _pAtlModule->GetGITPtr(ppGIT); + } +} + +template +class ATL_NO_VTABLE CAtlModuleT : + public CAtlModule +{ +public : + CAtlModuleT() throw() + { + T::InitLibId(); + } + + static void InitLibId() throw() + { + } + + HRESULT RegisterServer( + _In_ BOOL bRegTypeLib = FALSE, + _In_opt_ const CLSID* pCLSID = NULL) throw() + { + (pCLSID); + (bRegTypeLib); + + HRESULT hr = S_OK; + +#ifndef _ATL_NO_COM_SUPPORT + + hr = _AtlComModule.RegisterServer(bRegTypeLib, pCLSID); + +#endif // _ATL_NO_COM_SUPPORT + + +#ifndef _ATL_NO_PERF_SUPPORT + +#endif + + return hr; + } + + HRESULT UnregisterServer( + _In_ BOOL bUnRegTypeLib, + _In_opt_ const CLSID* pCLSID = NULL) throw() + { + (bUnRegTypeLib); + (pCLSID); + + HRESULT hr = S_OK; + +#ifndef _ATL_NO_PERF_SUPPORT + + if (_pPerfUnRegFunc != NULL) + hr = (*_pPerfUnRegFunc)(); + +#endif + +#ifndef _ATL_NO_COM_SUPPORT + + if (SUCCEEDED(hr)) + hr = _AtlComModule.UnregisterServer(bUnRegTypeLib, pCLSID); + +#endif // _ATL_NO_COM_SUPPORT + + return hr; + + } + + static HRESULT WINAPI UpdateRegistryAppId(_In_ BOOL /*bRegister*/) throw() + { + return S_OK; + } + HRESULT RegisterAppId() throw() + { + return T::UpdateRegistryAppId(TRUE); + } + + HRESULT UnregisterAppId() throw() + { + return T::UpdateRegistryAppId(FALSE); + } + + virtual HRESULT AddCommonRGSReplacements(_Inout_ IRegistrarBase* pRegistrar) throw() + { + return pRegistrar->AddReplacement(L"APPID", T::GetAppId()); + } + static LPCOLESTR GetAppId() throw() + { + return OLESTR(""); + } +}; + +#if !defined(_ATL_NATIVE_INITIALIZATION) +#pragma warning(push) +#pragma warning(disable:4483) +namespace __identifier("") +#pragma warning(pop) +{ + __declspec(selectany) bool DllModuleInitialized = false; +} + +#endif + +template +class ATL_NO_VTABLE CAtlDllModuleT : + public CAtlModuleT +{ +public : + CAtlDllModuleT() throw() + { + _AtlComModule.ExecuteObjectMain(true); +#if !defined(_ATL_NATIVE_INITIALIZATION) +#pragma warning(push) +#pragma warning(disable:4483) + using namespace __identifier(""); +#pragma warning(pop) + ATLASSERT(DllModuleInitialized == false); + DllModuleInitialized = true; + _DllMain(DLL_PROCESS_ATTACH, NULL); +#endif + } + + ~CAtlDllModuleT() throw() + { +#if !defined(_ATL_NATIVE_INITIALIZATION) +#pragma warning(push) +#pragma warning(disable:4483) + using namespace __identifier(""); +#pragma warning(pop) + ATLASSERT(DllModuleInitialized == true); + _DllMain(DLL_PROCESS_DETACH, NULL); +#endif + _AtlComModule.ExecuteObjectMain(false); + } + + BOOL WINAPI DllMain( + _In_ DWORD dwReason, + _In_opt_ LPVOID lpReserved) throw(); + + BOOL WINAPI _DllMain( + _In_ DWORD dwReason, + _In_opt_ LPVOID /* lpReserved */) throw() + { + if (dwReason == DLL_PROCESS_ATTACH) + { + if (CAtlBaseModule::m_bInitFailed) + { + ATLASSERT(0); + return FALSE; + } + } +#ifdef _DEBUG + else if (dwReason == DLL_PROCESS_DETACH) + { + // Prevent false memory leak reporting. ~CAtlWinModule may be too late. + _AtlWinModule.Term(); + } +#endif // _DEBUG + return TRUE; // ok + } + + HRESULT DllCanUnloadNow() throw() + { + T* pT = static_cast(this); + return (pT->GetLockCount()==0) ? S_OK : S_FALSE; + } + + HRESULT DllGetClassObject( + _In_ REFCLSID rclsid, + _In_ REFIID riid, + _Deref_out_ LPVOID* ppv) throw() + { + T* pT = static_cast(this); + return pT->GetClassObject(rclsid, riid, ppv); + } + + HRESULT DllRegisterServer( + _In_ BOOL bRegTypeLib = TRUE) throw() + { + LCID lcid = GetThreadLocale(); + SetThreadLocale(LOCALE_SYSTEM_DEFAULT); + // registers object, typelib and all interfaces in typelib + T* pT = static_cast(this); + HRESULT hr = pT->RegisterAppId(); + if (SUCCEEDED(hr)) + hr = pT->RegisterServer(bRegTypeLib); + SetThreadLocale(lcid); + return hr; + } + + HRESULT DllUnregisterServer( + _In_ BOOL bUnRegTypeLib = TRUE) throw() + { + LCID lcid = GetThreadLocale(); + SetThreadLocale(LOCALE_SYSTEM_DEFAULT); + T* pT = static_cast(this); + HRESULT hr = pT->UnregisterServer(bUnRegTypeLib); + if (SUCCEEDED(hr)) + hr = pT->UnregisterAppId(); + SetThreadLocale(lcid); + return hr; + } + + // Obtain a Class Factory + HRESULT GetClassObject( + _In_ REFCLSID rclsid, + _In_ REFIID riid, + _Deref_out_ LPVOID* ppv) throw() + { + return AtlComModuleGetClassObject(&_AtlComModule, rclsid, riid, ppv); + } +}; + +#pragma managed(push, off) + +template +inline BOOL WINAPI CAtlDllModuleT::DllMain( + _In_ DWORD dwReason, + _In_opt_ LPVOID lpReserved) throw() +{ +#if !defined(_ATL_NATIVE_INITIALIZATION) + UNREFERENCED_PARAMETER(dwReason); UNREFERENCED_PARAMETER(lpReserved); +#pragma warning(push) +#pragma warning(disable:4483) + using namespace __identifier(""); +#pragma warning(pop) + if (dwReason == DLL_PROCESS_ATTACH) + { + ATLASSERT(DllModuleInitialized == false); + } + return TRUE; +#else + return _DllMain(dwReason, lpReserved); +#endif +} + +#pragma managed(pop) + +#ifndef _AFX + + +#endif // !_AFX + +#ifdef _AFX + +class CAtlMfcModule : + public ATL::CAtlModuleT +{ +public : + virtual LONG Lock() throw() + { +#ifdef _USRDLL + AFX_MANAGE_STATE(AfxGetStaticModuleState()); +#endif + AfxOleLockApp(); + return AfxGetModuleState()->m_nObjectCount; + } + + virtual LONG Unlock() throw() + { +#ifdef _USRDLL + AFX_MANAGE_STATE(AfxGetStaticModuleState()); +#endif + AfxOleUnlockApp(); + return AfxGetModuleState()->m_nObjectCount; + } + + virtual LONG GetLockCount() throw() + { +#ifdef _USRDLL + AFX_MANAGE_STATE(AfxGetStaticModuleState()); +#endif + return AfxGetModuleState()->m_nObjectCount; + } + + // Obtain a Class Factory (DLL only) + HRESULT GetClassObject( + _In_ REFCLSID rclsid, + _In_ REFIID riid, + _Deref_out_ LPVOID* ppv) + { + return ATL::AtlComModuleGetClassObject(&ATL::_AtlComModule, rclsid, riid, ppv); + } + + // Register/Revoke All Class Factories with the OS (EXE only) + HRESULT RegisterClassObjects( + _In_ DWORD dwClsContext, + _In_ DWORD dwFlags) + { + return ATL::AtlComModuleRegisterClassObjects(&ATL::_AtlComModule, dwClsContext, dwFlags); + } + + HRESULT RevokeClassObjects() + { + return ATL::AtlComModuleRevokeClassObjects(&ATL::_AtlComModule); + } +}; + +#endif // _AFX + +///////////////////////////////////////////////////////////////////////////// +// CComModule - Uses the functionality provided by other modules + +#define THREADFLAGS_APARTMENT 0x1 +#define THREADFLAGS_BOTH 0x2 +#define AUTPRXFLAG 0x4 + +#ifndef _ATL_NO_COMMODULE + +class CComModule; + +#if !defined(_ATL_NATIVE_INITIALIZATION) + +#pragma managed(push, off) + +#pragma warning(push) +#pragma warning(disable:4483) +namespace __identifier("") +#pragma warning(pop) +{ + struct CComModuleHelper + { + CComModule* Module; + HINSTANCE Instance; + _ATL_OBJMAP_ENTRY* ObjectMap; + const GUID* LibraryId; + + // Must NOT have any constructors + // We initialize the object in DllMain *before* + // the constructors would run. + + void Initialize( + _In_ CComModule* pModule, + _In_ HINSTANCE hInstance, + _In_ _ATL_OBJMAP_ENTRY* pObjMap, + _In_ const GUID* pLibID) + { + Module = pModule; + Instance = hInstance; + ObjectMap = pObjMap; + LibraryId = pLibID; + } + }; + + __declspec(selectany) CComModuleHelper ComModuleHelper; + __declspec(selectany) bool ComModuleInitialized = false; +} + +#pragma managed(pop) + +#endif + + +__declspec(selectany) CComModule* _pModule = NULL; +class CComModule : + public CAtlModuleT +{ +public : + + CComModule() + { + // Should have only one instance of a class + // derived from CComModule in a project. + ATLASSERT(_pModule == NULL); + _pModule = this; +#if !defined(_ATL_NATIVE_INITIALIZATION) +#pragma warning(push) +#pragma warning(disable:4483) + using namespace __identifier(""); +#pragma warning(pop) + ATLASSERT(ComModuleInitialized == false); + // If ComModuleHelper.Module == NULL it mean that DllMain has not been called, so we assume CComModule lives in + // an exe and not in a dll + if (ComModuleHelper.Module != NULL) + { + ATLASSERT(ComModuleHelper.Module == this); + _DllMain(ComModuleHelper.Instance, DLL_PROCESS_ATTACH, NULL, ComModuleHelper.ObjectMap, ComModuleHelper.LibraryId); + } + ComModuleInitialized = true; +#endif + } + + virtual ~CComModule() throw() + { +#if !defined(_ATL_NATIVE_INITIALIZATION) +#pragma warning(push) +#pragma warning(disable:4483) + using namespace __identifier(""); +#pragma warning(pop) + ATLASSERT(ComModuleInitialized == true); + // If ComModuleHelper.Module == NULL it mean that DllMain has not been called, so we assume CComModule lives in + // an exe and not in a dll + if (ComModuleHelper.Module != NULL) + { + ATLASSERT(ComModuleHelper.Module == this); + _DllMain(ComModuleHelper.Instance, DLL_PROCESS_DETACH, NULL, ComModuleHelper.ObjectMap, ComModuleHelper.LibraryId); + } +#endif + } + +#if !defined(__MINGW32__) + __declspec(property(get = get_m_hInst)) HINSTANCE m_hInst; +#endif + +#if !defined(__MINGW32__) + __declspec(property(get = get_m_hInstResource, put = put_m_hInstResource)) HINSTANCE m_hInstResource; +#endif +#if !defined(__MINGW32__) + __declspec(property(get = get_m_hInstTypeLib, put = put_m_hInstTypeLib)) HINSTANCE m_hInstTypeLib; +#endif + HINSTANCE& get_m_hInstTypeLib() const throw() + { + return _AtlComModule.m_hInstTypeLib; + } + void put_m_hInstTypeLib(_In_ HINSTANCE h) throw() + { + _AtlComModule.m_hInstTypeLib = h; + } + + HINSTANCE GetTypeLibInstance() const throw() + { + return _AtlComModule.m_hInstTypeLib; + } + + // For Backward compatibility + _ATL_OBJMAP_ENTRY* m_pObjMap; + +#if !defined(__MINGW32__) + __declspec(property(get = get_m_csWindowCreate)) CRITICAL_SECTION m_csWindowCreate; +#endif + CRITICAL_SECTION& get_m_csWindowCreate() throw(); + +#if !defined(__MINGW32__) + __declspec(property(get = get_m_csObjMap)) CRITICAL_SECTION m_csObjMap; +#endif + CRITICAL_SECTION& get_m_csObjMap() throw(); + +#if !defined(__MINGW32__) + __declspec(property(get = get_m_csStaticDataInit)) CRITICAL_SECTION m_csTypeInfoHolder; + __declspec(property(get = get_m_csStaticDataInit)) CRITICAL_SECTION m_csStaticDataInit; +#else + CRITICAL_SECTION m_csTypeInfoHolder; + CRITICAL_SECTION m_csStaticDataInit; +#endif + CRITICAL_SECTION& get_m_csStaticDataInit() throw(); + void EnterStaticDataCriticalSection() throw() + { + EnterCriticalSection(&this->m_csStaticDataInit); + } + + void LeaveStaticDataCriticalSection() throw() + { + LeaveCriticalSection(&this->m_csStaticDataInit); + } + +#if !defined(__MINGW32__) + __declspec(property(get = get_dwAtlBuildVer)) DWORD dwAtlBuildVer; +#endif + +#if !defined(__MINGW32__) + __declspec(property(get = get_m_pCreateWndList, put = put_m_pCreateWndList)) _AtlCreateWndData* m_pCreateWndList; +#endif + _AtlCreateWndData*& get_m_pCreateWndList() throw(); + void put_m_pCreateWndList(_In_ _AtlCreateWndData* p) throw(); + +#if !defined(__MINGW32__) + __declspec(property(get = get_pguidVer)) const GUID* pguidVer; +#endif + +#ifdef _ATL_DEBUG_INTERFACES + + __declspec(property(get = get_m_nIndexQI, put = put_m_nIndexQI)) UINT m_nIndexQI; + UINT& get_m_nIndexQI() throw(); + void put_m_nIndexQI(_In_ UINT nIndex) throw(); + + __declspec(property(get = get_m_nIndexBreakAt, put = put_m_nIndexBreakAt)) UINT m_nIndexBreakAt; + UINT& get_m_nIndexBreakAt() throw(); + void put_m_nIndexBreakAt(_In_ UINT nIndex) throw(); + + __declspec(property(get = get_m_paThunks)) CSimpleArray<_QIThunk*>* m_paThunks; + CSimpleArray<_QIThunk*>* get_m_paThunks() throw(); + HRESULT AddThunk( + _Inout_ _Deref_pre_valid_ _Deref_post_valid_ IUnknown** pp, + _In_z_ LPCTSTR lpsz, + _In_ REFIID iid) throw(); + + HRESULT AddNonAddRefThunk( + _Inout_ IUnknown* p, + _In_z_ LPCTSTR lpsz, + _Deref_out_ IUnknown** ppThunkRet) throw(); + + void DeleteNonAddRefThunk(_In_ IUnknown* pUnk) throw(); + void DeleteThunk(_In_ _QIThunk* p) throw(); + bool DumpLeakedThunks() throw(); +#endif // _ATL_DEBUG_INTERFACES + + HRESULT Init( + _In_ _ATL_OBJMAP_ENTRY* p, + _In_ HINSTANCE h, + _In_opt_ const GUID* plibid = NULL) throw(); + + void Term() throw(); + + HRESULT GetClassObject( + _In_ REFCLSID rclsid, + _In_ REFIID riid, + _Deref_out_ LPVOID* ppv) throw(); + // Register/Revoke All Class Factories with the OS (EXE only) + HRESULT RegisterClassObjects(_In_ DWORD dwClsContext, _In_ DWORD dwFlags) throw(); + HRESULT RevokeClassObjects() throw(); + // Registry support (helpers) + HRESULT RegisterTypeLib() throw(); + HRESULT RegisterTypeLib(_In_z_ LPCTSTR lpszIndex) throw(); + HRESULT UnRegisterTypeLib() throw(); + HRESULT UnRegisterTypeLib(_In_z_ LPCTSTR lpszIndex) throw(); + HRESULT RegisterServer( + _In_ BOOL bRegTypeLib = FALSE, + _In_opt_ const CLSID* pCLSID = NULL) throw(); + HRESULT UnregisterServer( + _In_ BOOL bUnRegTypeLib, + _In_opt_ const CLSID* pCLSID = NULL) throw(); + HRESULT UnregisterServer(_In_opt_ const CLSID* pCLSID = NULL) throw(); + + void AddCreateWndData( + _In_ _AtlCreateWndData* pData, + _In_ void* pObject) throw() + { + _AtlWinModule.AddCreateWndData(pData, pObject); + } + + void* ExtractCreateWndData() throw() + { + return _AtlWinModule.ExtractCreateWndData(); + } + + // Only used in CComAutoThreadModule + HRESULT CreateInstance( + _In_opt_ void* /*pfnCreateInstance*/, + _In_ REFIID /*riid*/, + _In_opt_ void** /*ppvObj*/) throw() + { + ATLASSERT(0); + ATLTRACENOTIMPL(_T("CComModule::CreateInstance")); + } + + HRESULT RegisterAppId(_In_z_ LPCTSTR pAppId); + HRESULT UnregisterAppId(_In_z_ LPCTSTR pAppId); + + // Resource-based Registration +#if defined(_ATL_STATIC_REGISTRY) + virtual HRESULT WINAPI UpdateRegistryFromResourceD( + _In_opt_z_ LPCTSTR lpszRes, + _In_ BOOL bRegister, + _In_opt_ struct _ATL_REGMAP_ENTRY* pMapEntries = NULL) throw() + { + (lpszRes); + (bRegister); + (pMapEntries); + return E_FAIL; + } +#else + virtual HRESULT WINAPI UpdateRegistryFromResourceD( + _In_z_ LPCTSTR lpszRes, + _In_ BOOL bRegister, + _In_opt_ struct _ATL_REGMAP_ENTRY* pMapEntries = NULL) throw() + { + return CAtlModuleT::UpdateRegistryFromResourceD(lpszRes, bRegister, pMapEntries); + } +#endif + + virtual HRESULT WINAPI UpdateRegistryFromResourceD( + _In_ UINT nResID, + _In_ BOOL bRegister, + _In_opt_ struct _ATL_REGMAP_ENTRY* pMapEntries = NULL) throw() + { +#if defined(_ATL_STATIC_REGISTRY) + (nResID); + (bRegister); + (pMapEntries); + return E_FAIL; +#else + return CAtlModuleT::UpdateRegistryFromResourceD(nResID, bRegister, pMapEntries); +#endif + } + + // Statically linking to Registry Ponent + virtual HRESULT WINAPI UpdateRegistryFromResourceS( + _In_z_ LPCTSTR lpszRes, + _In_ BOOL bRegister, + _In_opt_ struct _ATL_REGMAP_ENTRY* pMapEntries = NULL) throw() + { +#ifdef _ATL_STATIC_REGISTRY + return CAtlModuleT::UpdateRegistryFromResourceS(lpszRes, bRegister, pMapEntries); +#else + (lpszRes); + (bRegister); + (pMapEntries); + return E_FAIL; +#endif + } + virtual HRESULT WINAPI UpdateRegistryFromResourceS( + _In_ UINT nResID, + _In_ BOOL bRegister, + _In_opt_ struct _ATL_REGMAP_ENTRY* pMapEntries = NULL) throw() + { +#ifdef _ATL_STATIC_REGISTRY + return CAtlModuleT::UpdateRegistryFromResourceS(nResID, bRegister, pMapEntries); +#else + (nResID); + (bRegister); + (pMapEntries); + return E_FAIL; +#endif + } + + // Use RGS file for registration + + ATL_DEPRECATED("CComModule::RegisterProgID is no longer recommended. Instead, use an RGS file for registration.") + static HRESULT RegisterProgID( + _In_z_ LPCTSTR lpszCLSID, + _In_z_ LPCTSTR lpszProgID, + _In_z_ LPCTSTR lpszUserDesc); + + ATL_DEPRECATED("CComModule::RegisterVersionIndependentProgID is no longer recommended. Instead, use an RGS file for registration.") + static HRESULT RegisterVersionIndependentProgID( + _In_z_ LPCTSTR lpszCLSID, + _In_z_ LPCTSTR lpszVerIndProgID, + _In_z_ LPCTSTR lpszCurVerProgID, + _In_z_ LPCTSTR lpszUserDesc); + + // Standard Registration + ATL_DEPRECATED("CComModule::UpdateRegistryClass is no longer recommended. Instead, use an RGS file for registration.") + HRESULT WINAPI UpdateRegistryClass( + _In_ const CLSID& clsid, + _In_opt_z_ LPCTSTR lpszProgID, + _In_opt_z_ LPCTSTR lpszVerIndProgID, + _In_ UINT nDescID, + _In_ DWORD dwFlags, + _In_ BOOL bRegister); + + ATL_DEPRECATED("CComModule::UpdateRegistryClass is no longer recommended. Instead, use an RGS file for registration.") + HRESULT WINAPI UpdateRegistryClass( + _In_ const CLSID& clsid, + _In_opt_z_ LPCTSTR lpszProgID, + _In_opt_z_ LPCTSTR lpszVerIndProgID, + _In_z_ LPCTSTR szDesc, + _In_ DWORD dwFlags, + _In_ BOOL bRegister); + + ATL_DEPRECATED("CComModule::RegisterClassHelper is no longer recommended. Instead, use an RGS file for registration.") + HRESULT WINAPI RegisterClassHelper( + _In_ const CLSID& clsid, + _In_opt_z_ LPCTSTR lpszProgID, + _In_opt_z_ LPCTSTR lpszVerIndProgID, + _In_z_ LPCTSTR szDesc, + _In_ DWORD dwFlags); + + ATL_DEPRECATED("CComModule::UnregisterClassHelper is no longer recommended. Instead, use an RGS file for registration.") + HRESULT WINAPI UnregisterClassHelper( + _In_ const CLSID& clsid, + _In_opt_z_ LPCTSTR lpszProgID, + _In_opt_z_ LPCTSTR lpszVerIndProgID); + + BOOL WINAPI DllMain( + _In_ HINSTANCE hInstance, + _In_ DWORD dwReason, + _In_opt_ LPVOID /* lpReserved */, + _In_ _ATL_OBJMAP_ENTRY* pObjMap, + _In_ const GUID* pLibID); + + BOOL WINAPI _DllMain( + _In_ HINSTANCE hInstance, + _In_ DWORD dwReason, + _In_opt_ LPVOID /* lpReserved */, + _In_ _ATL_OBJMAP_ENTRY* pObjMap, + _In_ const GUID* pLibID) + { + if (dwReason == DLL_PROCESS_ATTACH) + { + if (CAtlBaseModule::m_bInitFailed) + { + ATLASSERT(0); + return FALSE; + } + + if (FAILED(Init(pObjMap, hInstance, pLibID))) + { + Term(); + return FALSE; + } + } + else if (dwReason == DLL_PROCESS_DETACH) + Term(); + return TRUE; // ok + } + + HRESULT DllCanUnloadNow() throw() + { + return (GetLockCount()==0) ? S_OK : S_FALSE; + } + HRESULT DllGetClassObject( + _In_ REFCLSID rclsid, + _In_ REFIID riid, + _Deref_out_ LPVOID* ppv) throw() + { + return GetClassObject(rclsid, riid, ppv); + } + + HRESULT DllRegisterServer(_In_ BOOL bRegTypeLib = TRUE) throw() + { + // registers object, typelib and all interfaces in typelib + return RegisterServer(bRegTypeLib); + } + + HRESULT DllUnregisterServer(_In_ BOOL bUnRegTypeLib = TRUE) throw() + { + return UnregisterServer(bUnRegTypeLib); + } + +private: + static HRESULT RegisterProgIDHelper( + _In_z_ LPCTSTR lpszCLSID, + _In_z_ LPCTSTR lpszProgID, + _In_opt_z_ LPCTSTR lpszCurVerProgID, + _In_z_ LPCTSTR lpszUserDesc, + _In_ BOOL bIsVerIndProgID); +}; + +#pragma managed(push, off) +inline BOOL WINAPI CComModule::DllMain( + _In_ HINSTANCE hInstance, + _In_ DWORD dwReason, + _In_opt_ LPVOID lpReserved, + _In_ _ATL_OBJMAP_ENTRY* pObjMap, + _In_ const GUID* pLibID) +{ +#if !defined(_ATL_NATIVE_INITIALIZATION) +#pragma warning(push) +#pragma warning(disable:4483) + using namespace __identifier(""); +#pragma warning(pop) + UNREFERENCED_PARAMETER(lpReserved); + if (dwReason == DLL_PROCESS_ATTACH) + { + ATLASSERT(ComModuleInitialized == false); + ComModuleHelper.Initialize(this, hInstance, pObjMap, pLibID); + } + return TRUE; +#else + return _DllMain(hInstance, dwReason, lpReserved, pObjMap, pLibID); +#endif +} +#pragma managed(pop) + +#endif // !_ATL_NO_COMMODULE + +///////////////////////////////////////////////////////////////////////////// +// Thread creation helpers + +// CRTThreadTraits +// This class is for use with CThreadPool or CWorkerThread +// It should be used if the worker class will use CRT +// functions. +class CRTThreadTraits +{ +public: + static HANDLE CreateThread( + _In_opt_ LPSECURITY_ATTRIBUTES lpsa, + _In_ DWORD dwStackSize, + _In_ LPTHREAD_START_ROUTINE pfnThreadProc, + _In_opt_ void *pvParam, + _In_ DWORD dwCreationFlags, + _Out_opt_ DWORD *pdwThreadId) throw() + { + ATLASSERT(sizeof(DWORD) == sizeof(unsigned int)); // sanity check for pdwThreadId + + // _beginthreadex calls CreateThread which will set the last error value before it returns. + return (HANDLE) _beginthreadex(lpsa, dwStackSize, (unsigned int (__stdcall *)(void *)) pfnThreadProc, pvParam, dwCreationFlags, (unsigned int *) pdwThreadId); + } +}; + +// Win32ThreadTraits +// This class is for use with CThreadPool or CWorkerThread +// It should be used if the worker class will not use CRT +// functions. +class Win32ThreadTraits +{ +public: + static HANDLE CreateThread( + _In_opt_ LPSECURITY_ATTRIBUTES lpsa, + _In_ DWORD dwStackSize, + _In_ LPTHREAD_START_ROUTINE pfnThreadProc, + _In_opt_ void *pvParam, + _In_ DWORD dwCreationFlags, + _Out_opt_ DWORD *pdwThreadId) throw() + { + return ::CreateThread(lpsa, dwStackSize, pfnThreadProc, pvParam, dwCreationFlags, pdwThreadId); + } +}; + +typedef CRTThreadTraits DefaultThreadTraits; + +template +HANDLE CreateThreadT( + _In_opt_ LPSECURITY_ATTRIBUTES lpsa, + _In_ DWORD dwStackSize, + _In_ DWORD (WINAPI * pfn)(_In_ T *pparam), + _In_opt_ T *pparam, + _In_ DWORD dwCreationFlags, + _Out_opt_ LPDWORD pdw) +{ + return DefaultThreadTraits::CreateThread(lpsa, + dwStackSize, + (LPTHREAD_START_ROUTINE)pfn, + pparam, + dwCreationFlags, + pdw); +} + +template +HANDLE AtlCreateThread(_In_ DWORD (WINAPI* pfn)(_In_ T *pparam), _In_ T *pparam) +{ + return CreateThreadT(0, 0, pfn, pparam, 0, 0); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +// Thread Pooling classes + +class _AtlAptCreateObjData +{ +public: + _ATL_CREATORFUNC* pfnCreateInstance; + const IID* piid; + HANDLE hEvent; + LPSTREAM pStream; + HRESULT hRes; +}; + +class CComApartment +{ +public: + CComApartment() + { + m_nLockCnt = 0; + m_hThread = NULL; + } + static UINT ATL_CREATE_OBJECT; + static DWORD WINAPI _Apartment(_In_ void* pv) + { + ATLENSURE(pv != NULL); + return ((CComApartment*)pv)->Apartment(); + } + DWORD Apartment() + { + CoInitialize(NULL); + MSG msg; + while(GetMessage(&msg, 0, 0, 0) > 0) + { + if (msg.message == ATL_CREATE_OBJECT) + { + _AtlAptCreateObjData* pdata = (_AtlAptCreateObjData*)msg.lParam; + IUnknown* pUnk = NULL; + pdata->hRes = pdata->pfnCreateInstance(NULL, __uuidof(IUnknown), (void**)&pUnk); + if (SUCCEEDED(pdata->hRes)) + pdata->hRes = CoMarshalInterThreadInterfaceInStream(*pdata->piid, pUnk, &pdata->pStream); + if (SUCCEEDED(pdata->hRes)) + { + pUnk->Release(); + } +#ifdef _DEBUG + else + { + } +#endif + SetEvent(pdata->hEvent); + } + DispatchMessage(&msg); + } + CoUninitialize(); + + return 0; + } + LONG Lock() + { + return CComGlobalsThreadModel::Increment(&m_nLockCnt); + } + LONG Unlock() + { + return CComGlobalsThreadModel::Decrement(&m_nLockCnt); + } + LONG GetLockCount() + { + return m_nLockCnt; + } + + DWORD m_dwThreadID; + HANDLE m_hThread; + LONG m_nLockCnt; +}; + +__declspec(selectany) UINT CComApartment::ATL_CREATE_OBJECT = 0; + +class CComSimpleThreadAllocator +{ +public: + CComSimpleThreadAllocator() + { + m_nThread = 0; + } + int GetThread(_In_opt_ CComApartment* /*pApt*/, _In_ int nThreads) + { + if (++m_nThread == nThreads) + m_nThread = 0; + return m_nThread; + } + int m_nThread; +}; + +#if !defined(__MINGW32__) +__interface IAtlAutoThreadModule +#else +class IAtlAutoThreadModule +#endif +{ +public: +#if defined(__MINGW32__) + virtual ~IAtlAutoThreadModule() {} +#endif + HRESULT CreateInstance( + _In_ void* pfnCreateInstance, + _In_ REFIID riid, + _Deref_out_ void** ppvObj); +}; + +#if !defined(__MINGW32__) +__declspec(selectany) IAtlAutoThreadModule* _pAtlAutoThreadModule; +#else +IAtlAutoThreadModule* _pAtlAutoThreadModule; +#endif + +template +class ATL_NO_VTABLE CAtlAutoThreadModuleT : + public IAtlAutoThreadModule +{ +// This class is not for use in a DLL. +// If this class were used in a DLL, there will be a deadlock when the DLL is unloaded. +// because of dwWait's default value of INFINITE +public: + CAtlAutoThreadModuleT(_In_ int nThreads = T::GetDefaultThreads()) + { + ATLASSERT(_pAtlAutoThreadModule == NULL); + _pAtlAutoThreadModule = this; + m_pApartments = NULL; + m_nThreads= 0; + + ATLTRY(m_pApartments = new CComApartment[nThreads]); + ATLASSERT(m_pApartments != NULL); + if(m_pApartments == NULL) + { + CAtlBaseModule::m_bInitFailed = true; + ATLENSURE(0); + } + + memset(m_pApartments, 0, sizeof(CComApartment) * nThreads); + + m_nThreads = nThreads; + for (int i = 0; i < nThreads; i++) + { + typedef unsigned ( __stdcall *pfnThread )( void * ); + errno_t save_errno = Checked::get_errno(); + Checked::set_errno(0); + m_pApartments[i].m_hThread = (HANDLE)_beginthreadex(NULL, 0, (pfnThread)CComApartment::_Apartment, &m_pApartments[i], 0, (UINT*)&m_pApartments[i].m_dwThreadID); + if (m_pApartments[i].m_hThread == NULL) + { + HRESULT hr = E_FAIL; + // _beginthreadex sets errno when it fails + switch (Checked::get_errno()) + { + case EAGAIN: + hr = HRESULT_FROM_WIN32(ERROR_TOO_MANY_TCBS); + break; + case EINVAL: + hr = E_INVALIDARG; + break; + } + ATLASSERT(0); + CAtlBaseModule::m_bInitFailed = true; + break; + } + Checked::set_errno(save_errno); + } + if (!CAtlBaseModule::m_bInitFailed) + CComApartment::ATL_CREATE_OBJECT = RegisterWindowMessage(_T("ATL_CREATE_OBJECT")); + } + + virtual ~CAtlAutoThreadModuleT() + { + if (m_pApartments == NULL) + return; + + DWORD dwCurrentThreadId = GetCurrentThreadId(); + int nCurrentThread = -1; + for (int i=0; i < m_nThreads; i++) + { + if (m_pApartments[i].m_hThread == NULL) + continue; + if (m_pApartments[i].m_dwThreadID == dwCurrentThreadId) + { + nCurrentThread = i; + continue; + } + while (::PostThreadMessage(m_pApartments[i].m_dwThreadID, WM_QUIT, 0, 0) == 0) + { + /* Unfortunately, we can not use GetLastError() here to determine + * what went wrong here. It could be the thread ID is invalid (in this case + * we want to break from this loop) or it could be the message loop for this + * thread has not been created yet (in this case, we should sleep and try again). + * However, GetLastError() will return ERROR_INVALID_THREAD_ID for both cases. + */ + ::Sleep(100); + } + ::WaitForSingleObject(m_pApartments[i].m_hThread, dwWait); + CloseHandle(m_pApartments[i].m_hThread); + } + if (nCurrentThread != -1) + CloseHandle(m_pApartments[nCurrentThread].m_hThread); + + delete [] m_pApartments; + m_pApartments = NULL; + } + + HRESULT CreateInstance( + _In_opt_ void* pfnCreateInstance, + _In_ REFIID riid, + _Deref_out_ void** ppvObj) + { + ATLASSERT(ppvObj != NULL); + if (ppvObj == NULL) + return E_POINTER; + *ppvObj = NULL; + + _ATL_CREATORFUNC* pFunc = (_ATL_CREATORFUNC*) pfnCreateInstance; + _AtlAptCreateObjData data; + data.pfnCreateInstance = pFunc; + data.piid = &riid; + data.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + ATLENSURE(data.hEvent != NULL); + data.hRes = S_OK; + int nThread = m_Allocator.GetThread(m_pApartments, m_nThreads); + int nIterations = 0; + while(::PostThreadMessage(m_pApartments[nThread].m_dwThreadID, CComApartment::ATL_CREATE_OBJECT, 0, (LPARAM)&data) == 0 && ++nIterations < 100) + { + Sleep(100); + } + if (nIterations < 100) + { + AtlWaitWithMessageLoop(data.hEvent); + } + else + { + data.hRes = AtlHresultFromLastError(); + } + if (data.hEvent) + CloseHandle(data.hEvent); + if (SUCCEEDED(data.hRes)) + data.hRes = CoGetInterfaceAndReleaseStream(data.pStream, riid, ppvObj); + return data.hRes; + } + DWORD dwThreadID; + int m_nThreads; + CComApartment* m_pApartments; + ThreadAllocator m_Allocator; + static int GetDefaultThreads() + { + SYSTEM_INFO si; + GetSystemInfo(&si); + return si.dwNumberOfProcessors * 4; + } +}; + +class CAtlAutoThreadModule : + public CAtlAutoThreadModuleT +{ +public : +}; + +#ifndef _ATL_NO_COMMODULE + +template +class CComAutoThreadModule : + public CComModule, + public CAtlAutoThreadModuleT, ThreadAllocator, dwWait> +{ +public: + CComAutoThreadModule(_In_ int nThreads = GetDefaultThreads()) : + CAtlAutoThreadModuleT, ThreadAllocator, dwWait>(nThreads) + { + } + HRESULT Init( + _In_ _ATL_OBJMAP_ENTRY* p, + _In_ HINSTANCE h, + _In_opt_ const GUID* plibid = NULL, + _In_ int nThreads = GetDefaultThreads()) + { + nThreads; + ATLASSERT(nThreads == GetDefaultThreads() && _T("Set number of threads through the constructor")); + return CComModule::Init(p, h, plibid); + } +}; + +#endif // !_ATL_NO_COMMODULE + +// Used in CThreadPool +class Win32WaitTraits +{ +public: + static DWORD WaitForSingleObject( + _In_ HANDLE hHandle, + _In_ DWORD dwTimeout) + { + return ::WaitForSingleObject(hHandle, dwTimeout); + } +}; + +typedef Win32WaitTraits DefaultWaitTraits; + +///////////////////////////////////////////////////////////////////////////// +// GIT Pointer + +template +class CComGITPtr +{ +public: + CComGITPtr() throw() + { + m_dwCookie = 0; + } + CComGITPtr(_In_ T* p) + { + m_dwCookie = 0; + HRESULT hr = Attach(p); + + if (FAILED(hr)) + AtlThrow(hr); + } + CComGITPtr(_In_ const CComGITPtr& git) + { + m_dwCookie = 0; + + if (git.m_dwCookie != 0) + { + CComPtr spT; + + HRESULT hr = git.CopyTo(&spT); + if (SUCCEEDED(hr)) + hr = Attach(spT); + + if (FAILED(hr)) + AtlThrow(hr); + } + } + explicit CComGITPtr(_In_ DWORD dwCookie) throw() + { + ATLASSUME(dwCookie != NULL); + m_dwCookie = dwCookie; + +#ifdef _DEBUG + CComPtr spT; + HRESULT hr = CopyTo(&spT); + ATLASSERT(SUCCEEDED(hr)); +#endif + } + +#if !defined(__MINGW32__) + CComGITPtr(CComGITPtr&& rv) + { + m_dwCookie = rv.m_dwCookie; + rv.m_dwCookie = 0; + } + + CComGITPtr& operator=(CComGITPtr&& rv) + { + if (this != &rv) + { + ATLVERIFY(SUCCEEDED(Revoke())); + + m_dwCookie = rv.m_dwCookie; + rv.m_dwCookie = 0; + } + + return *this; + } +#endif + + ~CComGITPtr() throw() + { + Revoke(); + } + CComGITPtr& operator=(_In_ const CComGITPtr& git) + { + if (this != &git) + { + if (git.m_dwCookie == 0) + { + ATLVERIFY(SUCCEEDED(Revoke())); + } + else + { + CComPtr spT; + + HRESULT hr = git.CopyTo(&spT); + if (SUCCEEDED(hr)) + { + hr = Attach(spT); + } + + if (FAILED(hr)) + { + AtlThrow(hr); + } + } + } + return *this; + } + CComGITPtr& operator=(_In_ T* p) + { + HRESULT hr = Attach(p); + if (FAILED(hr)) + AtlThrow(hr); + return *this; + } + CComGITPtr& operator=(_In_ DWORD dwCookie) + { + if(*this!=dwCookie) + { + HRESULT hr = Attach(dwCookie); + if (FAILED(hr)) + { + AtlThrow(hr); + } + + m_dwCookie = dwCookie; + +#ifdef _DEBUG + CComPtr spT; + hr = CopyTo(&spT); + ATLASSERT(SUCCEEDED(hr)); +#endif + } + return *this; + } + + // basic comparison operators + bool operator!=(_In_ const CComGITPtr& git) const + { + return !operator==(git); + } + + bool operator!=(_In_ DWORD dwCookie) const + { + return !operator==(dwCookie); + } + + bool operator==(_In_ const CComGITPtr& git) const + { + return m_dwCookie==git.GetCookie(); + } + + bool operator==(_In_ DWORD dwCookie) const + { + return m_dwCookie==dwCookie; + } + + // Get the cookie from the class + operator DWORD() const + { + return m_dwCookie; + } + // Get the cookie from the class + DWORD GetCookie() const + { + return m_dwCookie; + } + // Register the passed interface pointer in the GIT + HRESULT Attach(_In_ T* p) throw() + { + if (p) + { + CComPtr spGIT; + HRESULT hr = E_FAIL; + hr = AtlGetGITPtr(&spGIT); + ATLASSERT(spGIT != NULL); + ATLASSERT(SUCCEEDED(hr)); + if (FAILED(hr)) + return hr; + + if (m_dwCookie != 0) + hr = spGIT->RevokeInterfaceFromGlobal(m_dwCookie); + if (FAILED(hr)) + return hr; + + return spGIT->RegisterInterfaceInGlobal(p, __uuidof(T), &m_dwCookie); + } + else + { + return Revoke(); + } + } + + HRESULT Attach(_In_ DWORD dwCookie) throw() + { + ATLASSERT(dwCookie != NULL); + HRESULT hr = Revoke(); + if (FAILED(hr)) + return hr; + m_dwCookie = dwCookie; + return S_OK; + } + + // Detach + DWORD Detach() throw() + { + DWORD dwCookie = m_dwCookie; + m_dwCookie = NULL; + return dwCookie; + } + + // Remove the interface from the GIT + HRESULT Revoke() throw() + { + HRESULT hr = S_OK; + if (m_dwCookie != 0) + { + CComPtr spGIT; + hr = AtlGetGITPtr(&spGIT); + + ATLASSERT(spGIT != NULL); + ATLASSERT(SUCCEEDED(hr)); + if (FAILED(hr)) + return hr; + + hr = spGIT->RevokeInterfaceFromGlobal(m_dwCookie); + if (SUCCEEDED(hr)) + m_dwCookie = 0; + } + return hr; + } + // Get's the interface from the GIT and copies it to the passed pointer. The pointer + // must be released by the caller when finished. + HRESULT CopyTo(_Deref_out_ T** pp) const throw() + { + CComPtr spGIT; + HRESULT hr = E_FAIL; + hr = AtlGetGITPtr(&spGIT); + + ATLASSERT(spGIT != NULL); + ATLASSERT(SUCCEEDED(hr)); + if (FAILED(hr)) + return hr; + + ATLASSUME(m_dwCookie!=NULL); + return spGIT->GetInterfaceFromGlobal(m_dwCookie, __uuidof(T), (void**)pp); + } + DWORD m_dwCookie; +}; + +///////////////////////////////////////////////////////////////////////////// +// CRegKey + +class CRegKey +{ +public: + /// + /// CRegKey constructor + CRegKey() throw(); + CRegKey(_Inout_ CRegKey& key) throw(); + explicit CRegKey(_In_ HKEY hKey) throw(); + ~CRegKey() throw(); + + CRegKey& operator=(_Inout_ CRegKey& key) throw(); + +// Attributes +public: + operator HKEY() const throw(); + HKEY m_hKey; + REGSAM m_samWOW64; + +// Operations +public: + ATL_DEPRECATED("CRegKey::SetValue(DWORD, TCHAR *valueName) has been superseded by CRegKey::SetDWORDValue") + LONG SetValue( + _In_ DWORD dwValue, + _In_opt_z_ LPCTSTR lpszValueName); + + ATL_DEPRECATED("CRegKey::SetValue(TCHAR *value, TCHAR *valueName) has been superseded by CRegKey::SetStringValue and CRegKey::SetMultiStringValue") + LONG SetValue( + _In_z_ LPCTSTR lpszValue, + _In_opt_z_ LPCTSTR lpszValueName = NULL, + _In_ bool bMulti = false, + _In_ int nValueLen = -1); + LONG SetValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_ DWORD dwType, + _In_opt_ const void* pValue, + _In_ ULONG nBytes) throw(); + LONG SetGUIDValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_ REFGUID guidValue) throw(); + LONG SetBinaryValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_opt_ const void* pValue, + _In_ ULONG nBytes) throw(); + LONG SetDWORDValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_ DWORD dwValue) throw(); + LONG SetQWORDValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_ ULONGLONG qwValue) throw(); + LONG SetStringValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_opt_z_ LPCTSTR pszValue, + _In_ DWORD dwType = REG_SZ) throw(); + LONG SetMultiStringValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_z_ LPCTSTR pszValue) throw(); + + ATL_DEPRECATED("CRegKey::QueryValue(DWORD, TCHAR *valueName) has been superseded by CRegKey::QueryDWORDValue") + LONG QueryValue( + _Out_ DWORD& dwValue, + _In_opt_z_ LPCTSTR lpszValueName); + + ATL_DEPRECATED("CRegKey::QueryValue(TCHAR *value, TCHAR *valueName) has been superseded by CRegKey::QueryStringValue and CRegKey::QueryMultiStringValue") + LONG QueryValue( + _Out_opt_z_cap_post_count_(*pdwCount, *pdwCount) LPTSTR szValue, + _In_opt_z_ LPCTSTR lpszValueName, + _Inout_ DWORD* pdwCount); + LONG QueryValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_opt_ DWORD* pdwType, + _Out_opt_ void* pData, + _Inout_ ULONG* pnBytes) throw(); + LONG QueryGUIDValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_ GUID& guidValue) throw(); + LONG QueryBinaryValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_opt_ void* pValue, + _Inout_opt_ ULONG* pnBytes) throw(); + LONG QueryDWORDValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_ DWORD& dwValue) throw(); + LONG QueryQWORDValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_ ULONGLONG& qwValue) throw(); + LONG QueryStringValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_opt_z_cap_post_count_(*pnChars, *pnChars) LPTSTR pszValue, + _Inout_ ULONG* pnChars) throw(); + LONG QueryMultiStringValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_opt_z_cap_post_count_(*pnChars, *pnChars) LPTSTR pszValue, + _Inout_ ULONG* pnChars) throw(); + + // Get the key's security attributes. + LONG GetKeySecurity( + _In_ SECURITY_INFORMATION si, + _Out_opt_ PSECURITY_DESCRIPTOR psd, + _Inout_ LPDWORD pnBytes) throw(); + // Set the key's security attributes. + LONG SetKeySecurity( + _In_ SECURITY_INFORMATION si, + _In_ PSECURITY_DESCRIPTOR psd) throw(); + + LONG SetKeyValue( + _In_z_ LPCTSTR lpszKeyName, + _In_opt_z_ LPCTSTR lpszValue, + _In_opt_z_ LPCTSTR lpszValueName = NULL) throw(); + static LONG WINAPI SetValue( + _In_ HKEY hKeyParent, + _In_z_ LPCTSTR lpszKeyName, + _In_opt_z_ LPCTSTR lpszValue, + _In_opt_z_ LPCTSTR lpszValueName = NULL); + + // Create a new registry key (or open an existing one). + LONG Create( + _In_ HKEY hKeyParent, + _In_z_ LPCTSTR lpszKeyName, + _In_opt_z_ LPTSTR lpszClass = REG_NONE, + _In_ DWORD dwOptions = REG_OPTION_NON_VOLATILE, + _In_ REGSAM samDesired = KEY_READ | KEY_WRITE, + _In_opt_ LPSECURITY_ATTRIBUTES lpSecAttr = NULL, + _Out_opt_ LPDWORD lpdwDisposition = NULL) throw(); + // Open an existing registry key. + LONG Open( + _In_ HKEY hKeyParent, + _In_opt_z_ LPCTSTR lpszKeyName, + _In_ REGSAM samDesired = KEY_READ | KEY_WRITE) throw(); + // Close the registry key. + LONG Close() throw(); + // Flush the key's data to disk. + LONG Flush() throw(); + + // Detach the CRegKey object from its HKEY. Releases ownership. + HKEY Detach() throw(); + // Attach the CRegKey object to an existing HKEY. Takes ownership. + void Attach(_In_ HKEY hKey) throw(); + + // Enumerate the subkeys of the key. + LONG EnumKey( + _In_ DWORD iIndex, + _Out_z_cap_post_count_(*pnNameLength, *pnNameLength) LPTSTR pszName, + _Inout_ LPDWORD pnNameLength, + _Out_opt_ FILETIME* pftLastWriteTime = NULL) throw(); + LONG NotifyChangeKeyValue( + _In_ BOOL bWatchSubtree, + _In_ DWORD dwNotifyFilter, + _In_ HANDLE hEvent, + _In_ BOOL bAsync = TRUE) throw(); + + LONG DeleteSubKey(_In_z_ LPCTSTR lpszSubKey) throw(); + LONG RecurseDeleteKey(_In_z_ LPCTSTR lpszKey) throw(); + LONG DeleteValue(_In_z_ LPCTSTR lpszValue) throw(); +}; + +inline CRegKey::CRegKey() throw() : + m_hKey( NULL ), m_samWOW64(0) +{ +} + +inline CRegKey::CRegKey(_Inout_ CRegKey& key) throw() : + m_hKey( NULL ), m_samWOW64(key.m_samWOW64) +{ + Attach( key.Detach() ); +} + +inline CRegKey::CRegKey(_In_ HKEY hKey) throw() : + m_hKey(hKey), m_samWOW64(0) +{ +} + +inline CRegKey::~CRegKey() throw() +{Close();} + +inline CRegKey& CRegKey::operator=(_Inout_ CRegKey& key) throw() +{ + if(m_hKey!=key.m_hKey) + { + Close(); + Attach( key.Detach() ); + m_samWOW64 = key.m_samWOW64; + } + return( *this ); +} + +inline CRegKey::operator HKEY() const throw() +{ + return m_hKey; +} + +inline HKEY CRegKey::Detach() throw() +{ + HKEY hKey = m_hKey; + m_hKey = NULL; + m_samWOW64 = 0; + return hKey; +} + +inline void CRegKey::Attach(_In_ HKEY hKey) throw() +{ + ATLASSUME(m_hKey == NULL); + m_hKey = hKey; + m_samWOW64 = 0; +} + +inline LONG CRegKey::DeleteSubKey(_In_z_ LPCTSTR lpszSubKey) throw() +{ + ATLASSUME(m_hKey != NULL); + +#if WINVER >= 0x0501 + typedef LSTATUS (WINAPI * PFNRegDeleteKeyEx)(_In_ HKEY, _In_z_ LPCTSTR, _In_ REGSAM, _In_ DWORD); + static bool bInitialized = false; + static PFNRegDeleteKeyEx pfnRegDeleteKeyEx = NULL; + + if (!bInitialized) + { + HMODULE hAdvapi32 = GetModuleHandle(_T("Advapi32.dll")); + if (hAdvapi32 != NULL) + { +#ifdef _UNICODE + pfnRegDeleteKeyEx = (PFNRegDeleteKeyEx)GetProcAddress(hAdvapi32, "RegDeleteKeyExW"); +#else + pfnRegDeleteKeyEx = (PFNRegDeleteKeyEx)GetProcAddress(hAdvapi32, "RegDeleteKeyExA"); +#endif // _UNICODE + } + bInitialized = true; + } + + if (pfnRegDeleteKeyEx != NULL) + { + return pfnRegDeleteKeyEx(m_hKey, lpszSubKey, m_samWOW64, 0); + } + +#endif // WINVER + + return RegDeleteKey(m_hKey, lpszSubKey); +} + +inline LONG CRegKey::DeleteValue(_In_z_ LPCTSTR lpszValue) throw() +{ + ATLASSUME(m_hKey != NULL); + return RegDeleteValue(m_hKey, (LPTSTR)lpszValue); +} + +inline LONG CRegKey::Close() throw() +{ + LONG lRes = ERROR_SUCCESS; + if (m_hKey != NULL) + { + lRes = RegCloseKey(m_hKey); + m_hKey = NULL; + } + m_samWOW64 = 0; + return lRes; +} + +inline LONG CRegKey::Flush() throw() +{ + ATLASSUME(m_hKey != NULL); + + return ::RegFlushKey(m_hKey); +} + +inline LONG CRegKey::EnumKey( + _In_ DWORD iIndex, + _Out_z_cap_post_count_(*pnNameLength, *pnNameLength) LPTSTR pszName, + _Inout_ LPDWORD pnNameLength, + _Out_opt_ FILETIME* pftLastWriteTime) throw() +{ + FILETIME ftLastWriteTime; + + ATLASSUME(m_hKey != NULL); + if (pftLastWriteTime == NULL) + { + pftLastWriteTime = &ftLastWriteTime; + } + + return ::RegEnumKeyEx(m_hKey, iIndex, pszName, pnNameLength, NULL, NULL, NULL, pftLastWriteTime); +} + +inline LONG CRegKey::NotifyChangeKeyValue( + _In_ BOOL bWatchSubtree, + _In_ DWORD dwNotifyFilter, + _In_ HANDLE hEvent, + _In_ BOOL bAsync) throw() +{ + ATLASSUME(m_hKey != NULL); + ATLASSERT((hEvent != NULL) || !bAsync); + + return ::RegNotifyChangeKeyValue(m_hKey, bWatchSubtree, dwNotifyFilter, hEvent, bAsync); +} + +inline LONG CRegKey::Create( + _In_ HKEY hKeyParent, + _In_z_ LPCTSTR lpszKeyName, + _In_opt_z_ LPTSTR lpszClass, + _In_ DWORD dwOptions, + _In_ REGSAM samDesired, + _In_opt_ LPSECURITY_ATTRIBUTES lpSecAttr, + _Out_opt_ LPDWORD lpdwDisposition) throw() +{ + ATLASSERT(hKeyParent != NULL); + DWORD dw; + HKEY hKey = NULL; + LONG lRes = RegCreateKeyEx(hKeyParent, lpszKeyName, 0, lpszClass, dwOptions, samDesired, lpSecAttr, &hKey, &dw); + if (lpdwDisposition != NULL) + *lpdwDisposition = dw; + if (lRes == ERROR_SUCCESS) + { + lRes = Close(); + m_hKey = hKey; +#if WINVER >= 0x0501 + m_samWOW64 = samDesired & (KEY_WOW64_32KEY | KEY_WOW64_64KEY); +#endif + } + return lRes; +} + +inline LONG CRegKey::Open( + _In_ HKEY hKeyParent, + _In_opt_z_ LPCTSTR lpszKeyName, + _In_ REGSAM samDesired) throw() +{ + ATLASSUME(hKeyParent != NULL); + HKEY hKey = NULL; + LONG lRes = RegOpenKeyEx(hKeyParent, lpszKeyName, 0, samDesired, &hKey); + if (lRes == ERROR_SUCCESS) + { + lRes = Close(); + ATLASSERT(lRes == ERROR_SUCCESS); + m_hKey = hKey; +#if WINVER >= 0x0501 + m_samWOW64 = samDesired & (KEY_WOW64_32KEY | KEY_WOW64_64KEY); +#endif + } + return lRes; +} + +#pragma warning(push) +#pragma warning(disable: 4996) +inline LONG CRegKey::QueryValue( + _Out_ DWORD& dwValue, + _In_opt_z_ LPCTSTR lpszValueName) +{ + DWORD dwType = 0; + DWORD dwCount = sizeof(DWORD); + LONG lRes = RegQueryValueEx(m_hKey, lpszValueName, NULL, &dwType, + (LPBYTE)&dwValue, &dwCount); + ATLASSERT((lRes!=ERROR_SUCCESS) || (dwType == REG_DWORD)); + ATLASSERT((lRes!=ERROR_SUCCESS) || (dwCount == sizeof(DWORD))); + if (dwType != REG_DWORD) + return ERROR_INVALID_DATA; + return lRes; +} + +ATLPREFAST_SUPPRESS(6053 6385) +inline LONG CRegKey::QueryValue( + _Out_opt_z_cap_post_count_(*pdwCount, *pdwCount) LPTSTR pszValue, + _In_opt_z_ LPCTSTR lpszValueName, + _Inout_ DWORD* pdwCount) +{ + ATLENSURE(pdwCount != NULL); + DWORD dwType = 0; + LONG lRes = RegQueryValueEx(m_hKey, lpszValueName, NULL, &dwType, (LPBYTE)pszValue, pdwCount); + ATLASSERT((lRes!=ERROR_SUCCESS) || (dwType == REG_SZ) || + (dwType == REG_MULTI_SZ) || (dwType == REG_EXPAND_SZ)); + if (pszValue != NULL) + { + if(*pdwCount>0) + { + switch(dwType) + { + case REG_SZ: + case REG_EXPAND_SZ: + if ((*pdwCount) % sizeof(TCHAR) != 0 || pszValue[(*pdwCount) / sizeof(TCHAR) - 1] != 0) + { + pszValue[0]=_T('\0'); + return ERROR_INVALID_DATA; + } + break; + case REG_MULTI_SZ: + if ((*pdwCount) % sizeof(TCHAR) != 0 || (*pdwCount) / sizeof(TCHAR) < 1 || pszValue[(*pdwCount) / sizeof(TCHAR) -1] != 0 || (((*pdwCount) / sizeof(TCHAR))>1 && pszValue[(*pdwCount) / sizeof(TCHAR) - 2] != 0) ) + { + pszValue[0]=_T('\0'); + return ERROR_INVALID_DATA; + } + break; + default: + // Ensure termination + pszValue[0]=_T('\0'); + return ERROR_INVALID_DATA; + } + } + else + { + // this is a blank one with no data yet + // Ensure termination + pszValue[0]=_T('\0'); + } + } + return lRes; +} +ATLPREFAST_UNSUPPRESS() + +inline LONG CRegKey::QueryValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_opt_ DWORD* pdwType, + _Out_opt_ void* pData, + _Inout_ ULONG* pnBytes) throw() +{ + ATLASSUME(m_hKey != NULL); + + return( ::RegQueryValueEx(m_hKey, pszValueName, NULL, pdwType, static_cast< LPBYTE >( pData ), pnBytes) ); +} + +inline LONG CRegKey::QueryDWORDValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_ DWORD& dwValue) throw() +{ + LONG lRes; + ULONG nBytes; + DWORD dwType; + + ATLASSUME(m_hKey != NULL); + + nBytes = sizeof(DWORD); + lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast(&dwValue), + &nBytes); + if (lRes != ERROR_SUCCESS) + return lRes; + if (dwType != REG_DWORD) + return ERROR_INVALID_DATA; + + return ERROR_SUCCESS; +} +inline LONG CRegKey::QueryQWORDValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_ ULONGLONG& qwValue) throw() +{ + LONG lRes; + ULONG nBytes; + DWORD dwType; + + ATLASSUME(m_hKey != NULL); + + nBytes = sizeof(ULONGLONG); + lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast(&qwValue), + &nBytes); + if (lRes != ERROR_SUCCESS) + return lRes; + if (dwType != REG_QWORD) + return ERROR_INVALID_DATA; + + return ERROR_SUCCESS; +} + +inline LONG CRegKey::QueryBinaryValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_opt_ void* pValue, + _Inout_opt_ ULONG* pnBytes) throw() +{ + LONG lRes; + DWORD dwType; + + ATLASSERT(pnBytes != NULL); + ATLASSUME(m_hKey != NULL); + + lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast(pValue), + pnBytes); + if (lRes != ERROR_SUCCESS) + return lRes; + if (dwType != REG_BINARY) + return ERROR_INVALID_DATA; + + return ERROR_SUCCESS; +} + +ATLPREFAST_SUPPRESS(6053) +/* prefast noise VSW 496818 */ +inline LONG CRegKey::QueryStringValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_opt_z_cap_post_count_(*pnChars, *pnChars) LPTSTR pszValue, + _Inout_ ULONG* pnChars) throw() +{ + LONG lRes; + DWORD dwType; + ULONG nBytes; + + ATLASSUME(m_hKey != NULL); + ATLASSERT(pnChars != NULL); + + nBytes = (*pnChars)*sizeof(TCHAR); + *pnChars = 0; + lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast(pszValue), + &nBytes); + + if (lRes != ERROR_SUCCESS) + { + return lRes; + } + + if(dwType != REG_SZ && dwType != REG_EXPAND_SZ) + { + return ERROR_INVALID_DATA; + } + + if (pszValue != NULL) + { + if(nBytes!=0) + { +ATLPREFAST_SUPPRESS(6385) // suppress noisy code analysis warning due to annotation on RegQueryValueEx + if ((nBytes % sizeof(TCHAR) != 0) || (pszValue[nBytes / sizeof(TCHAR) -1] != 0)) + { + return ERROR_INVALID_DATA; + } +ATLPREFAST_UNSUPPRESS() + } + else + { + pszValue[0]=_T('\0'); + } + } + + *pnChars = nBytes/sizeof(TCHAR); + + return ERROR_SUCCESS; +} +ATLPREFAST_UNSUPPRESS() + +ATLPREFAST_SUPPRESS(6053) +/* prefast noise VSW 496818 */ +inline LONG CRegKey::QueryMultiStringValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_opt_z_cap_post_count_(*pnChars, *pnChars) LPTSTR pszValue, + _Inout_ ULONG* pnChars) throw() +{ + LONG lRes; + DWORD dwType; + ULONG nBytes; + + ATLASSUME(m_hKey != NULL); + ATLASSERT(pnChars != NULL); + + if (pszValue != NULL && *pnChars < 2) + return ERROR_INSUFFICIENT_BUFFER; + + nBytes = (*pnChars)*sizeof(TCHAR); + *pnChars = 0; + + lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast(pszValue), + &nBytes); + if (lRes != ERROR_SUCCESS) + return lRes; + if (dwType != REG_MULTI_SZ) + return ERROR_INVALID_DATA; + if (pszValue != NULL && (nBytes % sizeof(TCHAR) != 0 || nBytes / sizeof(TCHAR) < 1 || pszValue[nBytes / sizeof(TCHAR) -1] != 0 || ((nBytes/sizeof(TCHAR))>1 && pszValue[nBytes / sizeof(TCHAR) - 2] != 0))) + return ERROR_INVALID_DATA; + + *pnChars = nBytes/sizeof(TCHAR); + + return ERROR_SUCCESS; +} +ATLPREFAST_UNSUPPRESS() + +inline LONG CRegKey::QueryGUIDValue( + _In_opt_z_ LPCTSTR pszValueName, + _Out_ GUID& guidValue) throw() +{ + TCHAR szGUID[64]; + LONG lRes; + ULONG nCount; + HRESULT hr; + + ATLASSUME(m_hKey != NULL); + + guidValue = GUID_NULL; + + nCount = 64; + lRes = QueryStringValue(pszValueName, szGUID, &nCount); + + if (lRes != ERROR_SUCCESS) + return lRes; + + if(szGUID[0] != _T('{')) + return ERROR_INVALID_DATA; + + USES_CONVERSION_EX; + LPOLESTR lpstr = T2OLE_EX(szGUID, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if(lpstr == NULL) + return E_OUTOFMEMORY; +#endif + + hr = ::CLSIDFromString(lpstr, &guidValue); + if (FAILED(hr)) + return ERROR_INVALID_DATA; + + return ERROR_SUCCESS; +} + +inline LONG WINAPI CRegKey::SetValue( + _In_ HKEY hKeyParent, + _In_z_ LPCTSTR lpszKeyName, + _In_opt_z_ LPCTSTR lpszValue, + _In_opt_z_ LPCTSTR lpszValueName) +{ + ATLASSERT(lpszValue != NULL); + CRegKey key; + LONG lRes = key.Create(hKeyParent, lpszKeyName); + if (lRes == ERROR_SUCCESS) + lRes = key.SetStringValue(lpszValueName, lpszValue); + return lRes; +} + +inline LONG CRegKey::SetKeyValue( + _In_z_ LPCTSTR lpszKeyName, + _In_opt_z_ LPCTSTR lpszValue, + _In_opt_z_ LPCTSTR lpszValueName) throw() +{ + ATLASSERT(lpszValue != NULL); + CRegKey key; + LONG lRes = key.Create(m_hKey, lpszKeyName, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE | m_samWOW64); + if (lRes == ERROR_SUCCESS) + lRes = key.SetStringValue(lpszValueName, lpszValue); + return lRes; +} + +#pragma warning(push) +#pragma warning(disable: 4996) +inline LONG CRegKey::SetValue( + _In_ DWORD dwValue, + _In_opt_z_ LPCTSTR pszValueName) +{ + ATLASSUME(m_hKey != NULL); + return SetDWORDValue(pszValueName, dwValue); +} + +inline LONG CRegKey::SetValue( + _In_z_ LPCTSTR lpszValue, + _In_opt_z_ LPCTSTR lpszValueName, + _In_ bool bMulti, + _In_ int nValueLen) +{ + ATLENSURE(lpszValue != NULL); + ATLASSUME(m_hKey != NULL); + + if (bMulti && nValueLen == -1) + return ERROR_INVALID_PARAMETER; + + if (nValueLen == -1) + nValueLen = lstrlen(lpszValue) + 1; + + DWORD dwType = bMulti ? REG_MULTI_SZ : REG_SZ; + + return ::RegSetValueEx(m_hKey, lpszValueName, 0, dwType, + reinterpret_cast(lpszValue), nValueLen*sizeof(TCHAR)); +} +#pragma warning(pop) + +inline LONG CRegKey::SetValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_ DWORD dwType, + _In_opt_ const void* pValue, + _In_ ULONG nBytes) throw() +{ + ATLASSUME(m_hKey != NULL); + return ::RegSetValueEx(m_hKey, pszValueName, 0, dwType, static_cast(pValue), nBytes); +} + +inline LONG CRegKey::SetBinaryValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_opt_ const void* pData, + _In_ ULONG nBytes) throw() +{ + ATLASSUME(m_hKey != NULL); + return ::RegSetValueEx(m_hKey, pszValueName, 0, REG_BINARY, reinterpret_cast(pData), nBytes); +} + +inline LONG CRegKey::SetDWORDValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_ DWORD dwValue) throw() +{ + ATLASSUME(m_hKey != NULL); + return ::RegSetValueEx(m_hKey, pszValueName, 0, REG_DWORD, reinterpret_cast(&dwValue), sizeof(DWORD)); +} + +inline LONG CRegKey::SetQWORDValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_ ULONGLONG qwValue) throw() +{ + ATLASSUME(m_hKey != NULL); + return ::RegSetValueEx(m_hKey, pszValueName, 0, REG_QWORD, reinterpret_cast(&qwValue), sizeof(ULONGLONG)); +} + +inline LONG CRegKey::SetStringValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_opt_z_ LPCTSTR pszValue, + _In_ DWORD dwType) throw() +{ + ATLASSUME(m_hKey != NULL); + ATLENSURE_RETURN_VAL(pszValue != NULL, ERROR_INVALID_DATA); + ATLASSERT((dwType == REG_SZ) || (dwType == REG_EXPAND_SZ)); + + return ::RegSetValueEx(m_hKey, pszValueName, 0, dwType, reinterpret_cast(pszValue), (lstrlen(pszValue)+1)*sizeof(TCHAR)); +} + +inline LONG CRegKey::SetMultiStringValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_z_ LPCTSTR pszValue) throw() +{ + LPCTSTR pszTemp; + ULONG nBytes; + ULONG nLength; + + ATLASSUME(m_hKey != NULL); + ATLENSURE_RETURN_VAL(pszValue != NULL, ERROR_INVALID_DATA); + + // Find the total length (in bytes) of all of the strings, including the + // terminating '\0' of each string, and the second '\0' that terminates + // the list. + nBytes = 0; + pszTemp = pszValue; + do + { + nLength = lstrlen(pszTemp)+1; + pszTemp += nLength; + nBytes += nLength*sizeof(TCHAR); + } while (nLength != 1); + + return ::RegSetValueEx(m_hKey, pszValueName, 0, REG_MULTI_SZ, reinterpret_cast(pszValue), + nBytes); +} + +inline LONG CRegKey::SetGUIDValue( + _In_opt_z_ LPCTSTR pszValueName, + _In_ REFGUID guidValue) throw() +{ + OLECHAR szGUID[64]; + + ATLASSUME(m_hKey != NULL); + + ::StringFromGUID2(guidValue, szGUID, 64); + + USES_CONVERSION_EX; + LPCTSTR lpstr = OLE2CT_EX(szGUID, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if(lpstr == NULL) + return E_OUTOFMEMORY; +#endif + return SetStringValue(pszValueName, lpstr); +} + +inline LONG CRegKey::GetKeySecurity( + _In_ SECURITY_INFORMATION si, + _Out_opt_ PSECURITY_DESCRIPTOR psd, + _Inout_ LPDWORD pnBytes) throw() +{ + ATLASSUME(m_hKey != NULL); + ATLASSUME(pnBytes != NULL); + + return ::RegGetKeySecurity(m_hKey, si, psd, pnBytes); +} + +inline LONG CRegKey::SetKeySecurity( + _In_ SECURITY_INFORMATION si, + _In_ PSECURITY_DESCRIPTOR psd) throw() +{ + ATLASSUME(m_hKey != NULL); + ATLASSUME(psd != NULL); + + return ::RegSetKeySecurity(m_hKey, si, psd); +} + +inline LONG CRegKey::RecurseDeleteKey(_In_z_ LPCTSTR lpszKey) throw() +{ + CRegKey key; + LONG lRes = key.Open(m_hKey, lpszKey, KEY_READ | KEY_WRITE | m_samWOW64); + if (lRes != ERROR_SUCCESS) + { + if (lRes != ERROR_FILE_NOT_FOUND && lRes != ERROR_PATH_NOT_FOUND) + { + } + return lRes; + } + FILETIME time; + DWORD dwSize = 256; + TCHAR szBuffer[256]; + while (RegEnumKeyEx(key.m_hKey, 0, szBuffer, &dwSize, NULL, NULL, NULL, + &time)==ERROR_SUCCESS) + { + lRes = key.RecurseDeleteKey(szBuffer); + if (lRes != ERROR_SUCCESS) + return lRes; + dwSize = 256; + } + key.Close(); + return DeleteSubKey(lpszKey); +} + +#ifndef _ATL_NO_COMMODULE + +inline HRESULT CComModule::RegisterProgIDHelper( + _In_z_ LPCTSTR lpszCLSID, + _In_z_ LPCTSTR lpszProgID, + _In_opt_z_ LPCTSTR lpszCurVerProgID, + _In_z_ LPCTSTR lpszUserDesc, + _In_ BOOL bIsVerIndProgID) +{ + CRegKey keyProgID; + LONG lRes = keyProgID.Create(HKEY_CLASSES_ROOT, lpszProgID, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE); + if (lRes == ERROR_SUCCESS) + { + lRes = keyProgID.SetStringValue(NULL, lpszUserDesc); + if (lRes == ERROR_SUCCESS) + { + lRes = keyProgID.SetKeyValue(_T("CLSID"), lpszCLSID); + if (lRes == ERROR_SUCCESS) + { + lRes = bIsVerIndProgID ? keyProgID.SetKeyValue(_T("CurVer"), lpszCurVerProgID) : ERROR_SUCCESS; + if (lRes == ERROR_SUCCESS) + return S_OK; + } + } + } + return AtlHresultFromWin32(lRes); +} + +inline HRESULT CComModule::RegisterProgID( + _In_z_ LPCTSTR lpszCLSID, + _In_z_ LPCTSTR lpszProgID, + _In_z_ LPCTSTR lpszUserDesc) +{ + return RegisterProgIDHelper(lpszCLSID, lpszProgID, NULL, lpszUserDesc, FALSE); +} + +inline HRESULT CComModule::RegisterVersionIndependentProgID( + _In_z_ LPCTSTR lpszCLSID, + _In_z_ LPCTSTR lpszVerIndProgID, + _In_z_ LPCTSTR lpszCurVerProgID, + _In_z_ LPCTSTR lpszUserDesc) +{ + return RegisterProgIDHelper(lpszCLSID, lpszVerIndProgID, lpszCurVerProgID, lpszUserDesc, TRUE); +} + +inline HRESULT CComModule::RegisterAppId(_In_z_ LPCTSTR pAppId) +{ + HRESULT hr = S_OK; + return hr; +} + +inline HRESULT CComModule::UnregisterAppId(_In_z_ LPCTSTR pAppId) +{ + HRESULT hr = S_OK; + return hr; +} +#endif // !_ATL_NO_COMMODULE + +#ifdef _ATL_STATIC_REGISTRY +} // namespace ATL + + +#include + + +namespace ATL +{ + +#endif //_ATL_STATIC_REGISTRY + +#ifndef _ATL_NO_COMMODULE + +#pragma warning( push ) +#pragma warning( disable: 4996 ) // Disable "deprecated symbol" warning + +inline HRESULT WINAPI CComModule::UpdateRegistryClass( + _In_ const CLSID& clsid, + _In_opt_z_ LPCTSTR lpszProgID, + _In_opt_z_ LPCTSTR lpszVerIndProgID, + _In_ UINT nDescID, + _In_ DWORD dwFlags, + _In_ BOOL bRegister) +{ + if (bRegister) + { + TCHAR szDesc[256]; + // LoadString(m_hInst, nDescID, szDesc, 256); + return S_OK; // RegisterClassHelper(clsid, lpszProgID, lpszVerIndProgID, szDesc, dwFlags); + } + return UnregisterClassHelper(clsid, lpszProgID, lpszVerIndProgID); +} + +inline HRESULT WINAPI CComModule::UpdateRegistryClass( + _In_ const CLSID& clsid, + _In_opt_z_ LPCTSTR lpszProgID, + _In_opt_z_ LPCTSTR lpszVerIndProgID, + _In_z_ LPCTSTR szDesc, + _In_ DWORD dwFlags, + _In_ BOOL bRegister) +{ + if (bRegister) + return RegisterClassHelper(clsid, lpszProgID, lpszVerIndProgID, szDesc, dwFlags); + return UnregisterClassHelper(clsid, lpszProgID, lpszVerIndProgID); +} + +inline HRESULT WINAPI CComModule::RegisterClassHelper( + _In_ const CLSID& clsid, + _In_opt_z_ LPCTSTR lpszProgID, + _In_opt_z_ LPCTSTR lpszVerIndProgID, + _In_z_ LPCTSTR szDesc, + _In_ DWORD dwFlags) +{ + return S_OK; +} + +inline HRESULT WINAPI CComModule::UnregisterClassHelper( + _In_ const CLSID& clsid, + _In_opt_z_ LPCTSTR lpszProgID, + _In_opt_z_ LPCTSTR lpszVerIndProgID) +{ + USES_CONVERSION_EX; + CRegKey key; + LONG lRet; + + key.Attach(HKEY_CLASSES_ROOT); + if (lpszProgID != NULL && lpszProgID[0]!=_T('\0')) + { + lRet = key.RecurseDeleteKey(lpszProgID); + if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND && lRet != ERROR_PATH_NOT_FOUND) + { + key.Detach(); + return AtlHresultFromWin32(lRet); + } + } + if (lpszVerIndProgID != NULL && lpszVerIndProgID[0]!=_T('\0')) + { + lRet = key.RecurseDeleteKey(lpszVerIndProgID); + if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND && lRet != ERROR_PATH_NOT_FOUND) + { + key.Detach(); + return AtlHresultFromWin32(lRet); + } + } + LPOLESTR lpOleStr; + HRESULT hr = StringFromCLSID(clsid, &lpOleStr); + if (SUCCEEDED(hr)) + { + LPTSTR lpsz = OLE2T_EX(lpOleStr, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if(lpsz == NULL) + { + CoTaskMemFree(lpOleStr); + return E_OUTOFMEMORY; + } +#endif + + lRet = key.Open(key, _T("CLSID"), KEY_READ | KEY_WRITE); + if (lRet == ERROR_SUCCESS) + lRet = key.RecurseDeleteKey(lpsz); + if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND && lRet != ERROR_PATH_NOT_FOUND) + { + hr = AtlHresultFromWin32(lRet); + } + CoTaskMemFree(lpOleStr); + } + else + { + } + key.Detach(); + return hr; +} + +#pragma warning( pop ) // Disable "deprecated symbol" warning + +#endif // !_ATL_NO_COMMODULE + +#ifdef _ATL_DEBUG_INTERFACES + +inline void _QIThunk::Dump() throw() +{ + TCHAR buf[512+1]; + if (m_dwRef != 0) + { + _stprintf_s(buf, _countof(buf), _T("ATL: QIThunk - %-10d\tLEAK :\tObject = 0x%p\tRefcount = %d\tMaxRefCount = %d\t"), + m_nIndex, m_pUnk, m_dwRef, m_dwMaxRef); + buf[_countof(buf)-1] = 0; + OutputDebugString(buf); + AtlDumpIID(m_iid, m_lpszClassName, S_OK); + } + else + { + _stprintf_s(buf, _countof(buf), _T("ATL: QIThunk - %-10d\tNonAddRef LEAK :\tObject = 0x%p\t"), m_nIndex, m_pUnk); + buf[_countof(buf)-1] = 0; + OutputDebugString(buf); + AtlDumpIID(m_iid, m_lpszClassName, S_OK); + } +} + +#endif // _ATL_DEBUG_INTERFACES + +#if defined(_ATL_DEBUG_INTERFACES) || defined(_ATL_DEBUG_QI) +__forceinline HRESULT WINAPI AtlDumpIID( + _In_ REFIID iid, + _In_z_ LPCTSTR pszClassName, + _In_ HRESULT hr) throw() +{ + USES_CONVERSION_EX; + CRegKey key; + TCHAR szName[100]; + DWORD dwType; + DWORD dw = sizeof(szName); + + LPOLESTR pszGUID = NULL; + if (FAILED(StringFromCLSID(iid, &pszGUID))) + return hr; + + OutputDebugString(pszClassName); + OutputDebugString(_T(" - ")); + + LPTSTR lpszGUID = OLE2T_EX(pszGUID, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if(lpszGUID == NULL) + { + CoTaskMemFree(pszGUID); + return hr; + } +#endif + // Attempt to find it in the interfaces section + BOOL fClsNameFound = FALSE; + if (key.Open(HKEY_CLASSES_ROOT, _T("Interface"), KEY_READ) == ERROR_SUCCESS) + { + if (key.Open(key, lpszGUID, KEY_READ) == ERROR_SUCCESS) + { + *szName = 0; + if (RegQueryValueEx(key.m_hKey, (LPTSTR)NULL, NULL, &dwType, (LPBYTE)szName, &dw) == ERROR_SUCCESS) + { + OutputDebugString(szName); + fClsNameFound = TRUE; + } + } + } + // Attempt to find it in the clsid section + if ( !fClsNameFound && key.Open(HKEY_CLASSES_ROOT, _T("CLSID"), KEY_READ) == ERROR_SUCCESS) + { + if (key.Open(key, lpszGUID, KEY_READ) == ERROR_SUCCESS) + { + *szName = 0; + if (RegQueryValueEx(key.m_hKey, (LPTSTR)NULL, NULL, &dwType, (LPBYTE)szName, &dw) == ERROR_SUCCESS) + { + OutputDebugString(_T("(CLSID\?\?\?) ")); + OutputDebugString(szName); + fClsNameFound = TRUE; + } + } + } + /*Dump out the GUID only if no class name found*/ + if( !fClsNameFound ) + OutputDebugString(lpszGUID); + + if (hr != S_OK) + OutputDebugString(_T(" - failed")); + OutputDebugString(_T("\n")); + CoTaskMemFree(pszGUID); + + return hr; +} +#endif // _ATL_DEBUG_INTERFACES || _ATL_DEBUG_QI + + +// WM_FORWARDMSG - used to forward a message to another window for processing +// WPARAM - DWORD dwUserData - defined by user +// LPARAM - LPMSG pMsg - a pointer to the MSG structure +// return value - 0 if the message was not processed, nonzero if it was +#define WM_FORWARDMSG 0x037F + +}; //namespace ATL + +#ifndef _ATL_NO_AUTOMATIC_NAMESPACE +using namespace ATL; +#endif //!_ATL_NO_AUTOMATIC_NAMESPACE + +#ifdef _ATL_ATTRIBUTES +#include +#endif + +namespace ATL +{ + +// All exports go here +// Pull in if building ATL DLL or not linking to ATL DLL +#ifndef _ATL_DLL + +///////////////////////////////////////////////////////////////////////////// +// statics + +static inline LPTSTR AtlFindExtension(_In_z_ LPCTSTR psz) +{ + if (psz == NULL) + return NULL; + LPCTSTR pszRemember = NULL; + while (*psz != _T('\0')) + { + switch(*psz) + { + case _T('\\'): + pszRemember = NULL; + break; + case _T('.'): + pszRemember = psz; + break; + default: + break; + } + psz = CharNext(psz); + } + return (LPTSTR)((pszRemember == NULL) ? psz : pszRemember); +} + +///////////////////////////////////////////////////////////////////////////// +// Per User Registration + +ATLINLINE ATLAPI AtlSetPerUserRegistration(_In_ bool bEnable) +{ + _AtlRegisterPerUser = bEnable; + return S_OK; +} + +ATLINLINE ATLAPI AtlGetPerUserRegistration(_Out_ bool* pbEnabled) +{ + if (pbEnabled == NULL) + return E_POINTER; + + *pbEnabled = _AtlRegisterPerUser; + return S_OK; +} + +///////////////////////////////////////////////////////////////////////////// +// TypeLib registration + +#define _ATL_MAX_PATH_PLUS_INDEX (_MAX_PATH + _ATL_TYPELIB_INDEX_LENGTH) + +ATLPREFAST_SUPPRESS(6387) +ATLINLINE ATLAPI AtlLoadTypeLib( + _In_ HINSTANCE hInstTypeLib, + _In_opt_z_ LPCOLESTR lpszIndex, + _Deref_out_z_ BSTR* pbstrPath, + _Deref_out_ ITypeLib** ppTypeLib) +{ + ATLASSERT(pbstrPath != NULL && ppTypeLib != NULL); + if (pbstrPath == NULL || ppTypeLib == NULL) + return E_POINTER; + + *pbstrPath = NULL; + *ppTypeLib = NULL; + + USES_CONVERSION_EX; + ATLASSERT(hInstTypeLib != NULL); + TCHAR szModule[_ATL_MAX_PATH_PLUS_INDEX]; + + DWORD dwFLen = GetModuleFileName(hInstTypeLib, szModule, MAX_PATH); + if( dwFLen == 0 ) + return AtlHresultFromLastError(); + else if( dwFLen == MAX_PATH ) + return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); + + // get the extension pointer in case of fail + LPTSTR lpszExt = NULL; + + lpszExt = AtlFindExtension(szModule); + + if (lpszIndex != NULL) + { + LPCTSTR lpcszIndex = OLE2CT_EX(lpszIndex, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); + if(lpcszIndex == NULL) + { + return E_OUTOFMEMORY; + } + DWORD nIndexLen = lstrlen(lpcszIndex); + + DWORD newLen = dwFLen + nIndexLen; + if ((newLen < dwFLen) || (newLen < nIndexLen) || (newLen >= _ATL_MAX_PATH_PLUS_INDEX)) + return E_FAIL; +#ifdef UNICODE + Checked::wcscpy_s(szModule + dwFLen, _countof(szModule) - dwFLen, lpcszIndex); +#else + Checked::strcpy_s(szModule + dwFLen, _countof(szModule) - dwFLen, lpcszIndex); +#endif + } + LPOLESTR lpszModule = T2OLE_EX(szModule, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if(lpszModule == NULL) + return E_OUTOFMEMORY; +#endif + HRESULT hr = LoadTypeLib(lpszModule, ppTypeLib); + if (FAILED(hr)) + { + // typelib not in module, try .tlb instead + TCHAR szExt[] = _T(".tlb"); + if ((lpszExt - szModule + sizeof(szExt)/sizeof(TCHAR)) > _MAX_PATH) + return E_FAIL; + +#ifdef UNICODE + Checked::wcscpy_s(lpszExt, _countof(szModule) - (lpszExt - szModule), szExt); +#else + Checked::strcpy_s(lpszExt, _countof(szModule) - (lpszExt - szModule), szExt); +#endif + lpszModule = T2OLE_EX(szModule, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if(lpszModule == NULL) + return E_OUTOFMEMORY; +#endif + hr = LoadTypeLib(lpszModule, ppTypeLib); + } + if (SUCCEEDED(hr)) + { + *pbstrPath = ::SysAllocString(lpszModule); + if (*pbstrPath == NULL) + hr = E_OUTOFMEMORY; + } + return hr; +} +ATLPREFAST_UNSUPPRESS() + +ATLINLINE ATLAPI AtlRegisterClassCategoriesHelper( + _In_ REFCLSID clsid, + _In_opt_ const struct _ATL_CATMAP_ENTRY* pCatMap, + _In_ BOOL bRegister) +{ + CComPtr< ICatRegister > pCatRegister; + HRESULT hResult; + const struct _ATL_CATMAP_ENTRY* pEntry; + CATID catid; + + if( pCatMap == NULL ) + { + return( S_OK ); + } + + if (InlineIsEqualGUID(clsid, GUID_NULL)) + { + ATLASSERT(0 && _T("Use OBJECT_ENTRY_NON_CREATEABLE_EX macro if you want to register class categories for non creatable objects.")); + return S_OK; + } + + hResult = CoCreateInstance( CLSID_StdComponentCategoriesMgr, NULL, + CLSCTX_INPROC_SERVER, __uuidof(ICatRegister), (void**)&pCatRegister ); + if( FAILED( hResult ) ) + { + // Since not all systems have the category manager installed, we'll allow + // the registration to succeed even though we didn't register our + // categories. If you really want to register categories on a system + // without the category manager, you can either manually add the + // appropriate entries to your registry script (.rgs), or you can + // redistribute comcat.dll. + return( S_OK ); + } + + hResult = S_OK; + pEntry = pCatMap; + while( pEntry->iType != _ATL_CATMAP_ENTRY_END ) + { + catid = *pEntry->pcatid; + if( bRegister ) + { + if( pEntry->iType == _ATL_CATMAP_ENTRY_IMPLEMENTED ) + { + hResult = pCatRegister->RegisterClassImplCategories( clsid, 1, + &catid ); + } + else + { + ATLASSERT( pEntry->iType == _ATL_CATMAP_ENTRY_REQUIRED ); + hResult = pCatRegister->RegisterClassReqCategories( clsid, 1, + &catid ); + } + if( FAILED( hResult ) ) + { + return( hResult ); + } + } + else + { + if( pEntry->iType == _ATL_CATMAP_ENTRY_IMPLEMENTED ) + { + pCatRegister->UnRegisterClassImplCategories( clsid, 1, &catid ); + } + else + { + ATLASSERT( pEntry->iType == _ATL_CATMAP_ENTRY_REQUIRED ); + pCatRegister->UnRegisterClassReqCategories( clsid, 1, &catid ); + } + } + pEntry++; + } + + // When unregistering remove "Implemented Categories" and "Required Categories" subkeys if they are empty. + if (!bRegister) + { + OLECHAR szGUID[64]; + ::StringFromGUID2(clsid, szGUID, 64); + USES_CONVERSION_EX; + TCHAR* pszGUID = OLE2T_EX(szGUID, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); + if (pszGUID != NULL) + { + TCHAR szKey[128]; +#ifdef UNICODE + Checked::wcscpy_s(szKey, _countof(szKey), _T("CLSID\\")); + Checked::wcscat_s(szKey, _countof(szKey), pszGUID); + Checked::wcscat_s(szKey, _countof(szKey), _T("\\Required Categories")); +#else + Checked::strcpy_s(szKey, _countof(szKey), _T("CLSID\\")); + Checked::strcat_s(szKey, _countof(szKey), pszGUID); + Checked::strcat_s(szKey, _countof(szKey), _T("\\Required Categories")); +#endif + + CRegKey root(HKEY_CLASSES_ROOT); + CRegKey key; + DWORD cbSubKeys = 0; + + LRESULT lRes = key.Open(root, szKey, KEY_READ); + if (lRes == ERROR_SUCCESS) + { + lRes = RegQueryInfoKey(key, NULL, NULL, NULL, &cbSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + key.Close(); + if (lRes == ERROR_SUCCESS && cbSubKeys == 0) + { + root.DeleteSubKey(szKey); + } + } + +#ifdef UNICODE + Checked::wcscpy_s(szKey, _countof(szKey), _T("CLSID\\")); + Checked::wcscat_s(szKey, _countof(szKey), pszGUID); + Checked::wcscat_s(szKey, _countof(szKey), _T("\\Implemented Categories")); +#else + Checked::strcpy_s(szKey, _countof(szKey), _T("CLSID\\")); + Checked::strcat_s(szKey, _countof(szKey), pszGUID); + Checked::strcat_s(szKey, _countof(szKey), _T("\\Implemented Categories")); +#endif + lRes = key.Open(root, szKey, KEY_READ); + if (lRes == ERROR_SUCCESS) + { + lRes = RegQueryInfoKey(key, NULL, NULL, NULL, &cbSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + key.Close(); + if (lRes == ERROR_SUCCESS && cbSubKeys == 0) + { + root.DeleteSubKey(szKey); + } + } + } + } + return( S_OK ); +} + +#endif // _ATL_DLL + +ATLINLINE ATLAPIINL AtlWinModuleTerm( + _Inout_ _ATL_WIN_MODULE* pWinModule, + _In_ HINSTANCE hInst) +{ + if (pWinModule == NULL) + return E_INVALIDARG; + if (pWinModule->cbSize == 0) + return S_OK; + if (pWinModule->cbSize != sizeof(_ATL_WIN_MODULE)) + return E_INVALIDARG; + + for (int i = 0; i < pWinModule->m_rgWindowClassAtoms.GetSize(); i++) + UnregisterClass((LPCTSTR)pWinModule->m_rgWindowClassAtoms[i], hInst); + pWinModule->m_rgWindowClassAtoms.RemoveAll(); + pWinModule->m_csWindowCreate.Term(); + pWinModule->cbSize = 0; + return S_OK; +} + +static inline UINT WINAPI AtlGetDirLen(_In_z_ LPCOLESTR lpszPathName) throw() +{ + ATLASSERT(lpszPathName != NULL); + if(lpszPathName == NULL) + return 0; + + // always capture the complete file name including extension (if present) + LPCOLESTR lpszTemp = lpszPathName; + for (LPCOLESTR lpsz = lpszPathName; *lpsz != '\0'; ) + { + + LPCOLESTR lp = CharNextW(lpsz); + + // remember last directory/drive separator + if (*lpsz == OLESTR('\\') || *lpsz == OLESTR('/') || *lpsz == OLESTR(':')) + lpszTemp = lp; + lpsz = lp; + } + + return UINT( lpszTemp-lpszPathName ); +} + +ATLINLINE ATLAPIINL AtlUnRegisterTypeLib( + _In_ HINSTANCE hInstTypeLib, + _In_opt_z_ LPCOLESTR lpszIndex) +{ + CComBSTR bstrPath; + CComPtr pTypeLib; + HRESULT hr = AtlLoadTypeLib(hInstTypeLib, lpszIndex, &bstrPath, &pTypeLib); + if (SUCCEEDED(hr)) + { + TLIBATTR* ptla; + hr = pTypeLib->GetLibAttr(&ptla); + if (SUCCEEDED(hr)) + { + typedef HRESULT (STDAPICALLTYPE *PFNUNREGISTERTYPELIB)(REFGUID, WORD /* wVerMajor */, WORD /* wVerMinor */, LCID, SYSKIND); + PFNUNREGISTERTYPELIB pfnUnRegisterTypeLib = NULL; + + bool bRedirectionEnabled = false; + hr = AtlGetPerUserRegistration(&bRedirectionEnabled); + if( FAILED(hr) ) + { + return hr; + } + + if( true == bRedirectionEnabled ) + { + // HMODULE hmodOleAut=::GetModuleHandleW(L"OLEAUT32.DLL"); + // if(hmodOleAut) + { + // pfnUnRegisterTypeLib=reinterpret_cast(::GetProcAddress(hmodOleAut, "UnRegisterTypeLibForUser")); + } + } + + if( NULL == pfnUnRegisterTypeLib ) + { + pfnUnRegisterTypeLib = (PFNUNREGISTERTYPELIB)&UnRegisterTypeLib; + } + + hr = pfnUnRegisterTypeLib(ptla->guid, ptla->wMajorVerNum, ptla->wMinorVerNum, ptla->lcid, ptla->syskind); + + pTypeLib->ReleaseTLibAttr(ptla); + } + } + return hr; +} + +ATLINLINE ATLAPIINL AtlRegisterTypeLib( + _In_ HINSTANCE hInstTypeLib, + _In_opt_z_ LPCOLESTR lpszIndex) +{ + CComBSTR bstrPath; + CComPtr pTypeLib; + HRESULT hr = AtlLoadTypeLib(hInstTypeLib, lpszIndex, &bstrPath, &pTypeLib); + if (SUCCEEDED(hr)) + { + LPCOLESTR szDir=NULL; + OLECHAR szDirBuffer[MAX_PATH]; + CComBSTR bstrHelpFile; + hr = pTypeLib->GetDocumentation(-1, NULL, NULL, NULL, &bstrHelpFile); + if (SUCCEEDED(hr) && bstrHelpFile != NULL) + { + Checked::wcsncpy_s(szDirBuffer, MAX_PATH, bstrHelpFile.m_str, bstrHelpFile.Length()); + szDirBuffer[MAX_PATH - 1] = 0; + + // truncate at the directory level + szDirBuffer[AtlGetDirLen(szDirBuffer)] = 0; + + szDir=&szDirBuffer[0]; + } + + typedef HRESULT (STDAPICALLTYPE *PFNREGISTERTYPELIB)(ITypeLib *, LPCOLESTR /* const szFullPath */, LPCOLESTR /* const szHelpDir */); + PFNREGISTERTYPELIB pfnRegisterTypeLib = NULL; + + bool bRedirectionEnabled = false; + hr = AtlGetPerUserRegistration(&bRedirectionEnabled); + if( FAILED(hr) ) + { + return hr; + } + + if( true == bRedirectionEnabled ) + { + // HMODULE hmodOleAut=::GetModuleHandleW(L"OLEAUT32.DLL"); + // if(hmodOleAut) + { + // pfnRegisterTypeLib=reinterpret_cast(::GetProcAddress(hmodOleAut, "RegisterTypeLibForUser")); + } + } + + if( NULL == pfnRegisterTypeLib ) + { + pfnRegisterTypeLib = (PFNREGISTERTYPELIB)&RegisterTypeLib; + } + + hr = pfnRegisterTypeLib(pTypeLib, bstrPath, szDir); + + } + return hr; +} + +///////////////////////////////////////////////////////////////////////////// +// Registration + +// AtlComModuleRegisterServer walks the ATL Autogenerated Object Map and registers each object in the map +// If pCLSID is not NULL then only the object referred to by pCLSID is registered (The default case) +// otherwise all the objects are registered +ATLINLINE ATLAPIINL AtlComModuleRegisterServer( + _Inout_ _ATL_COM_MODULE* pComModule, + _In_ BOOL bRegTypeLib, + _In_opt_ const CLSID* pCLSID) +{ + ATLASSERT(pComModule != NULL); + if (pComModule == NULL) + return E_INVALIDARG; + ATLASSERT(pComModule->m_hInstTypeLib != NULL); + + HRESULT hr = S_OK; + + for (_ATL_OBJMAP_ENTRY** ppEntry = pComModule->m_ppAutoObjMapFirst; ppEntry < pComModule->m_ppAutoObjMapLast; ppEntry++) + { + if (*ppEntry != NULL) + { + _ATL_OBJMAP_ENTRY* pEntry = *ppEntry; + if (pCLSID != NULL) + { + if (!IsEqualGUID(*pCLSID, *pEntry->pclsid)) + continue; + } + hr = pEntry->pfnUpdateRegistry(TRUE); + if (FAILED(hr)) + break; + hr = AtlRegisterClassCategoriesHelper( *pEntry->pclsid, + pEntry->pfnGetCategoryMap(), TRUE ); + if (FAILED(hr)) + break; + } + } + + if (SUCCEEDED(hr) && bRegTypeLib) + { + ATLASSUME(pComModule->m_hInstTypeLib != NULL); + hr = AtlRegisterTypeLib(pComModule->m_hInstTypeLib, 0); + } + + return hr; +} + +// AtlComUnregisterServer walks the ATL Object Map and unregisters each object in the map +// If pCLSID is not NULL then only the object referred to by pCLSID is unregistered (The default case) +// otherwise all the objects are unregistered. +ATLINLINE ATLAPIINL AtlComModuleUnregisterServer( + _Inout_ _ATL_COM_MODULE* pComModule, + _In_ BOOL bUnRegTypeLib, + _In_opt_ const CLSID* pCLSID) +{ + ATLASSERT(pComModule != NULL); + if (pComModule == NULL) + return E_INVALIDARG; + + HRESULT hr = S_OK; + + for (_ATL_OBJMAP_ENTRY** ppEntry = pComModule->m_ppAutoObjMapFirst; ppEntry < pComModule->m_ppAutoObjMapLast; ppEntry++) + { + if (*ppEntry != NULL) + { + _ATL_OBJMAP_ENTRY* pEntry = *ppEntry; + if (pCLSID != NULL) + { + if (!IsEqualGUID(*pCLSID, *pEntry->pclsid)) + continue; + } + hr = AtlRegisterClassCategoriesHelper( *pEntry->pclsid, pEntry->pfnGetCategoryMap(), FALSE ); + if (FAILED(hr)) + break; + hr = pEntry->pfnUpdateRegistry(FALSE); //unregister + if (FAILED(hr)) + break; + } + } + if (SUCCEEDED(hr) && bUnRegTypeLib) + hr = AtlUnRegisterTypeLib(pComModule->m_hInstTypeLib, 0); + + return hr; +} + + +///////////////////////////////////////////////////////////////////////////// +// General DLL Version Helpers + +#pragma warning(push) +#pragma warning(disable : 4191) // 'type cast' : unsafe conversion from 'FARPROC' to 'DLLGETVERSIONPROC' + +inline HRESULT AtlGetDllVersion( + _In_ HINSTANCE hInstDLL, + _Out_ DLLVERSIONINFO* pDllVersionInfo) +{ + ATLENSURE(pDllVersionInfo != NULL); + + // We must get this function explicitly because some DLLs don't implement it. + DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(hInstDLL, "DllGetVersion"); + + if(pfnDllGetVersion == NULL) + { + return E_NOTIMPL; + } + + return (*pfnDllGetVersion)(pDllVersionInfo); +} + +#pragma warning(pop) + +inline HRESULT AtlGetDllVersion( + _In_z_ LPCTSTR lpstrDllName, + _Out_ DLLVERSIONINFO* pDllVersionInfo) +{ + HINSTANCE hInstDLL = ::LoadLibrary(lpstrDllName); + if(hInstDLL == NULL) + { + return AtlHresultFromLastError(); + } + HRESULT hRet = AtlGetDllVersion(hInstDLL, pDllVersionInfo); + ::FreeLibrary(hInstDLL); + return hRet; +} + +// Common Control Versions: +// WinNT 4.0 maj=4 min=00 +// IE 3.x maj=4 min=70 +// IE 4.0 maj=4 min=71 +// IE 5.0 maj=5 min=80 +// Win2000 maj=5 min=81 +inline HRESULT AtlGetCommCtrlVersion( + _Out_ LPDWORD pdwMajor, + _Out_ LPDWORD pdwMinor) +{ + ATLENSURE(( pdwMajor != NULL ) && ( pdwMinor != NULL )); + + DLLVERSIONINFO dvi; + memset(&dvi, 0, sizeof(dvi)); + dvi.cbSize = sizeof(dvi); + + HRESULT hRet = AtlGetDllVersion(_T("comctl32.dll"), &dvi); + + if(SUCCEEDED(hRet)) + { + *pdwMajor = dvi.dwMajorVersion; + *pdwMinor = dvi.dwMinorVersion; + } + + return hRet; +} + +// Shell Versions: +// WinNT 4.0 maj=4 min=00 +// IE 3.x, IE 4.0 without Web Integrated Desktop maj=4 min=00 +// IE 4.0 with Web Integrated Desktop maj=4 min=71 +// IE 4.01 with Web Integrated Desktop maj=4 min=72 +// Win2000 maj=5 min=00 +inline HRESULT AtlGetShellVersion( + _Out_ LPDWORD pdwMajor, + _Out_ LPDWORD pdwMinor) +{ + ATLENSURE(( pdwMajor != NULL) && ( pdwMinor != NULL )); + + DLLVERSIONINFO dvi; + memset(&dvi, 0, sizeof(dvi)); + dvi.cbSize = sizeof(dvi); + HRESULT hRet = AtlGetDllVersion(_T("shell32.dll"), &dvi); + + if(SUCCEEDED(hRet)) + { + *pdwMajor = dvi.dwMajorVersion; + *pdwMinor = dvi.dwMinorVersion; + } + + return hRet; +} + +inline ATL_DEPRECATED("AtlModuleRegisterClassObjects has been replaced by AtlComModuleRegisterClassObjects") +HRESULT AtlModuleRegisterClassObjects( + _In_opt_ _ATL_MODULE* /*pM*/, + _In_ DWORD dwClsContext, + _In_ DWORD dwFlags) +{ + return AtlComModuleRegisterClassObjects(&_AtlComModule, dwClsContext, dwFlags); +} + +inline ATL_DEPRECATED("AtlModuleRevokeClassObjects has been replaced by AtlComModuleRevokeClassObjects") +HRESULT AtlModuleRevokeClassObjects(_In_opt_ _ATL_MODULE* /*pM*/) +{ + return AtlComModuleRevokeClassObjects(&_AtlComModule); +} + +inline ATL_DEPRECATED("AtlModuleGetClassObject has been replaced by AtlComModuleGetClassObject") +HRESULT AtlModuleGetClassObject( + _In_opt_ _ATL_MODULE* /*pM*/, + _In_ REFCLSID rclsid, + _In_ REFIID riid, + _Deref_out_ LPVOID* ppv) +{ + return AtlComModuleGetClassObject(&_AtlComModule, rclsid, riid, ppv); +} + +inline ATL_DEPRECATED("AtlModuleRegisterServer has been replaced by AtlComModuleRegisterServer") +HRESULT AtlModuleRegisterServer( + _In_opt_ _ATL_MODULE* /*pM*/, + _In_ BOOL bRegTypeLib, + _In_opt_ const CLSID* pCLSID = NULL) +{ + return AtlComModuleRegisterServer(&_AtlComModule, bRegTypeLib, pCLSID); +} + +inline ATL_DEPRECATED("AtlModuleUnregisterServer has been replaced by AtlComModuleUnregisterServer") +HRESULT AtlModuleUnregisterServer( + _In_opt_ _ATL_MODULE* /*pM*/, + _In_opt_ const CLSID* pCLSID = NULL) +{ + return AtlComModuleUnregisterServer(&_AtlComModule, FALSE, pCLSID); +} + +inline ATL_DEPRECATED("AtlModuleUnregisterServerEx has been replaced by AtlComModuleUnregisterServer") +HRESULT AtlModuleUnregisterServerEx( + _In_opt_ _ATL_MODULE* /*pM*/, + _In_ BOOL bUnRegTypeLib, + _In_opt_ const CLSID* pCLSID = NULL) +{ + return AtlComModuleUnregisterServer(&_AtlComModule, bUnRegTypeLib, pCLSID); +} + +inline ATL_DEPRECATED("AtlModuleRegisterTypeLib has been replaced by AtlRegisterTypeLib") +HRESULT AtlModuleRegisterTypeLib( + _In_opt_ _ATL_MODULE* /*pM*/, + _In_z_ LPCOLESTR lpszIndex) +{ + return AtlRegisterTypeLib(_AtlComModule.m_hInstTypeLib, lpszIndex); +} + +inline ATL_DEPRECATED("AtlModuleUnRegisterTypeLib has been replaced by AtlUnRegisterTypeLib") +HRESULT AtlModuleUnRegisterTypeLib( + _In_opt_ _ATL_MODULE* /*pM*/, + _In_z_ LPCOLESTR lpszIndex) +{ + return AtlUnRegisterTypeLib(_AtlComModule.m_hInstTypeLib, lpszIndex); +} + +inline ATL_DEPRECATED("AtlModuleLoadTypeLib has been replaced by AtlLoadTypeLib") +HRESULT AtlModuleLoadTypeLib( + _In_opt_ _ATL_MODULE* /*pM*/, + _In_z_ LPCOLESTR lpszIndex, + _Deref_out_z_ BSTR* pbstrPath, + _Deref_out_ ITypeLib** ppTypeLib) +{ + return AtlLoadTypeLib(_AtlComModule.m_hInstTypeLib, lpszIndex, pbstrPath, ppTypeLib); +} + +inline ATL_DEPRECATED("AtlModuleInit is no longer required") +HRESULT AtlModuleInit( + _In_opt_ _ATL_MODULE* /*pM*/, + _In_opt_ _ATL_OBJMAP_ENTRY* /*p*/, + _In_ HINSTANCE /*h*/) +{ + return S_OK; +} + +inline ATL_DEPRECATED("AtlModuleTerm is no longer required") +HRESULT AtlModuleTerm(_In_opt_ _ATL_MODULE* /*pM*/) +{ + return S_OK; +} + +inline ATL_DEPRECATED("AtlModuleAddCreateWndData has been replaced by AtlWinModuleAddCreateWndData") +void AtlModuleAddCreateWndData( + _In_opt_ _ATL_MODULE* /*pM*/, + _In_ _AtlCreateWndData* pData, + _In_ void* pObject) +{ + AtlWinModuleAddCreateWndData(&_AtlWinModule, pData, pObject); +} + +inline ATL_DEPRECATED("AtlModuleExtractCreateWndData has been replaced by AtlWinModuleExtractCreateWndData") +void* AtlModuleExtractCreateWndData(_In_opt_ _ATL_MODULE* /*pM*/) +{ + return AtlWinModuleExtractCreateWndData(&_AtlWinModule); +} + +#ifndef _ATL_NO_COMMODULE + +inline CRITICAL_SECTION& CComModule::get_m_csWindowCreate() throw() +{ + return _AtlWinModule.m_csWindowCreate.m_sec; +} + +inline CRITICAL_SECTION& CComModule::get_m_csObjMap() throw() +{ + return _AtlComModule.m_csObjMap.m_sec; +} + +inline CRITICAL_SECTION& CComModule::get_m_csStaticDataInit() throw() +{ + return m_csStaticDataInitAndTypeInfo.m_sec; +} + +inline _AtlCreateWndData*& CComModule::get_m_pCreateWndList() throw() +{ + return _AtlWinModule.m_pCreateWndList; +} +inline void CComModule::put_m_pCreateWndList(_In_ _AtlCreateWndData* p) throw() +{ + _AtlWinModule.m_pCreateWndList = p; +} +#ifdef _ATL_DEBUG_INTERFACES +inline UINT& CComModule::get_m_nIndexQI() throw() +{ + return _AtlDebugInterfacesModule.m_nIndexQI; +} +inline void CComModule::put_m_nIndexQI(_In_ UINT nIndex) throw() +{ + _AtlDebugInterfacesModule.m_nIndexQI = nIndex; +} +inline UINT& CComModule::get_m_nIndexBreakAt() throw() +{ + return _AtlDebugInterfacesModule.m_nIndexBreakAt; +} +inline void CComModule::put_m_nIndexBreakAt(_In_ UINT nIndex) throw() +{ + _AtlDebugInterfacesModule.m_nIndexBreakAt = nIndex; +} +inline CSimpleArray<_QIThunk*>* CComModule::get_m_paThunks() throw() +{ + return &_AtlDebugInterfacesModule.m_aThunks; +} +inline HRESULT CComModule::AddThunk( + _Inout_ _Deref_pre_valid_ _Deref_post_valid_ IUnknown** pp, + _In_z_ LPCTSTR lpsz, + _In_ REFIID iid) throw() +{ + return _AtlDebugInterfacesModule.AddThunk(pp, lpsz, iid); +} +inline HRESULT CComModule::AddNonAddRefThunk( + _Inout_ IUnknown* p, + _In_z_ LPCTSTR lpsz, + _Deref_out_ IUnknown** ppThunkRet) throw() +{ + return _AtlDebugInterfacesModule.AddNonAddRefThunk(p, lpsz, ppThunkRet); +} + +inline void CComModule::DeleteNonAddRefThunk(_In_ IUnknown* pUnk) throw() +{ + _AtlDebugInterfacesModule.DeleteNonAddRefThunk(pUnk); +} + +inline void CComModule::DeleteThunk(_In_ _QIThunk* p) throw() +{ + _AtlDebugInterfacesModule.DeleteThunk(p); +} + +inline bool CComModule::DumpLeakedThunks() throw() +{ + return _AtlDebugInterfacesModule.DumpLeakedThunks(); +} +#endif // _ATL_DEBUG_INTERFACES + +inline HRESULT CComModule::Init( + _In_ _ATL_OBJMAP_ENTRY* p, + _In_ HINSTANCE /*h*/, + _In_opt_ const GUID* plibid) throw() +{ + if (plibid != NULL) + m_libid = *plibid; + + _ATL_OBJMAP_ENTRY* pEntry; + if (p != (_ATL_OBJMAP_ENTRY*)-1) + { + m_pObjMap = p; + if (m_pObjMap != NULL) + { + pEntry = m_pObjMap; + while (pEntry->pclsid != NULL) + { + pEntry->pfnObjectMain(true); //initialize class resources + pEntry++; + } + } + } + for (_ATL_OBJMAP_ENTRY** ppEntry = _AtlComModule.m_ppAutoObjMapFirst; ppEntry < _AtlComModule.m_ppAutoObjMapLast; ppEntry++) + { + if (*ppEntry != NULL) + (*ppEntry)->pfnObjectMain(true); //initialize class resources + } + return S_OK; +} + +inline void CComModule::Term() throw() +{ + _ATL_OBJMAP_ENTRY* pEntry; + if (m_pObjMap != NULL) + { + pEntry = m_pObjMap; + while (pEntry->pclsid != NULL) + { + if (pEntry->pCF != NULL) + pEntry->pCF->Release(); + pEntry->pCF = NULL; + pEntry->pfnObjectMain(false); //cleanup class resources + pEntry++; + } + } + + for (_ATL_OBJMAP_ENTRY** ppEntry = _AtlComModule.m_ppAutoObjMapFirst; ppEntry < _AtlComModule.m_ppAutoObjMapLast; ppEntry++) + { + if (*ppEntry != NULL) + (*ppEntry)->pfnObjectMain(false); //cleanup class resources + } +#ifdef _DEBUG + // Prevent false memory leak reporting. ~CAtlWinModule may be too late. + _AtlWinModule.Term(); +#endif // _DEBUG + + CAtlModuleT::Term(); +} + +ATLPREFAST_SUPPRESS(6387) +inline HRESULT CComModule::GetClassObject( + _In_ REFCLSID rclsid, + _In_ REFIID riid, + _Deref_out_ LPVOID* ppv) throw() +{ + *ppv = NULL; + HRESULT hr = S_OK; + + if (m_pObjMap != NULL) + { + const _ATL_OBJMAP_ENTRY* pEntry = m_pObjMap; + + while (pEntry->pclsid != NULL) + { + if ((pEntry->pfnGetClassObject != NULL) && InlineIsEqualGUID(rclsid, *pEntry->pclsid)) + { + if (pEntry->pCF == NULL) + { + CComCritSecLock lock(_AtlComModule.m_csObjMap, false); + hr = lock.Lock(); + if (FAILED(hr)) + { + ATLASSERT(FALSE); + break; + } + + if (pEntry->pCF == NULL) + { + hr = pEntry->pfnGetClassObject(pEntry->pfnCreateInstance, __uuidof(IUnknown), (LPVOID*)&pEntry->pCF); + } + } + + if (pEntry->pCF != NULL) + { + hr = pEntry->pCF->QueryInterface(riid, ppv); + } + break; + } + pEntry++; + } + } + + if (*ppv == NULL && hr == S_OK) + { + hr = AtlComModuleGetClassObject(&_AtlComModule, rclsid, riid, ppv); + } + + return hr; +} +ATLPREFAST_UNSUPPRESS() + +// Register/Revoke All Class Factories with the OS (EXE only) +inline HRESULT CComModule::RegisterClassObjects( + _In_ DWORD dwClsContext, + _In_ DWORD dwFlags) throw() +{ + HRESULT hr = S_OK; + _ATL_OBJMAP_ENTRY* pEntry; + if (m_pObjMap != NULL) + { + pEntry = m_pObjMap; + while (pEntry->pclsid != NULL && hr == S_OK) + { + hr = pEntry->RegisterClassObject(dwClsContext, dwFlags); + pEntry++; + } + } + if (hr == S_OK) + hr = AtlComModuleRegisterClassObjects(&_AtlComModule, dwClsContext, dwFlags); + return hr; +} +inline HRESULT CComModule::RevokeClassObjects() throw() +{ + HRESULT hr = S_OK; + _ATL_OBJMAP_ENTRY* pEntry; + if (m_pObjMap != NULL) + { + pEntry = m_pObjMap; + while (pEntry->pclsid != NULL && hr == S_OK) + { + hr = pEntry->RevokeClassObject(); + pEntry++; + } + } + if (hr == S_OK) + hr = AtlComModuleRevokeClassObjects(&_AtlComModule); + return hr; +} + +// Registry support (helpers) +inline HRESULT CComModule::RegisterTypeLib() throw() +{ + return _AtlComModule.RegisterTypeLib(); +} +inline HRESULT CComModule::RegisterTypeLib(_In_z_ LPCTSTR lpszIndex) throw() +{ + return _AtlComModule.RegisterTypeLib(lpszIndex); +} +inline HRESULT CComModule::UnRegisterTypeLib() throw() +{ + return _AtlComModule.UnRegisterTypeLib(); +} +inline HRESULT CComModule::UnRegisterTypeLib(_In_z_ LPCTSTR lpszIndex) throw() +{ + return _AtlComModule.UnRegisterTypeLib(lpszIndex); +} + +inline HRESULT CComModule::RegisterServer( + _In_ BOOL bRegTypeLib /*= FALSE*/, + _In_opt_ const CLSID* pCLSID /*= NULL*/) throw() +{ + HRESULT hr = S_OK; + _ATL_OBJMAP_ENTRY* pEntry = m_pObjMap; + if (pEntry != NULL) + { + for (;pEntry->pclsid != NULL; pEntry++) + { + if (pCLSID != NULL) + { + if (!IsEqualGUID(*pCLSID, *pEntry->pclsid)) + continue; + } + hr = pEntry->pfnUpdateRegistry(TRUE); + if (FAILED(hr)) + break; + hr = AtlRegisterClassCategoriesHelper( *pEntry->pclsid, + pEntry->pfnGetCategoryMap(), TRUE ); + if (FAILED(hr)) + break; + } + } + if (SUCCEEDED(hr)) + hr = CAtlModuleT::RegisterServer(bRegTypeLib, pCLSID); + return hr; +} + +inline HRESULT CComModule::UnregisterServer( + _In_ BOOL bUnRegTypeLib, + _In_opt_ const CLSID* pCLSID /*= NULL*/) throw() +{ + HRESULT hr = S_OK; + _ATL_OBJMAP_ENTRY* pEntry = m_pObjMap; + if (pEntry != NULL) + { + for (;pEntry->pclsid != NULL; pEntry++) + { + if (pCLSID != NULL) + { + if (!IsEqualGUID(*pCLSID, *pEntry->pclsid)) + continue; + } + hr = AtlRegisterClassCategoriesHelper( *pEntry->pclsid, + pEntry->pfnGetCategoryMap(), FALSE ); + if (FAILED(hr)) + break; + hr = pEntry->pfnUpdateRegistry(FALSE); //unregister + if (FAILED(hr)) + break; + } + } + if (SUCCEEDED(hr)) + hr = CAtlModuleT::UnregisterServer(bUnRegTypeLib, pCLSID); + return hr; +} + +inline HRESULT CComModule::UnregisterServer(_In_opt_ const CLSID* pCLSID /*= NULL*/) throw() +{ + return UnregisterServer(FALSE, pCLSID); +} + +#endif // !_ATL_NO_COMMODULE + +} // namespace ATL + + +#pragma warning( pop ) + +#if !defined(_ATL_DLL) && !defined(_DEBUG) + +#include + +#endif // !_ATL_DLL && !_DEBUG + +#pragma pack(pop) +#ifdef _ATL_ALL_WARNINGS +#pragma warning( pop ) +#endif + +///////////////////////////////////////////////////////////////////////////// + +#endif // __ATLBASE_H__ diff --git a/src/main/headers/atlbase.inl b/src/main/headers/atlbase.inl new file mode 100644 index 0000000..f6a58b6 --- /dev/null +++ b/src/main/headers/atlbase.inl @@ -0,0 +1,475 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#ifndef __ATLBASE_INL__ +#define __ATLBASE_INL__ + +#pragma once + +#ifndef __ATLBASE_H__ + #error atlbase.inl requires atlbase.h to be included first +#endif +#pragma warning(push) +#pragma warning(disable:4571) //catch(...) blocks compiled with /EHs do NOT catch or re-throw Structured Exceptions +namespace ATL +{ + +///////////////////////////////////////////////////////////////////////////// +// Connection Point Helpers + +ATLINLINE ATLAPI AtlAdvise( + _Inout_ IUnknown* pUnkCP, + _Inout_opt_ IUnknown* pUnk, + _In_ const IID& iid, + _Out_ LPDWORD pdw) +{ + if(pUnkCP == NULL) + return E_INVALIDARG; + + CComPtr pCPC; + CComPtr pCP; + HRESULT hRes = pUnkCP->QueryInterface(__uuidof(IConnectionPointContainer), (void**)&pCPC); + if (SUCCEEDED(hRes)) + hRes = pCPC->FindConnectionPoint(iid, &pCP); + if (SUCCEEDED(hRes)) + hRes = pCP->Advise(pUnk, pdw); + return hRes; +} + +ATLINLINE ATLAPI AtlUnadvise( + _Inout_ IUnknown* pUnkCP, + _In_ const IID& iid, + _In_ DWORD dw) +{ + if(pUnkCP == NULL) + return E_INVALIDARG; + + CComPtr pCPC; + CComPtr pCP; + HRESULT hRes = pUnkCP->QueryInterface(__uuidof(IConnectionPointContainer), (void**)&pCPC); + if (SUCCEEDED(hRes)) + hRes = pCPC->FindConnectionPoint(iid, &pCP); + if (SUCCEEDED(hRes)) + hRes = pCP->Unadvise(dw); + return hRes; +} + +///////////////////////////////////////////////////////////////////////////// +// Inproc Marshaling helpers + +//This API should be called from the same thread that called +//AtlMarshalPtrInProc +ATLINLINE ATLAPI AtlFreeMarshalStream(_Inout_ IStream* pStream) +{ + HRESULT hRes=S_OK; + if (pStream != NULL) + { + LARGE_INTEGER l; + l.QuadPart = 0; + pStream->Seek(l, STREAM_SEEK_SET, NULL); + hRes=CoReleaseMarshalData(pStream); + pStream->Release(); + } + return hRes; +} + +ATLPREFAST_SUPPRESS(6387) +ATLINLINE ATLAPI AtlMarshalPtrInProc( + _Inout_ IUnknown* pUnk, + _In_ const IID& iid, + _Deref_out_ IStream** ppStream) +{ + ATLASSERT(ppStream != NULL); + if (ppStream == NULL) + return E_POINTER; + + HRESULT hRes = CreateStreamOnHGlobal(NULL, TRUE, ppStream); + if (SUCCEEDED(hRes)) + { + hRes = CoMarshalInterface(*ppStream, iid, + pUnk, MSHCTX_INPROC, NULL, MSHLFLAGS_TABLESTRONG); + if (FAILED(hRes)) + { + (*ppStream)->Release(); + *ppStream = NULL; + } + } + return hRes; +} +ATLPREFAST_UNSUPPRESS() + +ATLINLINE ATLAPI AtlUnmarshalPtr( + _Inout_ IStream* pStream, + _In_ const IID& iid, + _Deref_out_ IUnknown** ppUnk) +{ + ATLASSERT(ppUnk != NULL); + if (ppUnk == NULL) + return E_POINTER; + + *ppUnk = NULL; + HRESULT hRes = E_INVALIDARG; + if (pStream != NULL) + { + LARGE_INTEGER l; + l.QuadPart = 0; + pStream->Seek(l, STREAM_SEEK_SET, NULL); + hRes = CoUnmarshalInterface(pStream, iid, (void**)ppUnk); + } + return hRes; +} + +///////////////////////////////////////////////////////////////////////////// +// Module +ATLPREFAST_SUPPRESS(6387) +ATLINLINE ATLAPI AtlComModuleGetClassObject( + _Inout_ _ATL_COM_MODULE* pComModule, + _In_ REFCLSID rclsid, + _In_ REFIID riid, + _Deref_out_ LPVOID* ppv) +{ + if (ppv == NULL) + { + return E_POINTER; + } + + *ppv = NULL; + + ATLASSERT(pComModule != NULL); + if (pComModule == NULL) + { + return E_INVALIDARG; + } + + if (pComModule->cbSize == 0) // Module hasn't been initialized + { + return E_UNEXPECTED; + } + + HRESULT hr = S_OK; + + for (_ATL_OBJMAP_ENTRY** ppEntry = pComModule->m_ppAutoObjMapFirst; ppEntry < pComModule->m_ppAutoObjMapLast; ppEntry++) + { + if (*ppEntry != NULL) + { + const _ATL_OBJMAP_ENTRY* pEntry = *ppEntry; + + if ((pEntry->pfnGetClassObject != NULL) && InlineIsEqualGUID(rclsid, *pEntry->pclsid)) + { + if (pEntry->pCF == NULL) + { + CComCritSecLock lock(pComModule->m_csObjMap, false); + hr = lock.Lock(); + if (FAILED(hr)) + { + ATLASSERT(FALSE); + break; + } + + if (pEntry->pCF == NULL) + { + hr = pEntry->pfnGetClassObject(pEntry->pfnCreateInstance, __uuidof(IUnknown), (LPVOID*)&pEntry->pCF); + } + } + + if (pEntry->pCF != NULL) + { + hr = pEntry->pCF->QueryInterface(riid, ppv); + } + break; + } + } + } + + if (*ppv == NULL && hr == S_OK) + { + hr = CLASS_E_CLASSNOTAVAILABLE; + } + + return hr; +} +ATLPREFAST_UNSUPPRESS() + +ATLINLINE ATLAPI AtlComModuleRegisterClassObjects( + _Inout_ _ATL_COM_MODULE* pComModule, + _In_ DWORD dwClsContext, + _In_ DWORD dwFlags) +{ + ATLASSERT(pComModule != NULL); + if (pComModule == NULL) + return E_INVALIDARG; + + HRESULT hr = S_FALSE; + for (_ATL_OBJMAP_ENTRY** ppEntry = pComModule->m_ppAutoObjMapFirst; ppEntry < pComModule->m_ppAutoObjMapLast && SUCCEEDED(hr); ppEntry++) + { + if (*ppEntry != NULL) + hr = (*ppEntry)->RegisterClassObject(dwClsContext, dwFlags); + } + return hr; +} + +ATLINLINE ATLAPI AtlComModuleRevokeClassObjects( + _Inout_ _ATL_COM_MODULE* pComModule) +{ + ATLASSERT(pComModule != NULL); + if (pComModule == NULL) + return E_INVALIDARG; + + HRESULT hr = S_OK; + for (_ATL_OBJMAP_ENTRY** ppEntry = pComModule->m_ppAutoObjMapFirst; ppEntry < pComModule->m_ppAutoObjMapLast && hr == S_OK; ppEntry++) + { + if (*ppEntry != NULL) + hr = (*ppEntry)->RevokeClassObject(); + } + return hr; +} + +ATLINLINE ATLAPI_(BOOL) AtlWaitWithMessageLoop(_In_ HANDLE hEvent) +{ + DWORD dwRet; + MSG msg; + + while(1) + { + dwRet = MsgWaitForMultipleObjectsEx(1, &hEvent, INFINITE, QS_ALLINPUT, MWMO_INPUTAVAILABLE); + + if (dwRet == WAIT_OBJECT_0) + return TRUE; // The event was signaled + + if (dwRet != WAIT_OBJECT_0 + 1) + break; // Something else happened + + // There is one or more window message available. Dispatch them + while(PeekMessage(&msg,0,0,0,PM_NOREMOVE)) + { + // check for unicode window so we call the appropriate functions + BOOL bUnicode = ::IsWindowUnicode(msg.hwnd); + BOOL bRet; + + if (bUnicode) + bRet = ::GetMessageW(&msg, NULL, 0, 0); + else + bRet = ::GetMessageA(&msg, NULL, 0, 0); + + if (bRet > 0) + { + ::TranslateMessage(&msg); + + if (bUnicode) + ::DispatchMessageW(&msg); + else + ::DispatchMessageA(&msg); + } + + if (WaitForSingleObject(hEvent, 0) == WAIT_OBJECT_0) + return TRUE; // Event is now signaled. + } + } + return FALSE; +} + +///////////////////////////////////////////////////////////////////////////// +// QI support +ATLPREFAST_SUPPRESS(6387) +ATLINLINE ATLAPI AtlInternalQueryInterface( + _Inout_ void* pThis, + _In_ const _ATL_INTMAP_ENTRY* pEntries, + _In_ REFIID iid, + _Deref_out_ void** ppvObject) +{ + ATLASSERT(pThis != NULL); + ATLASSERT(pEntries!= NULL); + + if(pThis == NULL || pEntries == NULL) + return E_INVALIDARG; + + // First entry in the com map should be a simple map entry + ATLASSERT(pEntries->pFunc == _ATL_SIMPLEMAPENTRY); + if (ppvObject == NULL) + return E_POINTER; + *ppvObject = NULL; + if (InlineIsEqualUnknown(iid)) // use first interface + { + IUnknown* pUnk = (IUnknown*)((INT_PTR)pThis+pEntries->dw); + pUnk->AddRef(); + *ppvObject = pUnk; + return S_OK; + } + while (pEntries->pFunc != NULL) + { + BOOL bBlind = (pEntries->piid == NULL); + if (bBlind || InlineIsEqualGUID(*(pEntries->piid), iid)) + { + if (pEntries->pFunc == _ATL_SIMPLEMAPENTRY) //offset + { + ATLASSERT(!bBlind); + IUnknown* pUnk = (IUnknown*)((INT_PTR)pThis+pEntries->dw); + pUnk->AddRef(); + *ppvObject = pUnk; + return S_OK; + } + else //actual function call + { + HRESULT hRes = pEntries->pFunc(pThis, + iid, ppvObject, pEntries->dw); + if (hRes == S_OK || (!bBlind && FAILED(hRes))) + return hRes; + } + } + pEntries++; + } + return E_NOINTERFACE; +} +ATLPREFAST_UNSUPPRESS() + +ATLINLINE ATLAPI_(DWORD) AtlGetVersion(_In_opt_ void* /* pReserved */) +{ + return _ATL_VER; +} + +///////////////////////////////////////////////////////////////////////////// +// Windowing + +ATLINLINE ATLAPI_(void) AtlWinModuleAddCreateWndData( + _Inout_ _ATL_WIN_MODULE* pWinModule, + _Inout_ _AtlCreateWndData* pData, + _In_ void* pObject) +{ + if (pWinModule == NULL) + _AtlRaiseException((DWORD)EXCEPTION_ACCESS_VIOLATION); + + ATLASSERT(pData != NULL && pObject != NULL); + if(pData == NULL || pObject == NULL) + _AtlRaiseException((DWORD)EXCEPTION_ACCESS_VIOLATION); + + pData->m_pThis = pObject; + pData->m_dwThreadID = ::GetCurrentThreadId(); + CComCritSecLock lock(pWinModule->m_csWindowCreate, false); + if (FAILED(lock.Lock())) + { + ATLASSERT(0); + return; + } + pData->m_pNext = pWinModule->m_pCreateWndList; + pWinModule->m_pCreateWndList = pData; +} + +ATLINLINE ATLAPI_(void*) AtlWinModuleExtractCreateWndData( + _Inout_opt_ _ATL_WIN_MODULE* pWinModule) +{ + if (pWinModule == NULL) + return NULL; + + void* pv = NULL; + CComCritSecLock lock(pWinModule->m_csWindowCreate, false); + if (FAILED(lock.Lock())) + { + ATLASSERT(0); + return pv; + } + _AtlCreateWndData* pEntry = pWinModule->m_pCreateWndList; + if(pEntry != NULL) + { + DWORD dwThreadID = ::GetCurrentThreadId(); + _AtlCreateWndData* pPrev = NULL; + while(pEntry != NULL) + { + if(pEntry->m_dwThreadID == dwThreadID) + { + if(pPrev == NULL) + pWinModule->m_pCreateWndList = pEntry->m_pNext; + else + pPrev->m_pNext = pEntry->m_pNext; + pv = pEntry->m_pThis; + break; + } + pPrev = pEntry; + pEntry = pEntry->m_pNext; + } + } + return pv; +} + +ATLINLINE ATLAPI AtlWinModuleInit( + _Inout_ _ATL_WIN_MODULE* pWinModule) +{ + if (pWinModule == NULL) + return E_INVALIDARG; + + // check only in the DLL + if (pWinModule->cbSize != sizeof(_ATL_WIN_MODULE)) + return E_INVALIDARG; + + pWinModule->m_pCreateWndList = NULL; + + HRESULT hr = pWinModule->m_csWindowCreate.Init(); + if (FAILED(hr)) + { + ATLASSERT(0); + } + return hr; +} + +///////////////////////////////////////////////////////////////////////////// +// Module + +ATLINLINE ATLAPI AtlModuleAddTermFunc( + _Inout_ _ATL_MODULE* pModule, + _In_ _ATL_TERMFUNC* pFunc, + _In_ DWORD_PTR dw) +{ + if (pModule == NULL) + return E_INVALIDARG; + + HRESULT hr = S_OK; + _ATL_TERMFUNC_ELEM* pNew = NULL; + ATLTRY(pNew = new _ATL_TERMFUNC_ELEM); + if (pNew == NULL) + hr = E_OUTOFMEMORY; + else + { + pNew->pFunc = pFunc; + pNew->dw = dw; + CComCritSecLock lock(pModule->m_csStaticDataInitAndTypeInfo, false); + hr = lock.Lock(); + if (SUCCEEDED(hr)) + { + pNew->pNext = pModule->m_pTermFuncs; + pModule->m_pTermFuncs = pNew; + } + else + { + delete pNew; + ATLASSERT(0); + } + } + return hr; +} + +ATLINLINE ATLAPI_(void) AtlCallTermFunc(_Inout_ _ATL_MODULE* pModule) +{ + if (pModule == NULL) + _AtlRaiseException((DWORD)EXCEPTION_ACCESS_VIOLATION); + + _ATL_TERMFUNC_ELEM* pElem = pModule->m_pTermFuncs; + _ATL_TERMFUNC_ELEM* pNext = NULL; + while (pElem != NULL) + { + pElem->pFunc(pElem->dw); + pNext = pElem->pNext; + delete pElem; + pElem = pNext; + } + pModule->m_pTermFuncs = NULL; +} + +} // namespace ATL +#pragma warning(pop) +#endif // __ATLBASE_INL__ diff --git a/src/main/headers/atlchecked.h b/src/main/headers/atlchecked.h new file mode 100644 index 0000000..3656462 --- /dev/null +++ b/src/main/headers/atlchecked.h @@ -0,0 +1,398 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#ifndef __ATLCHECKED_H__ +#define __ATLCHECKED_H__ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + + +#pragma pack(push,_ATL_PACKING) +namespace ATL +{ + +inline errno_t AtlCrtErrorCheck(_In_ errno_t nError) +{ + switch(nError) + { + case ENOMEM: + AtlThrow(E_OUTOFMEMORY); + break; + case EINVAL: + case ERANGE: + AtlThrow(E_INVALIDARG); + break; + case 0: + case STRUNCATE: + break; + default: + AtlThrow(E_FAIL); + break; + } + return nError; +} + +///////////////////////////////////////////////////////////////////////////// +// Secure (Checked) CRT functions + +namespace Checked +{ + +#ifdef _AFX +#define ATLMFC_CRT_ERRORCHECK(expr) AFX_CRT_ERRORCHECK(expr) +#else +#define ATLMFC_CRT_ERRORCHECK(expr) ATL_CRT_ERRORCHECK(expr) +#endif + +inline void __cdecl memcpy_s( + _Out_bytecap_post_bytecount_(_S1max,_N) void *_S1, + _In_ size_t _S1max, + _In_bytecount_(_N) const void *_S2, + _In_ size_t _N) +{ + ATLMFC_CRT_ERRORCHECK(::memcpy_s(_S1, _S1max, _S2, _N)); +} + +inline void __cdecl wmemcpy_s( + _Out_cap_post_count_(_N1,_N) wchar_t *_S1, + _In_ size_t _N1, + _In_count_(_N) const wchar_t *_S2, + _In_ size_t _N) +{ + ATLMFC_CRT_ERRORCHECK(::wmemcpy_s(_S1, _N1, _S2, _N)); +} + +inline void __cdecl memmove_s( + _Out_bytecap_post_bytecount_(_S1max,_N) void *_S1, + _In_ size_t _S1max, + _In_bytecount_(_N) const void *_S2, + _In_ size_t _N) +{ + ATLMFC_CRT_ERRORCHECK(::memmove_s(_S1, _S1max, _S2, _N)); +} + +inline void __cdecl strcpy_s( + _Out_z_cap_(_S1max) char *_S1, + _In_ size_t _S1max, + _In_z_ const char *_S2) +{ + ATLMFC_CRT_ERRORCHECK(::strcpy_s(_S1, _S1max, _S2)); +} + +inline void __cdecl wcscpy_s( + _Out_z_cap_(_S1max) wchar_t *_S1, + _In_ size_t _S1max, + _In_z_ const wchar_t *_S2) +{ + ATLMFC_CRT_ERRORCHECK(::wcscpy_s(_S1, _S1max, _S2)); +} + +inline void __cdecl tcscpy_s( + _Out_z_cap_(_SizeInChars) TCHAR * _Dst, + _In_ size_t _SizeInChars, + _In_z_ const TCHAR * _Src) +{ + ATLMFC_CRT_ERRORCHECK(::_tcscpy_s(_Dst, _SizeInChars, _Src)); +} + +inline errno_t __cdecl strncpy_s( + _Out_z_cap_(_SizeInChars) char *_Dest, + _In_ size_t _SizeInChars, + _In_z_ const char *_Source, + _In_ size_t _Count) +{ + return ATLMFC_CRT_ERRORCHECK(::strncpy_s(_Dest, _SizeInChars, _Source,_Count)); +} + +inline errno_t __cdecl wcsncpy_s( + _Out_z_cap_(_SizeInChars) wchar_t *_Dest, + _In_ size_t _SizeInChars, + _In_z_ const wchar_t *_Source, + _In_ size_t _Count) +{ + return ATLMFC_CRT_ERRORCHECK(::wcsncpy_s(_Dest, _SizeInChars, _Source,_Count)); +} + +inline errno_t __cdecl tcsncpy_s( + _Out_z_cap_(_SizeInChars) TCHAR *_Dest, + _In_ size_t _SizeInChars, + _In_z_ const TCHAR *_Source, + _In_ size_t _Count) +{ + return ATLMFC_CRT_ERRORCHECK(::_tcsncpy_s(_Dest, _SizeInChars, _Source,_Count)); +} + +inline void __cdecl strcat_s( + _Inout_z_cap_(_SizeInChars) char * _Dst, + _In_ size_t _SizeInChars, + _In_z_ const char * _Src) +{ + ATLMFC_CRT_ERRORCHECK(::strcat_s(_Dst, _SizeInChars, _Src)); +} + +inline void __cdecl wcscat_s( + _Inout_z_cap_(_SizeInChars) wchar_t * _Dst, + _In_ size_t _SizeInChars, + _In_z_ const wchar_t * _Src) +{ + ATLMFC_CRT_ERRORCHECK(::wcscat_s(_Dst, _SizeInChars, _Src)); +} + +inline void __cdecl tcscat_s( + _Inout_z_cap_(_SizeInChars) TCHAR * _Dst, + _In_ size_t _SizeInChars, + _In_z_ const TCHAR * _Src) +{ + ATLMFC_CRT_ERRORCHECK(::_tcscat_s(_Dst, _SizeInChars, _Src)); +} + +inline void __cdecl strlwr_s( + _Inout_z_cap_(_SizeInChars) char * _Str, + _In_ size_t _SizeInChars) +{ + ATLMFC_CRT_ERRORCHECK(::_strlwr_s(_Str, _SizeInChars)); +} + +inline void __cdecl wcslwr_s( + _Inout_z_cap_(_SizeInChars) wchar_t * _Str, + _In_ size_t _SizeInChars) +{ + ATLMFC_CRT_ERRORCHECK(::_wcslwr_s(_Str, _SizeInChars)); +} + +inline void __cdecl mbslwr_s( + _Inout_z_bytecap_(_SizeInChars) unsigned char * _Str, + _In_ size_t _SizeInChars) +{ + ATLMFC_CRT_ERRORCHECK(::_mbslwr_s(_Str, _SizeInChars)); +} + +inline void __cdecl tcslwr_s( + _Inout_z_cap_(_SizeInChars) TCHAR * _Str, + _In_ size_t _SizeInChars) +{ + ATLMFC_CRT_ERRORCHECK(::_tcslwr_s(_Str, _SizeInChars)); +} + +inline void __cdecl strupr_s( + _Inout_z_cap_(_SizeInChars) char * _Str, + _In_ size_t _SizeInChars) +{ + ATLMFC_CRT_ERRORCHECK(::_strupr_s(_Str, _SizeInChars)); +} + +inline void __cdecl wcsupr_s( + _Inout_z_cap_(_SizeInChars) wchar_t * _Str, + _In_ size_t _SizeInChars) +{ + ATLMFC_CRT_ERRORCHECK(::_wcsupr_s(_Str, _SizeInChars)); +} + +inline void __cdecl mbsupr_s( + _Inout_z_bytecap_(_SizeInChars) unsigned char * _Str, + _In_ size_t _SizeInChars) +{ + ATLMFC_CRT_ERRORCHECK(::_mbsupr_s(_Str, _SizeInChars)); +} + +inline void __cdecl tcsupr_s( + _Inout_z_cap_(_SizeInChars) TCHAR * _Str, + _In_ size_t _SizeInChars) +{ + ATLMFC_CRT_ERRORCHECK(::_tcsupr_s(_Str, _SizeInChars)); +} + +inline void __cdecl itoa_s( + _In_ int _Val, + _Out_z_cap_(_SizeInChars) char *_Buf, + _In_ size_t _SizeInChars, + _In_ int _Radix) +{ + ATLMFC_CRT_ERRORCHECK(::_itoa_s(_Val, _Buf, _SizeInChars, _Radix)); +} + +inline void __cdecl itot_s( + _In_ int _Val, + _Out_z_cap_(_SizeInChars) TCHAR *_Buf, + _In_ size_t _SizeInChars, + _In_ int _Radix) +{ + ATLMFC_CRT_ERRORCHECK(::_itot_s(_Val, _Buf, _SizeInChars, _Radix)); +} + +inline void __cdecl ltoa_s( + _In_ long _Val, + _Out_z_cap_(_SizeInChars) char *_Buf, + _In_ size_t _SizeInChars, + _In_ int _Radix) +{ + ATLMFC_CRT_ERRORCHECK(::_ltoa_s(_Val, _Buf, _SizeInChars, _Radix)); +} + +inline void __cdecl ltot_s( + _In_ long _Val, + _Out_z_cap_(_SizeInChars) TCHAR *_Buf, + _In_ size_t _SizeInChars, + _In_ int _Radix) +{ + ATLMFC_CRT_ERRORCHECK(::_ltot_s(_Val, _Buf, _SizeInChars, _Radix)); +} + +inline void __cdecl ultoa_s( + _In_ unsigned long _Val, + _Out_z_cap_(_SizeInChars) char *_Buf, + _In_ size_t _SizeInChars, + _In_ int _Radix) +{ + ATLMFC_CRT_ERRORCHECK(::_ultoa_s(_Val, _Buf, _SizeInChars, _Radix)); +} + +inline void __cdecl ultow_s( + _In_ unsigned long _Val, + _Out_z_cap_(_SizeInChars) wchar_t *_Buf, + _In_ size_t _SizeInChars, + _In_ int _Radix) +{ + ATLMFC_CRT_ERRORCHECK(::_ultow_s(_Val, _Buf, _SizeInChars, _Radix)); +} + +inline void __cdecl ultot_s( + _In_ unsigned long _Val, + _Out_z_cap_(_SizeInChars) TCHAR *_Buf, + _In_ size_t _SizeInChars, + _In_ int _Radix) +{ + ATLMFC_CRT_ERRORCHECK(::_ultot_s(_Val, _Buf, _SizeInChars, _Radix)); +} + +inline void __cdecl i64toa_s( + _In_ __int64 _Val, + _Out_z_cap_(_SizeInChars) char *_Buf, + _In_ size_t _SizeInChars, + _In_ int _Radix) +{ + ATLMFC_CRT_ERRORCHECK(::_i64toa_s(_Val, _Buf, _SizeInChars, _Radix)); +} + +inline void __cdecl i64tow_s( + _In_ __int64 _Val, + _Out_z_cap_(_SizeInChars) wchar_t *_Buf, + _In_ size_t _SizeInChars, + _In_ int _Radix) +{ + ATLMFC_CRT_ERRORCHECK(::_i64tow_s(_Val, _Buf, _SizeInChars, _Radix)); +} + +inline void __cdecl ui64toa_s( + _In_ unsigned __int64 _Val, + _Out_z_cap_(_SizeInChars) char *_Buf, + _In_ size_t _SizeInChars, + _In_ int _Radix) +{ + ATLMFC_CRT_ERRORCHECK(::_ui64toa_s(_Val, _Buf, _SizeInChars, _Radix)); +} + +inline void __cdecl ui64tow_s( + _In_ unsigned __int64 _Val, + _Out_z_cap_(_SizeInChars) wchar_t *_Buf, + _In_ size_t _SizeInChars, + _In_ int _Radix) +{ + ATLMFC_CRT_ERRORCHECK(::_ui64tow_s(_Val, _Buf, _SizeInChars, _Radix)); +} + +inline void __cdecl gcvt_s( + _Out_z_cap_(_SizeInChars) char *_Buffer, + _In_ size_t _SizeInChars, + _In_ double _Value, + _In_ int _Ndec) +{ + ATLMFC_CRT_ERRORCHECK(::_gcvt_s(_Buffer, _SizeInChars, _Value, _Ndec)); +} + +inline void __cdecl tsplitpath_s( + _In_z_ const TCHAR *_Path, + _Out_opt_z_cap_(_Drive_len) TCHAR *_Drive, + _In_ size_t _Drive_len, + _Out_opt_z_cap_(_Dir_len) TCHAR *_Dir, + _In_ size_t _Dir_len, + _Out_opt_z_cap_(_Fname_len) TCHAR *_Fname, + _In_ size_t _Fname_len, + _Out_opt_z_cap_(_Ext_len) TCHAR *_Ext, + _In_ size_t _Ext_len) +{ + ATLMFC_CRT_ERRORCHECK(::_tsplitpath_s(_Path, _Drive, _Drive_len, _Dir, _Dir_len, _Fname, _Fname_len, _Ext, _Ext_len)); +} + +inline void __cdecl tmakepath_s( + _Out_z_cap_(_SizeInChars) TCHAR *_Path, + _In_ size_t _SizeInChars, + _In_z_ const TCHAR *_Drive, + _In_z_ const TCHAR *_Dir, + _In_z_ const TCHAR *_Fname, + _In_z_ const TCHAR *_Ext) +{ + ATLMFC_CRT_ERRORCHECK(::_tmakepath_s(_Path, _SizeInChars, _Drive, _Dir, _Fname, _Ext)); +} + +inline size_t __cdecl strnlen( + _In_z_count_(_Maxsize) const char *_Str, + _In_ size_t _Maxsize) +{ + return ::strnlen(_Str, _Maxsize); +} + +inline size_t __cdecl wcsnlen( + _In_z_count_(_Maxsize) const wchar_t *_Wcs, + _In_ size_t _Maxsize) +{ + return ::wcsnlen(_Wcs, _Maxsize); +} + +inline size_t __cdecl tcsnlen( + _In_z_count_(_Maxsize) const TCHAR *_Str, + _In_ size_t _Maxsize) +{ + return ::_tcsnlen(_Str, _Maxsize); +} + +inline int get_errno() throw() +{ + int nErrNo=0; + errno_t nErrCall=::_get_errno(&nErrNo); + if(nErrCall) + { + return nErrCall; + } + return nErrNo; +} + +inline void set_errno(_In_ int _Value) +{ + ATLMFC_CRT_ERRORCHECK(::_set_errno(_Value)); +} + +} // namespace Checked + +} // namespace ATL +#pragma pack(pop) + +#endif // __ATLCHECKED_H__ + +///////////////////////////////////////////////////////////////////////////// diff --git a/src/main/headers/atlcomcli.h b/src/main/headers/atlcomcli.h new file mode 100644 index 0000000..33924e4 --- /dev/null +++ b/src/main/headers/atlcomcli.h @@ -0,0 +1,3210 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#ifndef __ATLCOMCLI_H__ +#define __ATLCOMCLI_H__ + +#pragma once + +#include +#include +#include +#include + +#pragma warning (push) +#pragma warning (disable: 4127) // conditional expression constant +#pragma warning (disable: 4571) //catch(...) blocks compiled with /EHs do NOT catch or re-throw Structured Exceptions + + +#pragma pack(push,_ATL_PACKING) +namespace ATL +{ +///////////////////////////////////////////////////////////////////////////// +// Error to HRESULT helpers + +ATL_NOINLINE inline HRESULT AtlHresultFromLastError() throw() +{ + DWORD dwErr = ::GetLastError(); + return HRESULT_FROM_WIN32(dwErr); +} + +ATL_NOINLINE inline HRESULT AtlHresultFromWin32(_In_ DWORD nError) throw() +{ + return( HRESULT_FROM_WIN32( nError ) ); +} + +///////////////////////////////////////////////////////////////////////////// +// Smart Pointer helpers + +ATLAPI_(IUnknown*) AtlComPtrAssign( + _Inout_opt_ _Deref_pre_maybenull_ _Deref_post_maybenull_ IUnknown** pp, + _In_opt_ IUnknown* lp); + +ATLAPI_(IUnknown*) AtlComQIPtrAssign( + _Inout_opt_ _Deref_pre_maybenull_ _Deref_post_maybenull_ IUnknown** pp, + _In_opt_ IUnknown* lp, + _In_ REFIID riid); + +///////////////////////////////////////////////////////////////////////////// +// Safe Ole Object Reading + +#if !defined(__MINGW32__) +union ClassesAllowedInStream +{ + const CLSID *rgclsidAllowed; + HRESULT (*pfnClsidAllowed)( + _In_ const CLSID& clsid, + _In_ REFIID iidInterface, + _Deref_out_opt_ void** ppvObj); +}; +#endif + +#ifndef _ATL_DLL + +ATLINLINE ATLAPI_(IUnknown*) AtlComPtrAssign( + _Inout_opt_ _Deref_pre_maybenull_ _Deref_post_maybenull_ IUnknown** pp, + _In_opt_ IUnknown* lp) +{ + if (pp == NULL) + return NULL; + + if (lp != NULL) + lp->AddRef(); + if (*pp) + (*pp)->Release(); + *pp = lp; + return lp; +} + +ATLINLINE ATLAPI_(IUnknown*) AtlComQIPtrAssign( + _Inout_opt_ _Deref_pre_maybenull_ _Deref_post_maybenull_ IUnknown** pp, + _In_opt_ IUnknown* lp, + _In_ REFIID riid) +{ + if (pp == NULL) + return NULL; + + IUnknown* pTemp = *pp; + *pp = NULL; + if (lp != NULL) + lp->QueryInterface(riid, (void**)pp); + if (pTemp) + pTemp->Release(); + return *pp; +} + +#endif // _ATL_DLL + +///////////////////////////////////////////////////////////////////////////// +// COM Smart pointers + +template +class _NoAddRefReleaseOnCComPtr : + public T +{ + private: + STDMETHOD_(ULONG, AddRef)()=0; + STDMETHOD_(ULONG, Release)()=0; +}; + +_Check_return_ inline HRESULT AtlSetChildSite( + _Inout_ IUnknown* punkChild, + _Inout_opt_ IUnknown* punkParent) +{ + if (punkChild == NULL) + return E_POINTER; + + HRESULT hr; + IObjectWithSite* pChildSite = NULL; + hr = punkChild->QueryInterface(__uuidof(IObjectWithSite), (void**)&pChildSite); + if (SUCCEEDED(hr) && pChildSite != NULL) + { + hr = pChildSite->SetSite(punkParent); + pChildSite->Release(); + } + return hr; +} + + +//CComPtrBase provides the basis for all other smart pointers +//The other smartpointers add their own constructors and operators +template +class CComPtrBase +{ +protected: + CComPtrBase() throw() + { + p = NULL; + } + CComPtrBase(_Inout_opt_ T* lp) throw() + { + p = lp; + if (p != NULL) + p->AddRef(); + } +public: + typedef T _PtrClass; + ~CComPtrBase() throw() + { + if (p) + p->Release(); + } + operator T*() const throw() + { + return p; + } + T& operator*() const + { + ATLENSURE(p!=NULL); + return *p; + } + //The assert on operator& usually indicates a bug. If this is really + //what is needed, however, take the address of the p member explicitly. + T** operator&() throw() + { + ATLASSERT(p==NULL); + return &p; + } + _NoAddRefReleaseOnCComPtr* operator->() const throw() + { + ATLASSERT(p!=NULL); + return (_NoAddRefReleaseOnCComPtr*)p; + } + bool operator!() const throw() + { + return (p == NULL); + } + bool operator<(_In_opt_ T* pT) const throw() + { + return p < pT; + } + bool operator!=(_In_opt_ T* pT) const + { + return !operator==(pT); + } + bool operator==(_In_opt_ T* pT) const throw() + { + return p == pT; + } + + // Release the interface and set to NULL + void Release() throw() + { + T* pTemp = p; + if (pTemp) + { + p = NULL; + pTemp->Release(); + } + } + // Compare two objects for equivalence + bool IsEqualObject(_Inout_opt_ IUnknown* pOther) throw() + { + /*if (p == NULL && pOther == NULL) + return true; // They are both NULL objects + + if (p == NULL || pOther == NULL) + return false; // One is NULL the other is not + + CComPtr punk1; + CComPtr punk2; + p->QueryInterface(__uuidof(IUnknown), (void**)&punk1); + pOther->QueryInterface(__uuidof(IUnknown), (void**)&punk2); + return punk1 == punk2;*/ + return false; + } + // Attach to an existing interface (does not AddRef) + void Attach(_In_opt_ T* p2) throw() + { + if (p) + p->Release(); + p = p2; + } + // Detach the interface (does not Release) + T* Detach() throw() + { + T* pt = p; + p = NULL; + return pt; + } + _Check_return_ HRESULT CopyTo(_Deref_out_opt_ T** ppT) throw() + { + ATLASSERT(ppT != NULL); + if (ppT == NULL) + return E_POINTER; + *ppT = p; + if (p) + p->AddRef(); + return S_OK; + } + _Check_return_ HRESULT SetSite(_Inout_opt_ IUnknown* punkParent) throw() + { + return AtlSetChildSite(p, punkParent); + } + _Check_return_ HRESULT Advise( + _Inout_ IUnknown* pUnk, + _In_ const IID& iid, + _Out_ LPDWORD pdw) throw() + { + return AtlAdvise(p, pUnk, iid, pdw); + } + _Check_return_ HRESULT CoCreateInstance( + _In_ REFCLSID rclsid, + _Inout_opt_ LPUNKNOWN pUnkOuter = NULL, + _In_ DWORD dwClsContext = CLSCTX_ALL) throw() + { + ATLASSERT(p == NULL); + return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p); + } + _Check_return_ HRESULT CoCreateInstance( + _In_z_ LPCOLESTR szProgID, + _Inout_opt_ LPUNKNOWN pUnkOuter = NULL, + _In_ DWORD dwClsContext = CLSCTX_ALL) throw() + { + CLSID clsid; + HRESULT hr = CLSIDFromProgID(szProgID, &clsid); + ATLASSERT(p == NULL); + if (SUCCEEDED(hr)) + hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p); + return hr; + } + template + _Check_return_ HRESULT QueryInterface(_Deref_out_ Q** pp) const throw() + { + ATLASSERT(pp != NULL); + return p->QueryInterface(__uuidof(Q), (void**)pp); + } + T* p; +}; + +template +class CComPtr : + public CComPtrBase +{ +public: + CComPtr() throw() + { + } + CComPtr(_Inout_opt_ T* lp) throw() : + CComPtrBase(lp) + { + } + CComPtr(_Inout_ const CComPtr& lp) throw() : + CComPtrBase(lp.p) + { + } + T* operator=(_Inout_opt_ T* lp) throw() + { + if(*this!=lp) + { + return static_cast(AtlComPtrAssign((IUnknown**)&this->p, lp)); + } + return *this; + } + template + T* operator=(_Inout_ const CComPtr& lp) throw() + { + if( !IsEqualObject(lp) ) + { + return static_cast(AtlComQIPtrAssign((IUnknown**)&this->p, lp, __uuidof(T))); + } + return *this; + } + T* operator=(_Inout_ const CComPtr& lp) throw() + { + if(*this!=lp) + { + return static_cast(AtlComPtrAssign((IUnknown**)&this->p, lp)); + } + return *this; + } +#if !defined(__MINGW32__) + CComPtr(_Inout_ CComPtr&& lp) throw() : + CComPtrBase() + { + p = lp.p; + lp.p = NULL; + } + T* operator=(_Inout_ CComPtr&& lp) throw() + { + if (*this != lp) + { + if (p != NULL) + p->Release(); + + p = lp.p; + lp.p = NULL; + } + return *this; + } +#endif +}; + +//specialization for IDispatch +template <> +class CComPtr : + public CComPtrBase +{ +public: + CComPtr() throw() + { + } + CComPtr(_Inout_opt_ IDispatch* lp) throw() : + CComPtrBase(lp) + { + } + CComPtr(_Inout_ const CComPtr& lp) throw() : + CComPtrBase(lp.p) + { + } + IDispatch* operator=(_Inout_opt_ IDispatch* lp) throw() + { + if(*this!=lp) + { + return static_cast(AtlComPtrAssign((IUnknown**)&this->p, lp)); + } + return *this; + } + IDispatch* operator=(_Inout_ const CComPtr& lp) throw() + { + if(*this!=lp) + { + return static_cast(AtlComPtrAssign((IUnknown**)&this->p, lp.p)); + } + return *this; + } +#if !defined(__MINGW32__) + CComPtr(_Inout_ CComPtr&& lp) throw() : + CComPtrBase() + { + p = lp.p; + lp.p = NULL; + } + IDispatch* operator=(_Inout_ CComPtr&& lp) throw() + { + if (*this != lp) + { + if (p != NULL) + p->Release(); + + p = lp.p; + lp.p = NULL; + } + return *this; + } +#endif +// IDispatch specific stuff + _Check_return_ HRESULT GetPropertyByName( + _In_z_ LPCOLESTR lpsz, + _Out_ VARIANT* pVar) throw() + { + ATLASSERT(p); + ATLASSERT(pVar); + DISPID dwDispID; + HRESULT hr = GetIDOfName(lpsz, &dwDispID); + if (SUCCEEDED(hr)) + hr = GetProperty(dwDispID, pVar); + return hr; + } + _Check_return_ HRESULT GetProperty( + _In_ DISPID dwDispID, + _Out_ VARIANT* pVar) throw() + { + return GetProperty(p, dwDispID, pVar); + } + _Check_return_ HRESULT PutPropertyByName( + _In_z_ LPCOLESTR lpsz, + _In_ VARIANT* pVar) throw() + { + ATLASSERT(p); + ATLASSERT(pVar); + DISPID dwDispID; + HRESULT hr = GetIDOfName(lpsz, &dwDispID); + if (SUCCEEDED(hr)) + hr = PutProperty(dwDispID, pVar); + return hr; + } + _Check_return_ HRESULT PutProperty( + _In_ DISPID dwDispID, + _In_ VARIANT* pVar) throw() + { + return PutProperty(p, dwDispID, pVar); + } + _Check_return_ HRESULT GetIDOfName( + _In_z_ LPCOLESTR lpsz, + _Out_ DISPID* pdispid) throw() + { + return p->GetIDsOfNames(IID_NULL, const_cast(&lpsz), 1, LOCALE_USER_DEFAULT, pdispid); + } + // Invoke a method by DISPID with no parameters + _Check_return_ HRESULT Invoke0( + _In_ DISPID dispid, + _Out_opt_ VARIANT* pvarRet = NULL) throw() + { + DISPPARAMS dispparams = { NULL, NULL, 0, 0}; + return p->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparams, pvarRet, NULL, NULL); + } + // Invoke a method by name with no parameters + _Check_return_ HRESULT Invoke0( + _In_z_ LPCOLESTR lpszName, + _Out_opt_ VARIANT* pvarRet = NULL) throw() + { + HRESULT hr; + DISPID dispid; + hr = GetIDOfName(lpszName, &dispid); + if (SUCCEEDED(hr)) + hr = Invoke0(dispid, pvarRet); + return hr; + } + // Invoke a method by DISPID with a single parameter + _Check_return_ HRESULT Invoke1( + _In_ DISPID dispid, + _In_ VARIANT* pvarParam1, + _Out_opt_ VARIANT* pvarRet = NULL) throw() + { + DISPPARAMS dispparams = { pvarParam1, NULL, 1, 0}; + return p->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparams, pvarRet, NULL, NULL); + } + // Invoke a method by name with a single parameter + _Check_return_ HRESULT Invoke1( + _In_z_ LPCOLESTR lpszName, + _In_ VARIANT* pvarParam1, + _Out_opt_ VARIANT* pvarRet = NULL) throw() + { + DISPID dispid; + HRESULT hr = GetIDOfName(lpszName, &dispid); + if (SUCCEEDED(hr)) + hr = Invoke1(dispid, pvarParam1, pvarRet); + return hr; + } + // Invoke a method by DISPID with two parameters + _Check_return_ HRESULT Invoke2( + _In_ DISPID dispid, + _In_ VARIANT* pvarParam1, + _In_ VARIANT* pvarParam2, + _Out_opt_ VARIANT* pvarRet = NULL) throw(); + // Invoke a method by name with two parameters + _Check_return_ HRESULT Invoke2( + _In_z_ LPCOLESTR lpszName, + _In_ VARIANT* pvarParam1, + _In_ VARIANT* pvarParam2, + _Out_opt_ VARIANT* pvarRet = NULL) throw() + { + DISPID dispid; + HRESULT hr = GetIDOfName(lpszName, &dispid); + if (SUCCEEDED(hr)) + hr = Invoke2(dispid, pvarParam1, pvarParam2, pvarRet); + return hr; + } + // Invoke a method by DISPID with N parameters + _Check_return_ HRESULT InvokeN( + _In_ DISPID dispid, + _In_ VARIANT* pvarParams, + _In_ int nParams, + _Out_opt_ VARIANT* pvarRet = NULL) throw() + { + DISPPARAMS dispparams = { pvarParams, NULL, nParams, 0}; + return p->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparams, pvarRet, NULL, NULL); + } + // Invoke a method by name with Nparameters + _Check_return_ HRESULT InvokeN( + _In_z_ LPCOLESTR lpszName, + _In_ VARIANT* pvarParams, + _In_ int nParams, + _Out_opt_ VARIANT* pvarRet = NULL) throw() + { + HRESULT hr; + DISPID dispid; + hr = GetIDOfName(lpszName, &dispid); + if (SUCCEEDED(hr)) + hr = InvokeN(dispid, pvarParams, nParams, pvarRet); + return hr; + } + _Check_return_ static HRESULT PutProperty( + _In_ IDispatch* p, + _In_ DISPID dwDispID, + _In_ VARIANT* pVar) throw() + { + ATLASSERT(p); + ATLASSERT(pVar != NULL); + if (pVar == NULL) + return E_POINTER; + + if(p == NULL) + return E_INVALIDARG; + + DISPPARAMS dispparams = {NULL, NULL, 1, 1}; + dispparams.rgvarg = pVar; + DISPID dispidPut = DISPID_PROPERTYPUT; + dispparams.rgdispidNamedArgs = &dispidPut; + + if (pVar->vt == VT_UNKNOWN || pVar->vt == VT_DISPATCH || + (pVar->vt & VT_ARRAY) || (pVar->vt & VT_BYREF)) + { + HRESULT hr = p->Invoke(dwDispID, IID_NULL, + LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUTREF, + &dispparams, NULL, NULL, NULL); + if (SUCCEEDED(hr)) + return hr; + } + return p->Invoke(dwDispID, IID_NULL, + LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, + &dispparams, NULL, NULL, NULL); + } + _Check_return_ static HRESULT GetProperty( + _In_ IDispatch* p, + _In_ DISPID dwDispID, + _Out_ VARIANT* pVar) throw() + { + ATLASSERT(p); + ATLASSERT(pVar != NULL); + if (pVar == NULL) + return E_POINTER; + + if(p == NULL) + return E_INVALIDARG; + + DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; + return p->Invoke(dwDispID, IID_NULL, + LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, + &dispparamsNoArgs, pVar, NULL, NULL); + } +}; + +template +class CComQIPtr : + public CComPtr +{ +public: + CComQIPtr() throw() + { + } + CComQIPtr(_Inout_opt_ T* lp) throw() : + CComPtr(lp) + { + } + CComQIPtr(_Inout_ const CComQIPtr& lp) throw() : + CComPtr(lp.p) + { + } + CComQIPtr(_Inout_opt_ IUnknown* lp) throw() + { + if (lp != NULL) + lp->QueryInterface(*piid, (void **)&this->p); + } + T* operator=(_Inout_opt_ T* lp) throw() + { + if(*this!=lp) + { + return static_cast(AtlComPtrAssign((IUnknown**)&this->p, lp)); + } + return *this; + } + T* operator=(_Inout_ const CComQIPtr& lp) throw() + { + if(*this!=lp) + { + return static_cast(AtlComPtrAssign((IUnknown**)&this->p, lp.p)); + } + return *this; + } + T* operator=(_Inout_opt_ IUnknown* lp) throw() + { + if(*this!=lp) + { + return static_cast(AtlComQIPtrAssign((IUnknown**)&this->p, lp, *piid)); + } + return *this; + } +}; + +//Specialization to make it work +template<> +class CComQIPtr : + public CComPtr +{ +public: + CComQIPtr() throw() + { + } + CComQIPtr(_Inout_opt_ IUnknown* lp) throw() + { + //Actually do a QI to get identity + if (lp != NULL) + lp->QueryInterface(__uuidof(IUnknown), (void **)&this->p); + } + CComQIPtr(_Inout_ const CComQIPtr& lp) throw() : + CComPtr(lp.p) + { + } + IUnknown* operator=(_Inout_opt_ IUnknown* lp) throw() + { + if(*this!=lp) + { + //Actually do a QI to get identity + return AtlComQIPtrAssign((IUnknown**)&this->p, lp, __uuidof(IUnknown)); + } + return *this; + } + + IUnknown* operator=(_Inout_ const CComQIPtr& lp) throw() + { + if(*this!=lp) + { + return AtlComPtrAssign((IUnknown**)&this->p, lp.p); + } + return *this; + } +}; + +#if !defined(__MINGW32__) +typedef CComQIPtr CComDispatchDriver; +#endif + +#define com_cast ATL::CComQIPtr +#ifndef _ATL_STREAM_MAX_SIZE +#define _ATL_STREAM_MAX_SIZE 0x100000 +#endif + +///////////////////////////////////////////////////////////////////////////// +// CComBSTR + +class CComBSTR +{ +public: + BSTR m_str; + + CComBSTR() throw() + { + m_str = NULL; + } + +#ifdef _ATL_CCOMBSTR_EXPLICIT_CONSTRUCTORS + explicit CComBSTR(_In_ int nSize) +#else + CComBSTR(_In_ int nSize) +#endif + { + if (nSize < 0) + { + AtlThrow(E_INVALIDARG); + } + + if (nSize == 0) + { + m_str = NULL; + } + else + { + m_str = ::SysAllocStringLen(NULL, nSize); + if (!*this) + { + AtlThrow(E_OUTOFMEMORY); + } + } + } + + CComBSTR(_In_ int nSize, _In_opt_count_(nSize) LPCOLESTR sz) + { + if (nSize < 0) + { + AtlThrow(E_INVALIDARG); + } + + if (nSize == 0) + { + m_str = NULL; + } + else + { + m_str = ::SysAllocStringLen(sz, nSize); + if (!*this) + { + AtlThrow(E_OUTOFMEMORY); + } + } + } + + CComBSTR(_In_opt_z_ LPCOLESTR pSrc) + { + if (pSrc == NULL) + { + m_str = NULL; + } + else + { + m_str = ::SysAllocString(pSrc); + if (!*this) + { + AtlThrow(E_OUTOFMEMORY); + } + } + } + + CComBSTR(_In_ const CComBSTR& src) + { + m_str = src.Copy(); + if (!!src && !*this) + { + AtlThrow(E_OUTOFMEMORY); + } + } + + CComBSTR(_In_ REFGUID guid) + { + OLECHAR szGUID[64]; + ::StringFromGUID2(guid, szGUID, 64); + m_str = ::SysAllocString(szGUID); + if (!*this) + { + AtlThrow(E_OUTOFMEMORY); + } + } + + CComBSTR& operator=(_In_ const CComBSTR& src) + { + if (m_str != src.m_str) + { + ::SysFreeString(m_str); + m_str = src.Copy(); + if (!!src && !*this) + { + AtlThrow(E_OUTOFMEMORY); + } + } + return *this; + } + + CComBSTR& operator=(_In_opt_z_ LPCOLESTR pSrc) + { + if (pSrc != m_str) + { + ::SysFreeString(m_str); + if (pSrc != NULL) + { + m_str = ::SysAllocString(pSrc); + if (!*this) + { + AtlThrow(E_OUTOFMEMORY); + } + } + else + { + m_str = NULL; + } + } + return *this; + } +#if !defined(__MINGW32__) + CComBSTR(_Inout_ CComBSTR&& src) + { + m_str = src.m_str; + src.m_str = NULL; + } + + CComBSTR& operator=(_Inout_ CComBSTR&& src) + { + if (m_str != src.m_str) + { + ::SysFreeString(m_str); + m_str = src.m_str; + src.m_str = NULL; + } + return *this; + } +#endif + + ~CComBSTR() throw(); + + unsigned int Length() const throw() + { + return ::SysStringLen(m_str); + } + + unsigned int ByteLength() const throw() + { + return ::SysStringByteLen(m_str); + } + + operator BSTR() const throw() + { + return m_str; + } + + +#ifndef ATL_CCOMBSTR_ADDRESS_OF_ASSERT +// Temp disable CComBSTR::operator& Assert +#define ATL_NO_CCOMBSTR_ADDRESS_OF_ASSERT +#endif + + + BSTR* operator&() throw() + { +#ifndef ATL_NO_CCOMBSTR_ADDRESS_OF_ASSERT + ATLASSERT(!*this); +#endif + return &m_str; + } + + _Ret_opt_z_ BSTR Copy() const throw() + { + if (!*this) + { + return NULL; + } + else if (m_str != NULL) + { + return ::SysAllocStringByteLen((char*)m_str, ::SysStringByteLen(m_str)); + } + else + { + return ::SysAllocStringByteLen(NULL, 0); + } + } + + _Check_return_ HRESULT CopyTo(_Deref_out_opt_z_ BSTR* pbstr) const throw() + { + ATLASSERT(pbstr != NULL); + if (pbstr == NULL) + { + return E_POINTER; + } + *pbstr = Copy(); + + if ((*pbstr == NULL) && (m_str != NULL)) + { + return E_OUTOFMEMORY; + } + return S_OK; + } + + // copy BSTR to VARIANT + _Check_return_ HRESULT CopyTo(_Out_ VARIANT *pvarDest) const throw() + { + ATLASSERT(pvarDest != NULL); + HRESULT hRes = E_POINTER; + if (pvarDest != NULL) + { + pvarDest->vt = VT_BSTR; + pvarDest->bstrVal = Copy(); + + if (pvarDest->bstrVal == NULL && m_str != NULL) + { + hRes = E_OUTOFMEMORY; + } + else + { + hRes = S_OK; + } + } + return hRes; + } + + void Attach(_In_opt_z_ BSTR src) throw() + { + if (m_str != src) + { + ::SysFreeString(m_str); + m_str = src; + } + } + + _Ret_opt_z_ BSTR Detach() throw() + { + BSTR s = m_str; + m_str = NULL; + return s; + } + + void Empty() throw() + { + ::SysFreeString(m_str); + m_str = NULL; + } + + bool operator!() const throw() + { + return (m_str == NULL); + } + + _Check_return_ HRESULT Append(_In_ const CComBSTR& bstrSrc) throw() + { + return AppendBSTR(bstrSrc.m_str); + } + +/* _Check_return_ HRESULT Append(_In_z_ LPCOLESTR lpsz) throw() + { + return Append(lpsz, UINT(wcslen(lpsz))); + } +*/ + // a BSTR is just a LPCOLESTR so we need a special version to signify + // that we are appending a BSTR + _Check_return_ HRESULT AppendBSTR(_In_opt_z_ BSTR p) throw() + { + if (::SysStringLen(p) == 0) + { + return S_OK; + } + BSTR bstrNew = NULL; + HRESULT hr; + __analysis_assume(p); + hr = VarBstrCat(m_str, p, &bstrNew); + if (SUCCEEDED(hr)) + { + ::SysFreeString(m_str); + m_str = bstrNew; + } + return hr; + } + +/* _Check_return_ HRESULT Append(_In_opt_count_(nLen) LPCOLESTR lpsz, _In_ int nLen) throw() + { + if (lpsz == NULL || (m_str != NULL && nLen == 0)) + { + return S_OK; + } + else if (nLen < 0) + { + return E_INVALIDARG; + } + + const unsigned int n1 = Length(); + unsigned int n1Bytes = 0; + unsigned int nSize = 0; + unsigned int nSizeBytes = 0; + + HRESULT hr = AtlAdd(&nSize, n1, nLen); + if (FAILED(hr)) + { + return hr; + } + + hr = AtlMultiply(&nSizeBytes, nSize, sizeof(OLECHAR)); + if (FAILED(hr)) + { + return hr; + } + + hr = AtlMultiply(&n1Bytes, n1, sizeof(OLECHAR)); + if (FAILED(hr)) + { + return hr; + } + + BSTR b = ::SysAllocStringLen(NULL, nSize); + if (b == NULL) + { + return E_OUTOFMEMORY; + } + + if(::SysStringLen(m_str) > 0) + { + __analysis_assume(m_str); // ::SysStringLen(m_str) guarantees that m_str != NULL + Checked::memcpy_s(b, nSizeBytes, m_str, n1Bytes); + } + + Checked::memcpy_s(b+n1, nLen*sizeof(OLECHAR), lpsz, nLen*sizeof(OLECHAR)); + b[nSize] = '\0'; + SysFreeString(m_str); + m_str = b; + return S_OK; + } + + _Check_return_ HRESULT Append(_In_ char ch) throw() + { + OLECHAR chO = ch; + + return( Append( &chO, 1 ) ); + } + + _Check_return_ HRESULT Append(_In_ wchar_t ch) throw() + { + return( Append( &ch, 1 ) ); + } + + _Check_return_ HRESULT AppendBytes( + _In_opt_count_(nLen) const char* lpsz, + _In_ int nLen) throw() + { + if (lpsz == NULL || nLen == 0) + { + return S_OK; + } + else if (nLen < 0) + { + return E_INVALIDARG; + } + + const unsigned int n1 = ByteLength(); + unsigned int nSize = 0; + HRESULT hr = AtlAdd(&nSize, n1, nLen); + if (FAILED(hr)) + { + return hr; + } + + BSTR b = ::SysAllocStringByteLen(NULL, nSize); + if (b == NULL) + { + return E_OUTOFMEMORY; + } + + Checked::memcpy_s(b, nSize, m_str, n1); + Checked::memcpy_s(((char*)b) + n1, nLen, lpsz, nLen); + + *((OLECHAR*)(((char*)b) + nSize)) = '\0'; + SysFreeString(m_str); + m_str = b; + return S_OK; + } +*/ + _Check_return_ HRESULT AssignBSTR(_In_opt_z_ const BSTR bstrSrc) throw() + { + HRESULT hr = S_OK; + if (m_str != bstrSrc) + { + ::SysFreeString(m_str); + if (bstrSrc != NULL) + { + m_str = ::SysAllocStringByteLen((char*)bstrSrc, ::SysStringByteLen(bstrSrc)); + if (!*this) + { + hr = E_OUTOFMEMORY; + } + } + else + { + m_str = NULL; + } + } + + return hr; + } + + _Check_return_ HRESULT ToLower() throw() + { + if (::SysStringLen(m_str) > 0) + { +#ifdef _UNICODE + // Convert in place + CharLowerBuff(m_str, Length()); +#else + // Cannot use conversion macros due to possible embedded NULLs + UINT _acp = _AtlGetConversionACP(); + int _convert = WideCharToMultiByte(_acp, 0, m_str, Length(), NULL, 0, NULL, NULL); + CTempBuffer pszA; + ATLTRY(pszA.Allocate(_convert)); + if (pszA == NULL) + return E_OUTOFMEMORY; + + int nRet = WideCharToMultiByte(_acp, 0, m_str, Length(), pszA, _convert, NULL, NULL); + if (nRet == 0) + { + ATLASSERT(0); + return AtlHresultFromLastError(); + } + + CharLowerBuff(pszA, nRet); + + _convert = MultiByteToWideChar(_acp, 0, pszA, nRet, NULL, 0); + + CTempBuffer pszW; + ATLTRY(pszW.Allocate(_convert)); + if (pszW == NULL) + return E_OUTOFMEMORY; + + nRet = MultiByteToWideChar(_acp, 0, pszA, nRet, pszW, _convert); + if (nRet <= 0) + { + ATLASSERT(0); + return AtlHresultFromLastError(); + } + + UINT nBytes=0; + HRESULT hr=S_OK; + if( FAILED(hr=::ATL::AtlMultiply(&nBytes, static_cast(nRet), static_cast(sizeof(OLECHAR))))) + { + return hr; + } + BSTR b = ::SysAllocStringByteLen((LPCSTR) (LPWSTR) pszW, nBytes); + if (b == NULL) + return E_OUTOFMEMORY; + SysFreeString(m_str); + m_str = b; +#endif + } + return S_OK; + } + _Check_return_ HRESULT ToUpper() throw() + { + if (::SysStringLen(m_str) > 0) + { +#ifdef _UNICODE + // Convert in place + CharUpperBuff(m_str, Length()); +#else + // Cannot use conversion macros due to possible embedded NULLs + UINT _acp = _AtlGetConversionACP(); + int _convert = WideCharToMultiByte(_acp, 0, m_str, Length(), NULL, 0, NULL, NULL); + CTempBuffer pszA; + ATLTRY(pszA.Allocate(_convert)); + if (pszA == NULL) + return E_OUTOFMEMORY; + + int nRet = WideCharToMultiByte(_acp, 0, m_str, Length(), pszA, _convert, NULL, NULL); + if (nRet == 0) + { + ATLASSERT(0); + return AtlHresultFromLastError(); + } + + CharUpperBuff(pszA, nRet); + + _convert = MultiByteToWideChar(_acp, 0, pszA, nRet, NULL, 0); + + CTempBuffer pszW; + ATLTRY(pszW.Allocate(_convert)); + if (pszW == NULL) + return E_OUTOFMEMORY; + + nRet = MultiByteToWideChar(_acp, 0, pszA, nRet, pszW, _convert); + if (nRet <= 0) + { + ATLASSERT(0); + return AtlHresultFromLastError(); + } + + UINT nBytes=0; + HRESULT hr=S_OK; + if( FAILED(hr=::ATL::AtlMultiply(&nBytes, static_cast(nRet), static_cast(sizeof(OLECHAR))))) + { + return hr; + } + BSTR b = ::SysAllocStringByteLen((LPCSTR) (LPWSTR) pszW, nBytes); + if (b == NULL) + return E_OUTOFMEMORY; + SysFreeString(m_str); + m_str = b; +#endif + } + return S_OK; + } + + bool LoadString( + _In_ HINSTANCE hInst, + _In_ UINT nID) throw() + { + ::SysFreeString(m_str); + m_str = NULL; + return LoadStringResource(hInst, nID, m_str); + } + + bool LoadString(_In_ UINT nID) throw() + { + ::SysFreeString(m_str); + m_str = NULL; + return LoadStringResource(nID, m_str); + } + + CComBSTR& operator+=(_In_ const CComBSTR& bstrSrc) + { + HRESULT hr; + hr = AppendBSTR(bstrSrc.m_str); + if (FAILED(hr)) + AtlThrow(hr); + return *this; + } + + CComBSTR& operator+=(_In_z_ LPCOLESTR pszSrc) + { + HRESULT hr; + hr = Append(pszSrc); + if (FAILED(hr)) + AtlThrow(hr); + return *this; + } + + bool operator<(_In_ const CComBSTR& bstrSrc) const throw() + { + return VarBstrCmp(m_str, bstrSrc.m_str, LOCALE_USER_DEFAULT, 0) == static_cast(VARCMP_LT); + } + bool operator<(_In_z_ LPCOLESTR pszSrc) const + { + CComBSTR bstr2(pszSrc); + return operator<(bstr2); + } + bool operator<(_In_z_ LPOLESTR pszSrc) const + { + return operator<((LPCOLESTR)pszSrc); + } + + bool operator>(_In_ const CComBSTR& bstrSrc) const throw() + { + return VarBstrCmp(m_str, bstrSrc.m_str, LOCALE_USER_DEFAULT, 0) == static_cast(VARCMP_GT); + } + bool operator>(_In_z_ LPCOLESTR pszSrc) const + { + CComBSTR bstr2(pszSrc); + return operator>(bstr2); + } + bool operator>(_In_z_ LPOLESTR pszSrc) const + { + return operator>((LPCOLESTR)pszSrc); + } + + bool operator!=(_In_ const CComBSTR& bstrSrc) const throw() + { + return !operator==(bstrSrc); + } + bool operator!=(_In_z_ LPCOLESTR pszSrc) const + { + return !operator==(pszSrc); + } + bool operator!=(_In_ int nNull) const throw() + { + return !operator==(nNull); + } + bool operator!=(_In_z_ LPOLESTR pszSrc) const + { + return operator!=((LPCOLESTR)pszSrc); + } + bool operator==(_In_ const CComBSTR& bstrSrc) const throw() + { + return VarBstrCmp(m_str, bstrSrc.m_str, LOCALE_USER_DEFAULT, 0) == static_cast(VARCMP_EQ); + } + bool operator==(LPCOLESTR pszSrc) const + { + CComBSTR bstr2(pszSrc); + return operator==(bstr2); + } + bool operator==(_In_z_ LPOLESTR pszSrc) const + { + return operator==((LPCOLESTR)pszSrc); + } + + bool operator==(_In_ int nNull) const throw() + { + ATLASSERT(nNull == 0); + (void)nNull; + return (!*this); + } + +#if defined(_NATIVE_NULLPTR_SUPPORTED) && !defined(_DO_NOT_USE_NULLPTR_IN_ATL) + #ifdef _M_CEE + CComBSTR(decltype(__nullptr)) + { + m_str = NULL; + } + bool operator==(decltype(__nullptr)) const throw() + { + return *this == 0; + } + bool operator!=(decltype(__nullptr)) const throw() + { + return *this != 0; + } + #else // _M_CEE + CComBSTR(decltype(nullptr)) + { + m_str = NULL; + } + bool operator==(decltype(nullptr)) const throw() + { + return *this == 0; + } + bool operator!=(decltype(nullptr)) const throw() + { + return *this != 0; + } + #endif // _M_CEE +#endif // defined(_NATIVE_NULLPTR_SUPPORTED) && !defined(_DO_NOT_USE_NULLPTR_IN_ATL) + + CComBSTR(_In_opt_z_ LPCSTR pSrc) + { + if (pSrc != NULL) + { + m_str = A2WBSTR(pSrc); + if (!*this) + { + AtlThrow(E_OUTOFMEMORY); + } + } + else + { + m_str = NULL; + } + } + + CComBSTR(_In_ int nSize, _In_opt_count_(nSize) LPCSTR sz) + { + if (nSize < 0) + { + AtlThrow(E_INVALIDARG); + } + + if (nSize != 0 && sz == NULL) + { + m_str = ::SysAllocStringLen(NULL, nSize); + if (!*this) + { + AtlThrow(E_OUTOFMEMORY); + } + return; + } + + m_str = A2WBSTR(sz, nSize); + if (!*this && nSize != 0) + { + AtlThrow(E_OUTOFMEMORY); + } + } + + _Check_return_ HRESULT Append(_In_opt_z_ LPCSTR lpsz) throw() + { + if (lpsz == NULL) + return S_OK; + + CComBSTR bstrTemp; + ATLTRY(bstrTemp = lpsz); + if (!bstrTemp) + { + return E_OUTOFMEMORY; + } + return Append(bstrTemp); + } + + CComBSTR& operator=(_In_opt_z_ LPCSTR pSrc) + { + ::SysFreeString(m_str); + m_str = A2WBSTR(pSrc); + if (!*this && pSrc != NULL) + { + AtlThrow(E_OUTOFMEMORY); + } + return *this; + } + + bool operator<(_In_opt_z_ LPCSTR pszSrc) const + { + CComBSTR bstr2(pszSrc); + return operator<(bstr2); + } + bool operator>(_In_opt_z_ LPCSTR pszSrc) const + { + CComBSTR bstr2(pszSrc); + return operator>(bstr2); + } + bool operator!=(_In_opt_z_ LPCSTR pszSrc) const + { + return !operator==(pszSrc); + } + bool operator==(_In_opt_z_ LPCSTR pszSrc) const + { + CComBSTR bstr2(pszSrc); + return operator==(bstr2); + } + + _Check_return_ HRESULT WriteToStream(_Inout_ IStream* pStream) throw() + { + ATLASSERT(pStream != NULL); + if(pStream == NULL) + { + return E_INVALIDARG; + } + + ULONG cb; + ULONG cbStrLen = CComBSTR::GetStreamSize(m_str); + ATLASSERT(cbStrLen >= sizeof(ULONG)); + cbStrLen -= sizeof(ULONG); + + HRESULT hr = pStream->Write((void*) &cbStrLen, sizeof(cbStrLen), &cb); + if (FAILED(hr)) + { + return hr; + } + + if (cbStrLen == 0) + { + return S_OK; + } + return pStream->Write((void*) m_str, cbStrLen, &cb); + } + + _Check_return_ HRESULT ReadFromStream(_Inout_ IStream* pStream) throw() + { + ATLASSERT(pStream != NULL); + if(pStream == NULL) + { + return E_INVALIDARG; + } + + ATLASSERT(!*this); // should be empty + Empty(); + + HRESULT hrSeek; + ULARGE_INTEGER nBegOffset; + { + LARGE_INTEGER nZeroOffset; + nZeroOffset.QuadPart = 0L; + hrSeek = pStream->Seek(nZeroOffset, STREAM_SEEK_CUR, &nBegOffset); + } + + ULONG cbRead = 0; + ULONG cbStrLen = 0; + HRESULT hr = pStream->Read(reinterpret_cast(&cbStrLen), sizeof(cbStrLen), &cbRead); + + if (SUCCEEDED(hr)) + { + // invalid data size + if (sizeof(cbStrLen) != cbRead) + { + hr = E_FAIL; + } + // read NULL string + else if (cbStrLen == 0) + { + } + // invalid data length + else if (cbStrLen < sizeof(OLECHAR)) + { + hr = E_FAIL; + } + // security checks when system hang for huge stream of data + else if (cbStrLen > _ATL_STREAM_MAX_SIZE) + { + hr = E_ACCESSDENIED; + } + else + { + //subtract size for terminating NULL which we wrote out + cbStrLen -= sizeof(OLECHAR); + + m_str = ::SysAllocStringByteLen(NULL, cbStrLen); + if (!*this) + { + hr = E_OUTOFMEMORY; + } + else + { + hr = pStream->Read(reinterpret_cast(m_str), cbStrLen, &cbRead); + + if (SUCCEEDED(hr)) + { + if (cbRead != cbStrLen) + { + hr = E_FAIL; + } + else + { + OLECHAR ch; + hr = pStream->Read(reinterpret_cast(&ch), sizeof(OLECHAR), &cbRead); + + if (SUCCEEDED(hr)) + { +#ifndef _ATL_CCOMBSTR_READFROMSTREAM_INSECURE + if (cbRead != sizeof(OLECHAR) || ch != L'\0') +#else + if (cbRead != sizeof(OLECHAR)) +#endif + { + hr = E_FAIL; + } + } + } + } + + if (FAILED(hr)) + { + ::SysFreeString(m_str); + m_str = NULL; + } + } + } + } + + // If SysAllocStringByteLen or IStream::Read failed, reset seek + // pointer to start of BSTR size. + if (FAILED(hr) && SUCCEEDED(hrSeek)) + { + LARGE_INTEGER nOffset; + nOffset.QuadPart = static_cast(nBegOffset.QuadPart); + pStream->Seek(nOffset, STREAM_SEEK_SET, NULL); + } + + return hr; + } + + static bool LoadStringResource( + _In_ HINSTANCE hInstance, + _In_ UINT uID, + _Deref_out_opt_z_ BSTR& bstrText) throw() + { +ATLPREFAST_SUPPRESS(6001) // Using uninitialized memory + ATLASSERT(bstrText == NULL); +ATLPREFAST_UNSUPPRESS() + + const ATLSTRINGRESOURCEIMAGE* pImage = AtlGetStringResourceImage(hInstance, uID); + if (pImage != NULL) + { + bstrText = ::SysAllocStringLen(pImage->achString, pImage->nLength); + } + else + { + bstrText = NULL; + } + return (bstrText != NULL) ? true : false; + } + + static bool LoadStringResource( + _In_ UINT uID, + _Deref_out_opt_z_ BSTR& bstrText) throw() + { +ATLPREFAST_SUPPRESS(6001) // Using uninitialized memory + ATLASSERT(bstrText == NULL); +ATLPREFAST_UNSUPPRESS() + + const ATLSTRINGRESOURCEIMAGE* pImage = AtlGetStringResourceImage(uID); + if (pImage != NULL) + { + bstrText = ::SysAllocStringLen(pImage->achString, pImage->nLength); + } + else + { + bstrText = NULL; + } + + return (bstrText != NULL) ? true : false; + } + + // each character in BSTR is copied to each element in SAFEARRAY + HRESULT BSTRToArray(_Deref_out_ LPSAFEARRAY *ppArray) throw() + { + return VectorFromBstr(m_str, ppArray); + } + + // first character of each element in SAFEARRAY is copied to BSTR + _Check_return_ HRESULT ArrayToBSTR(_In_ const SAFEARRAY *pSrc) throw() + { + ::SysFreeString(m_str); + return BstrFromVector((LPSAFEARRAY)pSrc, &m_str); + } + static ULONG GetStreamSize(_In_opt_z_ BSTR bstr) + { + ULONG ulSize = sizeof(ULONG); + if (bstr != NULL) + { + ulSize += SysStringByteLen(bstr) + sizeof(OLECHAR); + } + + return ulSize; + } +}; + +inline CComBSTR::~CComBSTR() throw() + { + ::SysFreeString(m_str); + } + +inline void SysFreeStringHelper(_In_ CComBSTR& bstr) +{ + bstr.Empty(); +} + +inline void SysFreeStringHelper(_In_opt_z_ BSTR bstr) +{ + ::SysFreeString(bstr); +} + +_Check_return_ inline HRESULT SysAllocStringHelper( + _Out_ CComBSTR& bstrDest, + _In_opt_z_ BSTR bstrSrc) +{ + bstrDest=bstrSrc; + return !bstrDest ? E_OUTOFMEMORY : S_OK; +} + +_Check_return_ inline HRESULT SysAllocStringHelper( + _Out_ BSTR& bstrDest, + _In_opt_z_ BSTR bstrSrc) +{ + bstrDest=::SysAllocString(bstrSrc); + + return bstrDest==NULL ? E_OUTOFMEMORY : S_OK; +} + +///////////////////////////////////////////////////////////// +// Class to Adapt CComBSTR and CComPtr for use with STL containers +// the syntax to use it is +// std::vector< CAdapt > vect; + +template +class CAdapt +{ +public: + CAdapt() + { + } + CAdapt(_In_ const T& rSrc) : + m_T( rSrc ) + { + } + CAdapt(_In_ const CAdapt& rSrCA) : + m_T( rSrCA.m_T ) + { + } + CAdapt& operator=(_In_ const T& rSrc) + { + m_T = rSrc; + + return *this; + } + CAdapt& operator=(_In_ const CAdapt& rSrc) + { + if (this != &rSrc) + { + m_T = rSrc.m_T; + } + return *this; + } +#if !defined(__MINGW32__) + CAdapt(_Inout_ T&& rSrc) : + m_T( static_cast(rSrc) ) + { + } + CAdapt(_Inout_ CAdapt&& rSrCA) : + m_T( static_cast(rSrCA.m_T) ) + { + } + CAdapt& operator=(_Inout_ T&& rSrc) + { + m_T = static_cast(rSrc); + + return *this; + } + CAdapt& operator=(_Inout_ CAdapt&& rSrc) + { + if (this != &rSrc) + { + m_T = static_cast( rSrc.m_T ); + } + return *this; + } +#endif + bool operator<(_In_ const T& rSrc) const + { + return m_T < rSrc; + } + bool operator==(_In_ const T& rSrc) const + { + return m_T == rSrc; + } + operator T&() + { + return m_T; + } + + operator const T&() const + { + return m_T; + } + + T& operator->() + { + return m_T; + } + + const T& operator->() const + { + return m_T; + } + + T m_T; +}; + +///////////////////////////////////////////////////////////////////////////// +// CComVariant + + +#define ATL_VARIANT_TRUE VARIANT_BOOL( -1 ) +#define ATL_VARIANT_FALSE VARIANT_BOOL( 0 ) + +template< typename T > +class _CVarTypeInfo +{ +// static const VARTYPE VT; // VARTYPE corresponding to type T +// static T VARIANT::* const pmField; // Pointer-to-member of corresponding field in VARIANT struct +}; + +template< typename T > +class CVarTypeInfo : public _CVarTypeInfo +{ +#if defined(_CHAR_UNSIGNED) && !defined(_ATL_ALLOW_CHAR_UNSIGNED) + ATLSTATIC_ASSERT(!(_CVarTypeInfo::VT == static_cast(VT_I1) || _CVarTypeInfo::VT == (VT_I1|VT_BYREF)), + "CVarTypeInfo< char > or CVarTypeInfo< char* > cannot be compiled with /J or _CHAR_UNSIGNED flag enabled"); +#endif +}; + +template<> +class _CVarTypeInfo< char > +{ +public: + static const VARTYPE VT = VT_I1; + static char VARIANT::* const pmField; +}; + +__declspec( selectany ) char VARIANT::* const _CVarTypeInfo< char >::pmField = &VARIANT::cVal; + +template<> +class _CVarTypeInfo< unsigned char > +{ +public: + static const VARTYPE VT = VT_UI1; + static unsigned char VARIANT::* const pmField; +}; + +__declspec( selectany ) unsigned char VARIANT::* const _CVarTypeInfo< unsigned char >::pmField = &VARIANT::bVal; + +template<> +class _CVarTypeInfo< char* > +{ +public: + static const VARTYPE VT = VT_I1|VT_BYREF; + static char* VARIANT::* const pmField; +}; + +__declspec( selectany ) char* VARIANT::* const _CVarTypeInfo< char* >::pmField = &VARIANT::pcVal; + +template<> +class _CVarTypeInfo< unsigned char* > +{ +public: + static const VARTYPE VT = VT_UI1|VT_BYREF; + static unsigned char* VARIANT::* const pmField; +}; + +__declspec( selectany ) unsigned char* VARIANT::* const _CVarTypeInfo< unsigned char* >::pmField = &VARIANT::pbVal; + +template<> +class _CVarTypeInfo< short > +{ +public: + static const VARTYPE VT = VT_I2; + static short VARIANT::* const pmField; +}; + +__declspec( selectany ) short VARIANT::* const _CVarTypeInfo< short >::pmField = &VARIANT::iVal; + +template<> +class _CVarTypeInfo< short* > +{ +public: + static const VARTYPE VT = VT_I2|VT_BYREF; + static short* VARIANT::* const pmField; +}; + +__declspec( selectany ) short* VARIANT::* const _CVarTypeInfo< short* >::pmField = &VARIANT::piVal; + +template<> +class _CVarTypeInfo< unsigned short > +{ +public: + static const VARTYPE VT = VT_UI2; + static unsigned short VARIANT::* const pmField; +}; + +__declspec( selectany ) unsigned short VARIANT::* const _CVarTypeInfo< unsigned short >::pmField = &VARIANT::uiVal; + +#ifdef _NATIVE_WCHAR_T_DEFINED // Only treat unsigned short* as VT_UI2|VT_BYREF if BSTR isn't the same as unsigned short* +template<> +class _CVarTypeInfo< unsigned short* > +{ +public: + static const VARTYPE VT = VT_UI2|VT_BYREF; + static unsigned short* VARIANT::* const pmField; +}; + +__declspec( selectany ) unsigned short* VARIANT::* const _CVarTypeInfo< unsigned short* >::pmField = &VARIANT::puiVal; +#endif // _NATIVE_WCHAR_T_DEFINED + +template<> +class _CVarTypeInfo< int > +{ +public: + static const VARTYPE VT = VT_I4; + static int VARIANT::* const pmField; +}; + +__declspec( selectany ) int VARIANT::* const _CVarTypeInfo< int >::pmField = &VARIANT::intVal; + +template<> +class _CVarTypeInfo< int* > +{ +public: + static const VARTYPE VT = VT_I4|VT_BYREF; + static int* VARIANT::* const pmField; +}; + +__declspec( selectany ) int* VARIANT::* const _CVarTypeInfo< int* >::pmField = &VARIANT::pintVal; + +template<> +class _CVarTypeInfo< unsigned int > +{ +public: + static const VARTYPE VT = VT_UI4; + static unsigned int VARIANT::* const pmField; +}; + +__declspec( selectany ) unsigned int VARIANT::* const _CVarTypeInfo< unsigned int >::pmField = &VARIANT::uintVal; + +template<> +class _CVarTypeInfo< unsigned int* > +{ +public: + static const VARTYPE VT = VT_UI4|VT_BYREF; + static unsigned int* VARIANT::* const pmField; +}; + +__declspec( selectany ) unsigned int* VARIANT::* const _CVarTypeInfo< unsigned int* >::pmField = &VARIANT::puintVal; + +template<> +class _CVarTypeInfo< long > +{ +public: + static const VARTYPE VT = VT_I4; + static long VARIANT::* const pmField; +}; + +__declspec( selectany ) long VARIANT::* const _CVarTypeInfo< long >::pmField = &VARIANT::lVal; + +template<> +class _CVarTypeInfo< long* > +{ +public: + static const VARTYPE VT = VT_I4|VT_BYREF; + static long* VARIANT::* const pmField; +}; + +__declspec( selectany ) long* VARIANT::* const _CVarTypeInfo< long* >::pmField = &VARIANT::plVal; + +template<> +class _CVarTypeInfo< unsigned long > +{ +public: + static const VARTYPE VT = VT_UI4; + static unsigned long VARIANT::* const pmField; +}; + +__declspec( selectany ) unsigned long VARIANT::* const _CVarTypeInfo< unsigned long >::pmField = &VARIANT::ulVal; + +template<> +class _CVarTypeInfo< unsigned long* > +{ +public: + static const VARTYPE VT = VT_UI4|VT_BYREF; + static unsigned long* VARIANT::* const pmField; +}; + +__declspec( selectany ) unsigned long* VARIANT::* const _CVarTypeInfo< unsigned long* >::pmField = &VARIANT::pulVal; + +template<> +class _CVarTypeInfo< __int64 > +{ +public: + static const VARTYPE VT = VT_I8; + static __int64 VARIANT::* const pmField; +}; + +__declspec( selectany ) __int64 VARIANT::* const _CVarTypeInfo< __int64 >::pmField = &VARIANT::llVal; + +template<> +class _CVarTypeInfo< __int64* > +{ +public: + static const VARTYPE VT = VT_I8|VT_BYREF; + static __int64* VARIANT::* const pmField; +}; + +__declspec( selectany ) __int64* VARIANT::* const _CVarTypeInfo< __int64* >::pmField = &VARIANT::pllVal; + +template<> +class _CVarTypeInfo< unsigned __int64 > +{ +public: + static const VARTYPE VT = VT_UI8; + static unsigned __int64 VARIANT::* const pmField; +}; + +__declspec( selectany ) unsigned __int64 VARIANT::* const _CVarTypeInfo< unsigned __int64 >::pmField = &VARIANT::ullVal; + +template<> +class _CVarTypeInfo< unsigned __int64* > +{ +public: + static const VARTYPE VT = VT_UI8|VT_BYREF; + static unsigned __int64* VARIANT::* const pmField; +}; + +__declspec( selectany ) unsigned __int64* VARIANT::* const _CVarTypeInfo< unsigned __int64* >::pmField = &VARIANT::pullVal; + +template<> +class _CVarTypeInfo< float > +{ +public: + static const VARTYPE VT = VT_R4; + static float VARIANT::* const pmField; +}; + +__declspec( selectany ) float VARIANT::* const _CVarTypeInfo< float >::pmField = &VARIANT::fltVal; + +template<> +class _CVarTypeInfo< float* > +{ +public: + static const VARTYPE VT = VT_R4|VT_BYREF; + static float* VARIANT::* const pmField; +}; + +__declspec( selectany ) float* VARIANT::* const _CVarTypeInfo< float* >::pmField = &VARIANT::pfltVal; + +template<> +class _CVarTypeInfo< double > +{ +public: + static const VARTYPE VT = VT_R8; + static double VARIANT::* const pmField; +}; + +__declspec( selectany ) double VARIANT::* const _CVarTypeInfo< double >::pmField = &VARIANT::dblVal; + +template<> +class _CVarTypeInfo< double* > +{ +public: + static const VARTYPE VT = VT_R8|VT_BYREF; + static double* VARIANT::* const pmField; +}; + +__declspec( selectany ) double* VARIANT::* const _CVarTypeInfo< double* >::pmField = &VARIANT::pdblVal; + +template<> + +class _CVarTypeInfo< VARIANT* > +{ +public: + static const VARTYPE VT = VT_VARIANT|VT_BYREF; +}; + +template<> +class _CVarTypeInfo< BSTR > +{ +public: + static const VARTYPE VT = VT_BSTR; + static BSTR VARIANT::* const pmField; +}; + +__declspec( selectany ) BSTR VARIANT::* const _CVarTypeInfo< BSTR >::pmField = &VARIANT::bstrVal; + +template<> +class _CVarTypeInfo< BSTR* > +{ +public: + static const VARTYPE VT = VT_BSTR|VT_BYREF; + static BSTR* VARIANT::* const pmField; +}; + +__declspec( selectany ) BSTR* VARIANT::* const _CVarTypeInfo< BSTR* >::pmField = &VARIANT::pbstrVal; + +template<> +class _CVarTypeInfo< IUnknown* > +{ +public: + static const VARTYPE VT = VT_UNKNOWN; + static IUnknown* VARIANT::* const pmField; +}; + +__declspec( selectany ) IUnknown* VARIANT::* const _CVarTypeInfo< IUnknown* >::pmField = &VARIANT::punkVal; + +template<> +class _CVarTypeInfo< IUnknown** > +{ +public: + static const VARTYPE VT = VT_UNKNOWN|VT_BYREF; + static IUnknown** VARIANT::* const pmField; +}; + +__declspec( selectany ) IUnknown** VARIANT::* const _CVarTypeInfo< IUnknown** >::pmField = &VARIANT::ppunkVal; + +template<> +class _CVarTypeInfo< IDispatch* > +{ +public: + static const VARTYPE VT = VT_DISPATCH; + static IDispatch* VARIANT::* const pmField; +}; + +__declspec( selectany ) IDispatch* VARIANT::* const _CVarTypeInfo< IDispatch* >::pmField = &VARIANT::pdispVal; + +template<> +class _CVarTypeInfo< IDispatch** > +{ +public: + static const VARTYPE VT = VT_DISPATCH|VT_BYREF; + static IDispatch** VARIANT::* const pmField; +}; + +__declspec( selectany ) IDispatch** VARIANT::* const _CVarTypeInfo< IDispatch** >::pmField = &VARIANT::ppdispVal; + +template<> +class _CVarTypeInfo< CY > +{ +public: + static const VARTYPE VT = VT_CY; + static CY VARIANT::* const pmField; +}; + +__declspec( selectany ) CY VARIANT::* const _CVarTypeInfo< CY >::pmField = &VARIANT::cyVal; + +template<> +class _CVarTypeInfo< CY* > +{ +public: + static const VARTYPE VT = VT_CY|VT_BYREF; + static CY* VARIANT::* const pmField; +}; + +__declspec( selectany ) CY* VARIANT::* const _CVarTypeInfo< CY* >::pmField = &VARIANT::pcyVal; + +#ifdef _ATL_NO_VARIANT_THROW +#define ATLVARIANT_THROW() throw() +#else +#define ATLVARIANT_THROW() +#endif + +class CComVariant : + public tagVARIANT +{ +// Constructors +public: + CComVariant() throw() + { + ::VariantInit(this); + } + ~CComVariant() throw() + { + HRESULT hr = Clear(); + ATLASSERT(SUCCEEDED(hr)); + (hr); + } + CComVariant(_In_ const VARIANT& varSrc) ATLVARIANT_THROW() + { + vt = VT_EMPTY; + InternalCopy(&varSrc); + } + CComVariant(_In_ const CComVariant& varSrc) ATLVARIANT_THROW() + { + vt = VT_EMPTY; + InternalCopy(&varSrc); + } + CComVariant(_In_z_ LPCOLESTR lpszSrc) ATLVARIANT_THROW() + { + vt = VT_EMPTY; + *this = lpszSrc; + } + CComVariant(_In_z_ LPCSTR lpszSrc) ATLVARIANT_THROW() + { + vt = VT_EMPTY; + *this = lpszSrc; + } + CComVariant(_In_ bool bSrc) throw() + { + vt = VT_BOOL; + boolVal = bSrc ? ATL_VARIANT_TRUE : ATL_VARIANT_FALSE; + } + + CComVariant(_In_ int nSrc, _In_ VARTYPE vtSrc = VT_I4) ATLVARIANT_THROW() + { + ATLASSERT(vtSrc == VT_I4 || vtSrc == VT_INT); + if (vtSrc == VT_I4 || vtSrc == VT_INT) + { + vt = vtSrc; + intVal = nSrc; + } + else + { + vt = VT_ERROR; + scode = E_INVALIDARG; +#ifndef _ATL_NO_VARIANT_THROW + AtlThrow(E_INVALIDARG); +#endif + } + } + + CComVariant(_In_ BYTE nSrc) throw() + { + vt = VT_UI1; + bVal = nSrc; + } + CComVariant(_In_ short nSrc) throw() + { + vt = VT_I2; + iVal = nSrc; + } + CComVariant(_In_ long nSrc, _In_ VARTYPE vtSrc = VT_I4) ATLVARIANT_THROW() + { + ATLASSERT(vtSrc == VT_I4 || vtSrc == VT_ERROR); + if (vtSrc == VT_I4 || vtSrc == VT_ERROR) + { + vt = vtSrc; + lVal = nSrc; + } + else + { + vt = VT_ERROR; + scode = E_INVALIDARG; +#ifndef _ATL_NO_VARIANT_THROW + AtlThrow(E_INVALIDARG); +#endif + } + } + + CComVariant(_In_ float fltSrc) throw() + { + vt = VT_R4; + fltVal = fltSrc; + } + CComVariant(_In_ double dblSrc, _In_ VARTYPE vtSrc = VT_R8) ATLVARIANT_THROW() + { + ATLASSERT(vtSrc == VT_R8 || vtSrc == VT_DATE); + if (vtSrc == VT_R8 || vtSrc == VT_DATE) + { + vt = vtSrc; + dblVal = dblSrc; + } + else + { + vt = VT_ERROR; + scode = E_INVALIDARG; +#ifndef _ATL_NO_VARIANT_THROW + AtlThrow(E_INVALIDARG); +#endif + } + } + +#if (_WIN32_WINNT >= 0x0501) || defined(_ATL_SUPPORT_VT_I8) + CComVariant(_In_ LONGLONG nSrc) throw() + { + vt = VT_I8; + llVal = nSrc; + } + CComVariant(_In_ ULONGLONG nSrc) throw() + { + vt = VT_UI8; + ullVal = nSrc; + } +#endif + CComVariant(_In_ CY cySrc) throw() + { + vt = VT_CY; + cyVal.Hi = cySrc.Hi; + cyVal.Lo = cySrc.Lo; + } + CComVariant(_In_opt_ IDispatch* pSrc) throw() + { + vt = VT_DISPATCH; + pdispVal = pSrc; + // Need to AddRef as VariantClear will Release + if (pdispVal != NULL) + pdispVal->AddRef(); + } + CComVariant(_In_opt_ IUnknown* pSrc) throw() + { + vt = VT_UNKNOWN; + punkVal = pSrc; + // Need to AddRef as VariantClear will Release + if (punkVal != NULL) + punkVal->AddRef(); + } + CComVariant(_In_ char cSrc) throw() + { + vt = VT_I1; + cVal = cSrc; + } + CComVariant(_In_ unsigned short nSrc) throw() + { + vt = VT_UI2; + uiVal = nSrc; + } + CComVariant(_In_ unsigned long nSrc) throw() + { + vt = VT_UI4; + ulVal = nSrc; + } + CComVariant(_In_ unsigned int nSrc, _In_ VARTYPE vtSrc = VT_UI4) ATLVARIANT_THROW() + { + ATLASSERT(vtSrc == VT_UI4 || vtSrc == VT_UINT); + if (vtSrc == VT_UI4 || vtSrc == VT_UINT) + { + vt = vtSrc; + uintVal= nSrc; + } + else + { + vt = VT_ERROR; + scode = E_INVALIDARG; +#ifndef _ATL_NO_VARIANT_THROW + AtlThrow(E_INVALIDARG); +#endif + } + } + CComVariant(_In_ const CComBSTR& bstrSrc) ATLVARIANT_THROW() + { + vt = VT_EMPTY; + *this = bstrSrc; + } + CComVariant(_In_ const SAFEARRAY *pSrc) ATLVARIANT_THROW() + { + ATLASSERT(pSrc != NULL); + if (pSrc == NULL) + { + vt = VT_ERROR; + scode = E_INVALIDARG; +#ifndef _ATL_NO_VARIANT_THROW + AtlThrow(E_INVALIDARG); +#endif + } + else + { + LPSAFEARRAY pCopy; + HRESULT hRes = ::SafeArrayCopy((LPSAFEARRAY)pSrc, &pCopy); + if (SUCCEEDED(hRes)) + { + ::ATL::AtlSafeArrayGetActualVartype((LPSAFEARRAY)pSrc, &vt); + vt |= VT_ARRAY; + parray = pCopy; + } + else + { + vt = VT_ERROR; + scode = hRes; +#ifndef _ATL_NO_VARIANT_THROW + if(hRes == E_OUTOFMEMORY) + { + AtlThrow(E_OUTOFMEMORY); + } + else + { + ATLENSURE_THROW(FALSE, hRes); + } +#endif + } + } + } +// Assignment Operators +public: + CComVariant& operator=(_In_ const CComVariant& varSrc) ATLVARIANT_THROW() + { + if(this!=&varSrc) + { + InternalCopy(&varSrc); + } + return *this; + } + CComVariant& operator=(_In_ const VARIANT& varSrc) ATLVARIANT_THROW() + { + if(static_cast(this)!=&varSrc) + { + InternalCopy(&varSrc); + } + return *this; + } + + CComVariant& operator=(_In_ const CComBSTR& bstrSrc) ATLVARIANT_THROW() + { + ClearThrow(); + + vt = VT_BSTR; + bstrVal = bstrSrc.Copy(); + + if (bstrVal == NULL && bstrSrc.m_str != NULL) + { + vt = VT_ERROR; + scode = E_OUTOFMEMORY; +#ifndef _ATL_NO_VARIANT_THROW + AtlThrow(E_OUTOFMEMORY); +#endif + } + + return *this; + } + + CComVariant& operator=(_In_z_ LPCOLESTR lpszSrc) ATLVARIANT_THROW() + { + ClearThrow(); + + vt = VT_BSTR; + bstrVal = ::SysAllocString(lpszSrc); + + if (bstrVal == NULL && lpszSrc != NULL) + { + vt = VT_ERROR; + scode = E_OUTOFMEMORY; +#ifndef _ATL_NO_VARIANT_THROW + AtlThrow(E_OUTOFMEMORY); +#endif + + } + return *this; + } + + CComVariant& operator=(_In_z_ LPCSTR lpszSrc) ATLVARIANT_THROW() + { + USES_CONVERSION_EX; + ClearThrow(); + + vt = VT_BSTR; + bstrVal = ::SysAllocString(A2COLE_EX(lpszSrc, _ATL_SAFE_ALLOCA_DEF_THRESHOLD)); + + if (bstrVal == NULL && lpszSrc != NULL) + { + vt = VT_ERROR; + scode = E_OUTOFMEMORY; +#ifndef _ATL_NO_VARIANT_THROW + AtlThrow(E_OUTOFMEMORY); +#endif + } + return *this; + } + + CComVariant& operator=(_In_ bool bSrc) ATLVARIANT_THROW() + { + if (vt != VT_BOOL) + { + ClearThrow(); + vt = VT_BOOL; + } + boolVal = bSrc ? ATL_VARIANT_TRUE : ATL_VARIANT_FALSE; + return *this; + } + + CComVariant& operator=(_In_ int nSrc) ATLVARIANT_THROW() + { + if (vt != VT_I4) + { + ClearThrow(); + vt = VT_I4; + } + intVal = nSrc; + + return *this; + } + + CComVariant& operator=(_In_ BYTE nSrc) ATLVARIANT_THROW() + { + if (vt != VT_UI1) + { + ClearThrow(); + vt = VT_UI1; + } + bVal = nSrc; + return *this; + } + + CComVariant& operator=(_In_ short nSrc) ATLVARIANT_THROW() + { + if (vt != VT_I2) + { + ClearThrow(); + vt = VT_I2; + } + iVal = nSrc; + return *this; + } + + CComVariant& operator=(_In_ long nSrc) ATLVARIANT_THROW() + { + if (vt != VT_I4) + { + ClearThrow(); + vt = VT_I4; + } + lVal = nSrc; + return *this; + } + + CComVariant& operator=(_In_ float fltSrc) ATLVARIANT_THROW() + { + if (vt != VT_R4) + { + ClearThrow(); + vt = VT_R4; + } + fltVal = fltSrc; + return *this; + } + + CComVariant& operator=(_In_ double dblSrc) ATLVARIANT_THROW() + { + if (vt != VT_R8) + { + ClearThrow(); + vt = VT_R8; + } + dblVal = dblSrc; + return *this; + } + + CComVariant& operator=(_In_ CY cySrc) ATLVARIANT_THROW() + { + if (vt != VT_CY) + { + ClearThrow(); + vt = VT_CY; + } + cyVal.Hi = cySrc.Hi; + cyVal.Lo = cySrc.Lo; + return *this; + } + + CComVariant& operator=(_Inout_opt_ IDispatch* pSrc) ATLVARIANT_THROW() + { + ClearThrow(); + + vt = VT_DISPATCH; + pdispVal = pSrc; + // Need to AddRef as VariantClear will Release + if (pdispVal != NULL) + pdispVal->AddRef(); + return *this; + } + + CComVariant& operator=(_Inout_opt_ IUnknown* pSrc) ATLVARIANT_THROW() + { + ClearThrow(); + + vt = VT_UNKNOWN; + punkVal = pSrc; + + // Need to AddRef as VariantClear will Release + if (punkVal != NULL) + punkVal->AddRef(); + return *this; + } + + CComVariant& operator=(_In_ char cSrc) ATLVARIANT_THROW() + { + if (vt != VT_I1) + { + ClearThrow(); + vt = VT_I1; + } + cVal = cSrc; + return *this; + } + + CComVariant& operator=(_In_ unsigned short nSrc) ATLVARIANT_THROW() + { + if (vt != VT_UI2) + { + ClearThrow(); + vt = VT_UI2; + } + uiVal = nSrc; + return *this; + } + + CComVariant& operator=(_In_ unsigned long nSrc) ATLVARIANT_THROW() + { + if (vt != VT_UI4) + { + ClearThrow(); + vt = VT_UI4; + } + ulVal = nSrc; + return *this; + } + + CComVariant& operator=(_In_ unsigned int nSrc) ATLVARIANT_THROW() + { + if (vt != VT_UI4) + { + ClearThrow(); + vt = VT_UI4; + } + uintVal= nSrc; + return *this; + } + + CComVariant& operator=(_In_ BYTE* pbSrc) ATLVARIANT_THROW() + { + if (vt != (VT_UI1|VT_BYREF)) + { + ClearThrow(); + vt = VT_UI1|VT_BYREF; + } + pbVal = pbSrc; + return *this; + } + + CComVariant& operator=(_In_ short* pnSrc) ATLVARIANT_THROW() + { + if (vt != (VT_I2|VT_BYREF)) + { + ClearThrow(); + vt = VT_I2|VT_BYREF; + } + piVal = pnSrc; + return *this; + } + +#ifdef _NATIVE_WCHAR_T_DEFINED + CComVariant& operator=(_In_ USHORT* pnSrc) ATLVARIANT_THROW() + { + if (vt != (VT_UI2|VT_BYREF)) + { + ClearThrow(); + vt = VT_UI2|VT_BYREF; + } + puiVal = pnSrc; + return *this; + } +#endif + + CComVariant& operator=(_In_ int* pnSrc) ATLVARIANT_THROW() + { + if (vt != (VT_I4|VT_BYREF)) + { + ClearThrow(); + vt = VT_I4|VT_BYREF; + } + pintVal = pnSrc; + return *this; + } + + CComVariant& operator=(_In_ UINT* pnSrc) ATLVARIANT_THROW() + { + if (vt != (VT_UI4|VT_BYREF)) + { + ClearThrow(); + vt = VT_UI4|VT_BYREF; + } + puintVal = pnSrc; + return *this; + } + + CComVariant& operator=(_In_ long* pnSrc) ATLVARIANT_THROW() + { + if (vt != (VT_I4|VT_BYREF)) + { + ClearThrow(); + vt = VT_I4|VT_BYREF; + } + plVal = pnSrc; + return *this; + } + + CComVariant& operator=(_In_ ULONG* pnSrc) ATLVARIANT_THROW() + { + if (vt != (VT_UI4|VT_BYREF)) + { + ClearThrow(); + vt = VT_UI4|VT_BYREF; + } + pulVal = pnSrc; + return *this; + } + +#if (_WIN32_WINNT >= 0x0501) || defined(_ATL_SUPPORT_VT_I8) + CComVariant& operator=(_In_ LONGLONG nSrc) ATLVARIANT_THROW() + { + if (vt != VT_I8) + { + ClearThrow(); + vt = VT_I8; + } + llVal = nSrc; + + return *this; + } + + CComVariant& operator=(_In_ LONGLONG* pnSrc) ATLVARIANT_THROW() + { + if (vt != (VT_I8|VT_BYREF)) + { + ClearThrow(); + vt = VT_I8|VT_BYREF; + } + pllVal = pnSrc; + return *this; + } + + CComVariant& operator=(_In_ ULONGLONG nSrc) ATLVARIANT_THROW() + { + if (vt != VT_UI8) + { + ClearThrow(); + vt = VT_UI8; + } + ullVal = nSrc; + + return *this; + } + + CComVariant& operator=(_In_ ULONGLONG* pnSrc) ATLVARIANT_THROW() + { + if (vt != (VT_UI8|VT_BYREF)) + { + ClearThrow(); + vt = VT_UI8|VT_BYREF; + } + pullVal = pnSrc; + return *this; + } +#endif + + CComVariant& operator=(_In_ float* pfSrc) ATLVARIANT_THROW() + { + if (vt != (VT_R4|VT_BYREF)) + { + ClearThrow(); + vt = VT_R4|VT_BYREF; + } + pfltVal = pfSrc; + return *this; + } + + CComVariant& operator=(_In_ double* pfSrc) ATLVARIANT_THROW() + { + if (vt != (VT_R8|VT_BYREF)) + { + ClearThrow(); + vt = VT_R8|VT_BYREF; + } + pdblVal = pfSrc; + return *this; + } + + CComVariant& operator=(_In_ const SAFEARRAY *pSrc) ATLVARIANT_THROW() + { + ATLASSERT(pSrc != NULL); + ClearThrow(); + + if (pSrc == NULL) + { + vt = VT_ERROR; + scode = E_INVALIDARG; +#ifndef _ATL_NO_VARIANT_THROW + AtlThrow(E_INVALIDARG); +#endif + } + else + { + LPSAFEARRAY pCopy; + HRESULT hr = ::SafeArrayCopy((LPSAFEARRAY)pSrc, &pCopy); + if (SUCCEEDED(hr)) + { + ::ATL::AtlSafeArrayGetActualVartype((LPSAFEARRAY)pSrc, &vt); + vt |= VT_ARRAY; + parray = pCopy; + } + else + { + vt = VT_ERROR; + scode = hr; +#ifndef _ATL_NO_VARIANT_THROW + if(hr == E_OUTOFMEMORY) + { + AtlThrow(E_OUTOFMEMORY); + } + else + { + ATLENSURE_THROW(FALSE, hr); + } +#endif + } + } + + return *this; + } + +// Comparison Operators +public: + bool operator==(_In_ const VARIANT& varSrc) const throw() + { + // For backwards compatibility + if (vt == VT_NULL && varSrc.vt == VT_NULL) + { + return true; + } + // Variants not equal if types don't match + if (vt != varSrc.vt) + { + return false; + } + return VarCmp((VARIANT*)this, (VARIANT*)&varSrc, LOCALE_USER_DEFAULT, 0) == static_cast(VARCMP_EQ); + } + + bool operator!=(_In_ const VARIANT& varSrc) const throw() + { + return !operator==(varSrc); + } + + bool operator<(_In_ const VARIANT& varSrc) const throw() + { + if (vt == VT_NULL && varSrc.vt == VT_NULL) + return false; + return VarCmp((VARIANT*)this, (VARIANT*)&varSrc, LOCALE_USER_DEFAULT, 0)== static_cast(VARCMP_LT); + } + + bool operator>(_In_ const VARIANT& varSrc) const throw() + { + if (vt == VT_NULL && varSrc.vt == VT_NULL) + return false; + return VarCmp((VARIANT*)this, (VARIANT*)&varSrc, LOCALE_USER_DEFAULT, 0)== static_cast(VARCMP_GT); + } + +private: + inline HRESULT VarCmp( + _In_ LPVARIANT pvarLeft, + _In_ LPVARIANT pvarRight, + _In_ LCID lcid, + _In_ ULONG dwFlags) const throw(); + +// Operations +public: + HRESULT Clear() + { + return ::VariantClear(this); + } + HRESULT Copy(_In_ const VARIANT* pSrc) + { + return ::VariantCopy(this, const_cast(pSrc)); + } + +ATLPREFAST_SUPPRESS(6387) + // copy VARIANT to BSTR + HRESULT CopyTo(_Deref_out_z_ BSTR *pstrDest) const + { + ATLASSERT(pstrDest != NULL && vt == VT_BSTR); + HRESULT hRes = E_POINTER; + if (pstrDest != NULL && vt == VT_BSTR) + { + *pstrDest = ::SysAllocStringByteLen((char*)bstrVal, ::SysStringByteLen(bstrVal)); + if (*pstrDest == NULL) + hRes = E_OUTOFMEMORY; + else + hRes = S_OK; + } + else if (vt != VT_BSTR) + hRes = DISP_E_TYPEMISMATCH; + + return hRes; + } +ATLPREFAST_UNSUPPRESS() + + HRESULT Attach(_In_ VARIANT* pSrc) + { + if(pSrc == NULL) + return E_INVALIDARG; + + // Clear out the variant + HRESULT hr = Clear(); + if (SUCCEEDED(hr)) + { + // Copy the contents and give control to CComVariant + Checked::memcpy_s(this, sizeof(CComVariant), pSrc, sizeof(VARIANT)); + pSrc->vt = VT_EMPTY; + hr = S_OK; + } + return hr; + } + + HRESULT Detach(_Out_ VARIANT* pDest) + { + ATLASSERT(pDest != NULL); + if(pDest == NULL) + return E_POINTER; + + // Clear out the variant + HRESULT hr = ::VariantClear(pDest); + if (SUCCEEDED(hr)) + { + // Copy the contents and remove control from CComVariant + Checked::memcpy_s(pDest, sizeof(VARIANT), this, sizeof(VARIANT)); + vt = VT_EMPTY; + hr = S_OK; + } + return hr; + } + + HRESULT ChangeType(_In_ VARTYPE vtNew, _In_opt_ const VARIANT* pSrc = NULL) + { + VARIANT* pVar = const_cast(pSrc); + // Convert in place if pSrc is NULL + if (pVar == NULL) + pVar = this; + // Do nothing if doing in place convert and vts not different + return ::VariantChangeType(this, pVar, 0, vtNew); + } + + template< typename T > + void SetByRef(_In_ T* pT) ATLVARIANT_THROW() + { + ClearThrow(); + vt = CVarTypeInfo< T* >::VT; + byref = pT; + } + + _Check_return_ HRESULT WriteToStream(_Inout_ IStream* pStream); + _Check_return_ HRESULT WriteToStream( + _Inout_ IStream* pStream, + _In_ VARTYPE vtWrite) + { + if (vtWrite != VT_EMPTY && vtWrite != vt) + { + CComVariant varConv; + HRESULT hr = varConv.ChangeType(vtWrite, this); + if (FAILED(hr)) + { + return hr; + } + return varConv.WriteToStream(pStream); + } + return WriteToStream(pStream); + } + + _Check_return_ HRESULT ReadFromStream( + _Inout_ IStream* pStream, + _In_ VARTYPE vtExpected = VT_EMPTY); + + _Check_return_ HRESULT ReadFromStream( + _Inout_ IStream* pStream, + _In_ VARTYPE vtExpected, + // _In_ ClassesAllowedInStream rgclsidAllowed, + _In_ DWORD cclsidAllowed); + + // Return the size in bytes of the current contents + ULONG GetSize() const; + HRESULT GetSizeMax(_Out_ ULARGE_INTEGER* pcbSize) const; + +// Implementation +private: + void ClearThrow() ATLVARIANT_THROW() + { + HRESULT hr = Clear(); + ATLASSERT(SUCCEEDED(hr)); + (hr); +#ifndef _ATL_NO_VARIANT_THROW + if (FAILED(hr)) + { + AtlThrow(hr); + } +#endif + } + +public: + _Check_return_ HRESULT InternalClear() ATLVARIANT_THROW() + { + HRESULT hr = Clear(); + ATLASSERT(SUCCEEDED(hr)); + if (FAILED(hr)) + { + vt = VT_ERROR; + scode = hr; +#ifndef _ATL_NO_VARIANT_THROW + AtlThrow(hr); +#endif + } + return hr; + } + + void InternalCopy(_In_ const VARIANT* pSrc) ATLVARIANT_THROW() + { + HRESULT hr = Copy(pSrc); + if (FAILED(hr)) + { + vt = VT_ERROR; + scode = hr; +#ifndef _ATL_NO_VARIANT_THROW + AtlThrow(hr); +#endif + } + } +}; + +#pragma warning(push) +#pragma warning(disable: 4702) +_Check_return_ inline HRESULT CComVariant::WriteToStream(_Inout_ IStream* pStream) +{ + if(pStream == NULL) + return E_INVALIDARG; + + HRESULT hr = pStream->Write(&vt, sizeof(VARTYPE), NULL); + if (FAILED(hr)) + return hr; + + int cbWrite = 0; + switch (vt) + { + case VT_UNKNOWN: + case VT_DISPATCH: + { + CComPtr spStream; + if (punkVal != NULL) + { + hr = punkVal->QueryInterface(__uuidof(IPersistStream), (void**)&spStream); + if (FAILED(hr)) + { + hr = punkVal->QueryInterface(__uuidof(IPersistStreamInit), (void**)&spStream); + if (FAILED(hr)) + return hr; + } + } + if (spStream != NULL) + return OleSaveToStream(spStream, pStream); + return WriteClassStm(pStream, CLSID_NULL); + } + case VT_UI1: + case VT_I1: + cbWrite = sizeof(BYTE); + break; + case VT_I2: + case VT_UI2: + case VT_BOOL: + cbWrite = sizeof(short); + break; + case VT_I4: + case VT_UI4: + case VT_R4: + case VT_INT: + case VT_UINT: + case VT_ERROR: + cbWrite = sizeof(long); + break; + case VT_I8: + case VT_UI8: + cbWrite = sizeof(LONGLONG); + break; + case VT_R8: + case VT_CY: + case VT_DATE: + cbWrite = sizeof(double); + break; + default: + break; + } + if (cbWrite != 0) + return pStream->Write((void*) &bVal, cbWrite, NULL); + + CComBSTR bstrWrite; + CComVariant varBSTR; + if (vt != VT_BSTR) + { + hr = VariantChangeType(&varBSTR, this, VARIANT_NOVALUEPROP, VT_BSTR); + if (FAILED(hr)) + return hr; + bstrWrite.Attach(varBSTR.bstrVal); + } + else + bstrWrite.Attach(bstrVal); + + hr = bstrWrite.WriteToStream(pStream); + bstrWrite.Detach(); + return hr; +} +#pragma warning(pop) // C4702 + + +inline HRESULT CComVariant::GetSizeMax(_Out_ ULARGE_INTEGER* pcbSize) const +{ + ATLASSERT(pcbSize != NULL); + if (pcbSize == NULL) + { + return E_INVALIDARG; + } + + HRESULT hr = S_OK; + ULARGE_INTEGER nSize; + nSize.QuadPart = sizeof(VARTYPE); + + switch (vt) + { + case VT_UNKNOWN: + case VT_DISPATCH: + { + nSize.LowPart += sizeof(CLSID); + + if (punkVal != NULL) + { + CComPtr spStream; + + hr = punkVal->QueryInterface(__uuidof(IPersistStream), (void**)&spStream); + if (FAILED(hr)) + { + hr = punkVal->QueryInterface(__uuidof(IPersistStreamInit), (void**)&spStream); + if (FAILED(hr)) + { + break; + } + } + + ULARGE_INTEGER nPersistSize; + nPersistSize.QuadPart = 0; + + ATLASSERT(spStream != NULL); + hr = spStream->GetSizeMax(&nPersistSize); + if (SUCCEEDED(hr)) + { + hr = AtlAdd(&nSize.QuadPart, nSize.QuadPart, nPersistSize.QuadPart); + } + } + } + break; + case VT_UI1: + case VT_I1: + nSize.LowPart += sizeof(BYTE); + break; + case VT_I2: + case VT_UI2: + case VT_BOOL: + nSize.LowPart += sizeof(short); + break; + case VT_I4: + case VT_UI4: + case VT_R4: + case VT_INT: + case VT_UINT: + case VT_ERROR: + nSize.LowPart += sizeof(long); + break; + case VT_I8: + case VT_UI8: + nSize.LowPart += sizeof(LONGLONG); + break; + case VT_R8: + case VT_CY: + case VT_DATE: + nSize.LowPart += sizeof(double); + break; + default: + { + VARTYPE vtTmp = vt; + BSTR bstr = NULL; + CComVariant varBSTR; + if (vtTmp != VT_BSTR) + { + hr = VariantChangeType(&varBSTR, const_cast((const VARIANT*)this), VARIANT_NOVALUEPROP, VT_BSTR); + if (SUCCEEDED(hr)) + { + bstr = varBSTR.bstrVal; + vtTmp = VT_BSTR; + } + } + else + { + bstr = bstrVal; + } + + if (vtTmp == VT_BSTR) + { + // Add the size of the length + string (in bytes) + NULL terminator. + nSize.QuadPart += CComBSTR::GetStreamSize(bstr); + } + } + } + + if (SUCCEEDED(hr)) + { + pcbSize->QuadPart = nSize.QuadPart; + } + + return hr; +} + +inline ATL_DEPRECATED("GetSize has been replaced by GetSizeMax") +ULONG CComVariant::GetSize() const +{ + ULARGE_INTEGER nSize; + HRESULT hr = GetSizeMax(&nSize); + + if (SUCCEEDED(hr) && nSize.QuadPart <= ULONG_MAX) + { + return nSize.LowPart; + } + + return sizeof(VARTYPE); +} + +_Check_return_ inline HRESULT CComPtr::Invoke2( + _In_ DISPID dispid, + _In_ VARIANT* pvarParam1, + _In_ VARIANT* pvarParam2, + _Out_opt_ VARIANT* pvarRet) throw() +{ + if(pvarParam1 == NULL || pvarParam2 == NULL) + return E_INVALIDARG; + + CComVariant varArgs[2] = { *pvarParam2, *pvarParam1 }; + DISPPARAMS dispparams = { &varArgs[0], NULL, 2, 0}; + return p->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparams, pvarRet, NULL, NULL); +} + +/* + Workaround for VarCmp function which does not compare VT_I1, VT_UI2, VT_UI4, VT_UI8 values +*/ +inline HRESULT CComVariant::VarCmp( + _In_ LPVARIANT pvarLeft, + _In_ LPVARIANT pvarRight, + _In_ LCID lcid, + _In_ ULONG dwFlags) const throw() +{ + switch(vt) + { + case VT_I1: + if (pvarLeft->cVal == pvarRight->cVal) + { + return VARCMP_EQ; + } + return pvarLeft->cVal > pvarRight->cVal ? VARCMP_GT : VARCMP_LT; + case VT_UI2: + if (pvarLeft->uiVal == pvarRight->uiVal) + { + return VARCMP_EQ; + } + return pvarLeft->uiVal > pvarRight->uiVal ? VARCMP_GT : VARCMP_LT; + + case VT_UI4: + if (pvarLeft->uintVal == pvarRight->uintVal) + { + return VARCMP_EQ; + } + return pvarLeft->uintVal > pvarRight->uintVal ? VARCMP_GT : VARCMP_LT; + + case VT_UI8: + if (pvarLeft->ullVal == pvarRight->ullVal) + { + return VARCMP_EQ; + } + return pvarLeft->ullVal > pvarRight->ullVal ? VARCMP_GT : VARCMP_LT; + + default: + return ::VarCmp(pvarLeft, pvarRight, lcid, dwFlags); + } +} + +} // namespace ATL +#pragma pack(pop) + +#pragma warning (pop) + +#ifndef _ATL_NO_AUTOMATIC_NAMESPACE +using namespace ATL; +#endif //!_ATL_NO_AUTOMATIC_NAMESPACE + +#endif // __ATLCOMCLI_H__ diff --git a/src/main/headers/atlconv.h b/src/main/headers/atlconv.h new file mode 100644 index 0000000..17a90d7 --- /dev/null +++ b/src/main/headers/atlconv.h @@ -0,0 +1,1485 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#ifndef __ATLCONV_H__ +#define __ATLCONV_H__ + +#pragma once + +#ifndef _ATL_NO_PRAGMA_WARNINGS +#pragma warning (push) +#pragma warning(disable: 4127) // unreachable code +#endif //!_ATL_NO_PRAGMA_WARNINGS + +#ifndef __cplusplus + #error ATL requires C++ compilation (use a .cpp suffix) +#endif + +#include +#include +#include + +#ifndef __wtypes_h__ + +#if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_IX86) +#define _X86_ +#endif + +#if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_AMD64) +#define _AMD64_ +#endif + +#if !defined(_X86_) && !defined(_M_IX86) && !defined(_AMD64_) && defined(_M_IA64) +#if !defined(_IA64_) +#define _IA64_ +#endif // !_IA64_ +#endif + +#include +#include +#include +#include + +#if !defined(OLE2ANSI) + +typedef WCHAR OLECHAR; +typedef OLECHAR *LPOLESTR; +typedef const OLECHAR *LPCOLESTR; +#define OLESTR(str) L##str + +#else + +typedef char OLECHAR; +typedef LPSTR LPOLESTR; +typedef LPCSTR LPCOLESTR; +#define OLESTR(str) str + +#endif // !OLE2ANSI +#endif // __wtypes_h__ + +#ifndef _OLEAUTO_H_ +typedef LPWSTR BSTR;// must (semantically) match typedef in oleauto.h + +extern "C" +{ +__declspec(dllimport) _Ret_opt_z_ BSTR __stdcall SysAllocString(_In_opt_z_ const OLECHAR *); +__declspec(dllimport) _Ret_opt_z_ BSTR __stdcall SysAllocStringLen( + _In_z_count_(nLen) const OLECHAR *, + _In_ UINT nLen); +__declspec(dllimport) INT __stdcall SysReAllocStringLen( + _Deref_out_opt_z_ BSTR*, + _In_opt_z_count_(nLen) const OLECHAR *, + _In_ UINT nLen); +__declspec(dllimport) void __stdcall SysFreeString(_In_opt_z_ BSTR); +} +#endif + +// we use our own implementation of InterlockedExchangePointer because of problems with the one in system headers +#ifdef _M_IX86 +#undef InterlockedExchangePointer +inline void* WINAPI InterlockedExchangePointer( + _Inout_ void** pp, + _In_opt_ void* pNew) throw() +{ + return( reinterpret_cast(static_cast( + ::InterlockedExchange(reinterpret_cast(pp), + static_cast(reinterpret_cast(pNew))))) ); +} +#endif + +#define ATLCONV_DEADLAND_FILL _SECURECRT_FILL_BUFFER_PATTERN + +#pragma pack(push,_ATL_PACKING) +namespace ATL +{ + +inline UINT WINAPI _AtlGetConversionACP() throw() +{ +#ifdef _CONVERSION_DONT_USE_THREAD_LOCALE + return CP_ACP; +#else + return CP_THREAD_ACP; +#endif +} + +template +inline void AtlConvAllocMemory( + _Inout_ _Deref_post_cap_(nLength) _CharType** ppBuff, + _In_ int nLength, + _Inout_cap_(nFixedBufferLength) _CharType* pszFixedBuffer, + _In_ int nFixedBufferLength) +{ + ATLENSURE_THROW(ppBuff != NULL, E_INVALIDARG); + ATLENSURE_THROW(nLength >= 0, E_INVALIDARG); + ATLENSURE_THROW(pszFixedBuffer != NULL, E_INVALIDARG); + + //if buffer malloced, try to realloc. + if (*ppBuff != pszFixedBuffer) + { + if( nLength > nFixedBufferLength ) + { + _CharType* ppReallocBuf = static_cast< _CharType* >( _recalloc(*ppBuff, nLength,sizeof( _CharType ) ) ); + if (ppReallocBuf == NULL) + { + AtlThrow( E_OUTOFMEMORY ); + } + *ppBuff = ppReallocBuf; + } else + { + nb_free(*ppBuff); + *ppBuff=pszFixedBuffer; + } + + } else //Buffer is not currently malloced. + { + if( nLength > nFixedBufferLength ) + { + *ppBuff = static_cast< _CharType* >( nb_calloc(nLength,sizeof( _CharType ) ) ); + } else + { + *ppBuff=pszFixedBuffer; + } + } + + if (*ppBuff == NULL) + { + AtlThrow( E_OUTOFMEMORY ); + } +} + +template +inline void AtlConvFreeMemory( + _Inout_ _CharType* pBuff, + _Inout_cap_(nFixedBufferLength) _CharType* pszFixedBuffer, + _In_ int nFixedBufferLength) +{ + (nFixedBufferLength); + if( pBuff != pszFixedBuffer ) + { + nb_free( pBuff ); + } +#ifdef _DEBUG + else + { + memset(pszFixedBuffer,ATLCONV_DEADLAND_FILL,nFixedBufferLength*sizeof(_CharType)); + } +#endif +} + +template< int t_nBufferLength = 128 > +class CW2WEX +{ +public: + CW2WEX(_In_z_ LPCWSTR psz) throw() : + m_psz( m_szBuffer ) + { + Init( psz ); + } + CW2WEX( + _In_z_ LPCWSTR psz, + _In_ UINT nCodePage) throw() : + m_psz( m_szBuffer ) + { + (void)nCodePage; // Code page doesn't matter + + Init( psz ); + } + ~CW2WEX() throw() + { + AtlConvFreeMemory(m_psz,m_szBuffer,t_nBufferLength); + } + + _Ret_z_ operator LPWSTR() const throw() + { + return( m_psz ); + } + +private: + void Init(_In_z_ LPCWSTR psz) throw() + { + if (psz == NULL) + { + m_psz = NULL; + return; + } + int nLength = lstrlenW( psz )+1; + AtlConvAllocMemory(&m_psz,nLength,m_szBuffer,t_nBufferLength); + ATLASSUME(m_psz != NULL); + Checked::memcpy_s( m_psz, nLength*sizeof( wchar_t ), psz, nLength*sizeof( wchar_t )); + } + +public: + LPWSTR m_psz; + wchar_t m_szBuffer[t_nBufferLength]; + +private: + CW2WEX(_In_ const CW2WEX&) throw(); + CW2WEX& operator=(_In_ const CW2WEX&) throw(); +}; +typedef CW2WEX<> CW2W; + +template< int t_nBufferLength = 128 > +class CA2AEX +{ +public: + CA2AEX(_In_z_ LPCSTR psz) throw() : + m_psz( m_szBuffer ) + { + Init( psz ); + } + CA2AEX( + _In_z_ LPCSTR psz, + _In_ UINT nCodePage) throw() : + m_psz( m_szBuffer ) + { + (void)nCodePage; // Code page doesn't matter + + Init( psz ); + } + ~CA2AEX() throw() + { + AtlConvFreeMemory(m_psz,m_szBuffer,t_nBufferLength); + } + + _Ret_z_ operator LPSTR() const throw() + { + return( m_psz ); + } + +private: + void Init(_In_z_ LPCSTR psz) throw() + { + if (psz == NULL) + { + m_psz = NULL; + return; + } + int nLength = lstrlenA( psz )+1; + AtlConvAllocMemory(&m_psz,nLength,m_szBuffer,t_nBufferLength); + Checked::memcpy_s( m_psz, nLength*sizeof( char ), psz, nLength*sizeof( char )); + } + +public: + LPSTR m_psz; + char m_szBuffer[t_nBufferLength]; + +private: + CA2AEX(_In_ const CA2AEX&) throw(); + CA2AEX& operator=(_In_ const CA2AEX&) throw(); +}; +typedef CA2AEX<> CA2A; + +template< int t_nBufferLength = 128 > +class CA2CAEX +{ +public: + CA2CAEX(_In_z_ LPCSTR psz) throw() : + m_psz( psz ) + { + } + CA2CAEX( + _In_z_ LPCSTR psz, + _In_ UINT nCodePage) throw() : + m_psz( psz ) + { + (void)nCodePage; + } + ~CA2CAEX() throw() + { + } + + _Ret_z_ operator LPCSTR() const throw() + { + return( m_psz ); + } + +public: + LPCSTR m_psz; + +private: + CA2CAEX(_In_ const CA2CAEX&) throw(); + CA2CAEX& operator=(_In_ const CA2CAEX&) throw(); +}; +typedef CA2CAEX<> CA2CA; + +template< int t_nBufferLength = 128 > +class CW2CWEX +{ +public: + CW2CWEX(_In_z_ LPCWSTR psz) throw() : + m_psz( psz ) + { + } + CW2CWEX( + _In_z_ LPCWSTR psz, + _In_ UINT nCodePage) throw() : + m_psz( psz ) + { + UNREFERENCED_PARAMETER(nCodePage); + } + ~CW2CWEX() throw() + { + } + + _Ret_z_ operator LPCWSTR() const throw() + { + return( m_psz ); + } + +public: + LPCWSTR m_psz; + +private: + CW2CWEX(_In_ const CW2CWEX&) throw(); + CW2CWEX& operator=(_In_ const CW2CWEX&) throw(); +}; +typedef CW2CWEX<> CW2CW; + +template< int t_nBufferLength = 128 > +class CA2WEX +{ +public: + CA2WEX(_In_z_ LPCSTR psz) throw() : + m_psz( m_szBuffer ) + { + Init( psz, _AtlGetConversionACP() ); + } + CA2WEX( + _In_z_ LPCSTR psz, + _In_ UINT nCodePage) throw() : + m_psz( m_szBuffer ) + { + Init( psz, nCodePage ); + } + ~CA2WEX() throw() + { + AtlConvFreeMemory(m_psz,m_szBuffer,t_nBufferLength); + } + + _Ret_z_ operator LPWSTR() const throw() + { + return( m_psz ); + } + +private: + void Init( + _In_z_ LPCSTR psz, + _In_ UINT nCodePage) throw() + { + if (psz == NULL) + { + m_psz = NULL; + return; + } + int nLengthA = lstrlenA( psz )+1; + int nLengthW = nLengthA; + + AtlConvAllocMemory(&m_psz,nLengthW,m_szBuffer,t_nBufferLength); + + BOOL bFailed=(0 == ::MultiByteToWideChar( nCodePage, 0, psz, nLengthA, m_psz, nLengthW ) ); + if (bFailed) + { + if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) + { + nLengthW = ::MultiByteToWideChar( nCodePage, 0, psz, nLengthA, NULL, 0); + AtlConvAllocMemory(&m_psz,nLengthW,m_szBuffer,t_nBufferLength); + bFailed=(0 == ::MultiByteToWideChar( nCodePage, 0, psz, nLengthA, m_psz, nLengthW ) ); + } + } + if (bFailed) + { + AtlThrowLastWin32(); + } + } + +public: + LPWSTR m_psz; + wchar_t m_szBuffer[t_nBufferLength]; + +private: + CA2WEX(_In_ const CA2WEX&) throw(); + CA2WEX& operator=(_In_ const CA2WEX&) throw(); +}; +typedef CA2WEX<> CA2W; + +template< int t_nBufferLength = 128 > +class CW2AEX +{ +public: + CW2AEX(_In_z_ LPCWSTR psz) throw() : + m_psz( m_szBuffer ) + { + Init( psz, _AtlGetConversionACP() ); + } + CW2AEX( + _In_z_ LPCWSTR psz, + _In_ UINT nCodePage) throw() : + m_psz( m_szBuffer ) + { + Init( psz, nCodePage ); + } + ~CW2AEX() throw() + { + AtlConvFreeMemory(m_psz,m_szBuffer,t_nBufferLength); + } + + _Ret_z_ operator LPSTR() const throw() + { + return( m_psz ); + } + +private: + void Init( + _In_z_ LPCWSTR psz, + _In_ UINT nConvertCodePage) throw() + { + if (psz == NULL) + { + m_psz = NULL; + return; + } + int nLengthW = lstrlenW( psz )+1; + int nLengthA = nLengthW*4; + + AtlConvAllocMemory(&m_psz,nLengthA,m_szBuffer,t_nBufferLength); + + BOOL bFailed=(0 == ::WideCharToMultiByte( nConvertCodePage, 0, psz, nLengthW, m_psz, nLengthA, NULL, NULL )); + if (bFailed) + { + if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) + { + nLengthA = ::WideCharToMultiByte( nConvertCodePage, 0, psz, nLengthW, NULL, 0, NULL, NULL ); + AtlConvAllocMemory(&m_psz,nLengthA,m_szBuffer,t_nBufferLength); + bFailed=(0 == ::WideCharToMultiByte( nConvertCodePage, 0, psz, nLengthW, m_psz, nLengthA, NULL, NULL )); + } + } + if (bFailed) + { + AtlThrowLastWin32(); + } + } + +public: + LPSTR m_psz; + char m_szBuffer[t_nBufferLength]; + +private: + CW2AEX(_In_ const CW2AEX&) throw(); + CW2AEX& operator=(_In_ const CW2AEX&) throw(); +}; +typedef CW2AEX<> CW2A; + +#ifdef _UNICODE + +#define CW2T CW2W +#define CW2TEX CW2WEX +#define CW2CT CW2CW +#define CW2CTEX CW2CWEX +#define CT2W CW2W +#define CT2WEX CW2WEX +#define CT2CW CW2CW +#define CT2CWEX CW2CWEX + +#define CA2T CA2W +#define CA2TEX CA2WEX +#define CA2CT CA2W +#define CA2CTEX CA2WEX +#define CT2A CW2A +#define CT2AEX CW2AEX +#define CT2CA CW2A +#define CT2CAEX CW2AEX + +#else // !_UNICODE + +#define CW2T CW2A +#define CW2TEX CW2AEX +#define CW2CT CW2A +#define CW2CTEX CW2AEX +#define CT2W CA2W +#define CT2WEX CA2WEX +#define CT2CW CA2W +#define CT2CWEX CA2WEX + +#define CA2T CA2A +#define CA2TEX CA2AEX +#define CA2CT CA2CA +#define CA2CTEX CA2CAEX +#define CT2A CA2A +#define CT2AEX CA2AEX +#define CT2CA CA2CA +#define CT2CAEX CA2CAEX + +#endif // !_UNICODE + +#define COLE2T CW2T +#define COLE2TEX CW2TEX +#define COLE2CT CW2CT +#define COLE2CTEX CW2CTEX +#define CT2OLE CT2W +#define CT2OLEEX CT2WEX +#define CT2COLE CT2CW +#define CT2COLEEX CT2CWEX + +}; // namespace ATL +#pragma pack(pop) + +#pragma pack(push,8) + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY + +#ifndef _DEBUG + #define USES_CONVERSION int _convert; (_convert); UINT _acp = ATL::_AtlGetConversionACP() /*CP_THREAD_ACP*/; (_acp); LPCWSTR _lpw; (_lpw); LPCSTR _lpa; (_lpa) +#else + #define USES_CONVERSION int _convert = 0; (_convert); UINT _acp = ATL::_AtlGetConversionACP() /*CP_THREAD_ACP*/; (_acp); LPCWSTR _lpw = NULL; (_lpw); LPCSTR _lpa = NULL; (_lpa) +#endif + +#endif // _ATL_EX_CONVERSION_MACROS_ONLY + +#ifndef _DEBUG + #define USES_CONVERSION_EX int _convert_ex; (_convert_ex); UINT _acp_ex = ATL::_AtlGetConversionACP(); (_acp_ex); LPCWSTR _lpw_ex; (_lpw_ex); LPCSTR _lpa_ex; (_lpa_ex); USES_ATL_SAFE_ALLOCA +#else + #define USES_CONVERSION_EX int _convert_ex = 0; (_convert_ex); UINT _acp_ex = ATL::_AtlGetConversionACP(); (_acp_ex); LPCWSTR _lpw_ex = NULL; (_lpw_ex); LPCSTR _lpa_ex = NULL; (_lpa_ex); USES_ATL_SAFE_ALLOCA +#endif + +///////////////////////////////////////////////////////////////////////////// +// Global UNICODE<>ANSI translation helpers +_Ret_opt_z_cap_(nChars) inline LPWSTR WINAPI AtlA2WHelper( + _Out_opt_z_cap_(nChars) LPWSTR lpw, + _In_opt_z_ LPCSTR lpa, + _In_ int nChars, + _In_ UINT acp) throw() +{ + ATLASSERT(lpa != NULL); + ATLASSERT(lpw != NULL); + if (lpw == NULL || lpa == NULL) + return NULL; + // verify that no illegal character present + // since lpw was allocated based on the size of lpa + // don't worry about the number of chars + *lpw = '\0'; + int ret = MultiByteToWideChar(acp, 0, lpa, -1, lpw, nChars); + if(ret == 0) + { + ATLASSERT(FALSE); + return NULL; + } + return lpw; +} + +_Ret_opt_z_cap_(nChars) inline LPSTR WINAPI AtlW2AHelper( + _Out_opt_z_cap_(nChars) LPSTR lpa, + _In_opt_z_ LPCWSTR lpw, + _In_ int nChars, + _In_ UINT acp) throw() +{ + ATLASSERT(lpw != NULL); + ATLASSERT(lpa != NULL); + if (lpa == NULL || lpw == NULL) + return NULL; + // verify that no illegal character present + // since lpa was allocated based on the size of lpw + // don't worry about the number of chars + *lpa = '\0'; + int ret = WideCharToMultiByte(acp, 0, lpw, -1, lpa, nChars, NULL, NULL); + if(ret == 0) + { + ATLASSERT(FALSE); + return NULL; + } + return lpa; +} +_Ret_opt_z_cap_(nChars) inline LPWSTR WINAPI AtlA2WHelper( + _Out_opt_z_cap_(nChars) LPWSTR lpw, + _In_opt_z_ LPCSTR lpa, + _In_ int nChars) throw() +{ + return AtlA2WHelper(lpw, lpa, nChars, CP_ACP); +} + +_Ret_opt_z_cap_(nChars) inline LPSTR WINAPI AtlW2AHelper( + _Out_opt_z_cap_(nChars) LPSTR lpa, + _In_opt_z_ LPCWSTR lpw, + _In_ int nChars) throw() +{ + return AtlW2AHelper(lpa, lpw, nChars, CP_ACP); +} + +#ifndef _CONVERSION_DONT_USE_THREAD_LOCALE + #ifdef ATLA2WHELPER + #undef ATLA2WHELPER + #undef ATLW2AHELPER + #endif + #define ATLA2WHELPER AtlA2WHelper + #define ATLW2AHELPER AtlW2AHelper +#else + #ifndef ATLA2WHELPER + #define ATLA2WHELPER AtlA2WHelper + #define ATLW2AHELPER AtlW2AHelper + #endif +#endif + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY + +#define A2W(lpa) (\ + ((_lpa = lpa) == NULL) ? NULL : (\ + _convert = (lstrlenA(_lpa)+1),\ + (INT_MAX/2<_convert)? NULL : \ + ATLA2WHELPER((LPWSTR) alloca(_convert*sizeof(WCHAR)), _lpa, _convert, _acp))) + +#define W2A(lpw) (\ + ((_lpw = lpw) == NULL) ? NULL : (\ + (_convert = (lstrlenW(_lpw)+1), \ + (_convert>INT_MAX/2) ? NULL : \ + ATLW2AHELPER((LPSTR) alloca(_convert*sizeof(WCHAR)), _lpw, _convert*sizeof(WCHAR), _acp)))) + +#define A2W_CP(lpa, cp) (\ + ((_lpa = lpa) == NULL) ? NULL : (\ + _convert = (lstrlenA(_lpa)+1),\ + (INT_MAX/2<_convert)? NULL : \ + ATLA2WHELPER((LPWSTR) alloca(_convert*sizeof(WCHAR)), _lpa, _convert, (cp)))) + +#define W2A_CP(lpw, cp) (\ + ((_lpw = lpw) == NULL) ? NULL : (\ + (_convert = (lstrlenW(_lpw)+1), \ + (_convert>INT_MAX/2) ? NULL : \ + ATLW2AHELPER((LPSTR) alloca(_convert*sizeof(WCHAR)), _lpw, _convert*sizeof(WCHAR), (cp))))) + +#endif + +// The call to _alloca will not cause stack overflow if _AtlVerifyStackAvailable returns TRUE. +// Notice that nChars is never used in these conversion functions. We cannot change the behavior of +// these functions to actually use nChars because we could potentially break a lot of legacy code. +#define A2W_EX(lpa, nChars) (\ + ((_lpa_ex = lpa) == NULL) ? NULL : (\ + _convert_ex = (lstrlenA(_lpa_ex)+1),\ + FAILED(::ATL::AtlMultiply(&_convert_ex, _convert_ex, static_cast(sizeof(WCHAR)))) ? NULL : \ + ATLA2WHELPER( \ + (LPWSTR)_ATL_SAFE_ALLOCA(_convert_ex, _ATL_SAFE_ALLOCA_DEF_THRESHOLD), \ + _lpa_ex, \ + _convert_ex / sizeof(WCHAR), \ + _acp_ex))) + +#define A2W_EX_DEF(lpa) A2W_EX(lpa, _ATL_SAFE_ALLOCA_DEF_THRESHOLD) + +#define W2A_EX(lpw, nChars) (\ + ((_lpw_ex = lpw) == NULL) ? NULL : (\ + _convert_ex = (lstrlenW(_lpw_ex)+1),\ + FAILED(::ATL::AtlMultiply(&_convert_ex, _convert_ex, static_cast(sizeof(WCHAR)))) ? NULL : \ + ATLW2AHELPER( \ + (LPSTR)_ATL_SAFE_ALLOCA(_convert_ex, _ATL_SAFE_ALLOCA_DEF_THRESHOLD), \ + _lpw_ex, \ + _convert_ex, \ + _acp_ex))) + +#define W2A_EX_DEF(lpa) W2A_EX(lpa, _ATL_SAFE_ALLOCA_DEF_THRESHOLD) + +#define A2W_CP_EX(lpa, nChars, cp) (\ + ((_lpa_ex = lpa) == NULL) ? NULL : (\ + _convert_ex = (lstrlenA(_lpa_ex)+1),\ + FAILED(::ATL::AtlMultiply(&_convert_ex, _convert_ex, static_cast(sizeof(WCHAR)))) ? NULL : \ + ATLA2WHELPER( \ + (LPWSTR)_ATL_SAFE_ALLOCA(_convert_ex, _ATL_SAFE_ALLOCA_DEF_THRESHOLD), \ + _lpa_ex, \ + _convert_ex / sizeof(WCHAR), \ + (cp)))) + +#define W2A_CP_EX(lpw, nChars, cp) (\ + ((_lpw_ex = lpw) == NULL) ? NULL : (\ + _convert_ex = (lstrlenW(_lpw_ex)+1),\ + FAILED(::ATL::AtlMultiply(&_convert_ex, _convert_ex, static_cast(sizeof(WCHAR)))) ? NULL : \ + ATLW2AHELPER( \ + (LPSTR)_ATL_SAFE_ALLOCA(_convert_ex, _ATL_SAFE_ALLOCA_DEF_THRESHOLD), \ + _lpw_ex, \ + _convert_ex, \ + (cp)))) + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY + +#define A2CW(lpa) ((LPCWSTR)A2W(lpa)) +#define W2CA(lpw) ((LPCSTR)W2A(lpw)) + +#define A2CW_CP(lpa, cp) ((LPCWSTR)A2W_CP(lpa, (cp))) +#define W2CA_CP(lpw, cp) ((LPCSTR)W2A_CP(lpw, (cp))) + +#endif // _ATL_EX_CONVERSION_MACROS_ONLY + +#define A2CW_EX(lpa, nChar) ((LPCWSTR)A2W_EX(lpa, nChar)) +#define A2CW_EX_DEF(lpa) ((LPCWSTR)A2W_EX_DEF(lpa)) +#define W2CA_EX(lpw, nChar) ((LPCSTR)W2A_EX(lpw, nChar)) +#define W2CA_EX_DEF(lpw) ((LPCSTR)W2A_EX_DEF(lpw)) + +#define A2CW_CP_EX(lpa, nChar, cp) ((LPCWSTR)A2W_CP_EX(lpa, nChar, (cp))) +#define W2CA_CP_EX(lpw, nChar, cp) ((LPCSTR)W2A_CP_EX(lpw, nChar, (cp))) + +inline int ocslen(_In_z_ LPCOLESTR x) throw() +{ + return lstrlenW(x); +} + +inline bool ocscpy_s( + _Out_z_cap_(maxSize) LPOLESTR dest, + _In_ size_t maxSize, + _In_z_ LPCOLESTR src) throw() +{ + return 0 == memcpy_s(dest, maxSize*sizeof(WCHAR), src, (ocslen(src)+1)*sizeof(WCHAR)); +} + +inline bool ocscat_s( + _Inout_z_cap_(maxSize) LPOLESTR dest, + _In_ size_t maxSize, + _In_z_ LPCOLESTR src) throw() +{ + return 0 == wcscat_s(dest, maxSize,src); +} + +#if defined(_UNICODE) + +// in these cases the default (TCHAR) is the same as OLECHAR + +_Ret_z_ inline LPCOLESTR T2COLE_EX( + _In_z_ LPCTSTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPCOLESTR T2COLE_EX_DEF(_In_z_ LPCTSTR lp) +{ + return lp; +} +_Ret_z_ inline LPCTSTR OLE2CT_EX( + _In_z_ LPCOLESTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPCTSTR OLE2CT_EX_DEF(_In_z_ LPCOLESTR lp) +{ + return lp; +} +_Ret_z_ inline LPOLESTR T2OLE_EX( + _In_z_ LPTSTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPOLESTR T2OLE_EX_DEF(_In_z_ LPTSTR lp) +{ + return lp; +} +_Ret_z_ inline LPTSTR OLE2T_EX( + _In_z_ LPOLESTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPTSTR OLE2T_EX_DEF(_In_z_ LPOLESTR lp) +{ + return lp; +} + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY + +_Ret_z_ inline LPCOLESTR T2COLE(_In_z_ LPCTSTR lp) +{ + return lp; +} +_Ret_z_ inline LPCTSTR OLE2CT(_In_z_ LPCOLESTR lp) +{ + return lp; +} +_Ret_z_ inline LPOLESTR T2OLE(_In_z_ LPTSTR lp) +{ + return lp; +} +_Ret_z_ inline LPTSTR OLE2T(_In_z_ LPOLESTR lp) +{ + return lp; +} + +#endif // _ATL_EX_CONVERSION_MACROS_ONLY + +#else // !defined(_UNICODE) + +_ATL_INSECURE_DEPRECATE("ocscpy is not safe. Intead, use ocscpy_s") +inline OLECHAR* ocscpy( + _Inout_ _Post_z_ LPOLESTR dest, + _In_z_ LPCOLESTR src) throw() +{ +#pragma warning(push) +#pragma warning(disable:4996) + return (LPOLESTR) memcpy(dest, src, (lstrlenW(src)+1)*sizeof(WCHAR)); +#pragma warning(pop) +} + +_ATL_INSECURE_DEPRECATE("ocscat is not safe. Intead, use ocscat_s") +inline OLECHAR* ocscat( + _Inout_ _Post_z_ LPOLESTR dest, + _In_z_ LPCOLESTR src) throw() +{ +#pragma warning(push) +#pragma warning(disable:4996) + return ocscpy(dest+ocslen(dest), src); +#pragma warning(pop) +} + +#define T2COLE_EX(lpa, nChar) A2CW_EX(lpa, nChar) +#define T2COLE_EX_DEF(lpa) A2CW_EX_DEF(lpa) +#define T2OLE_EX(lpa, nChar) A2W_EX(lpa, nChar) +#define T2OLE_EX_DEF(lpa) A2W_EX_DEF(lpa) +#define OLE2CT_EX(lpo, nChar) W2CA_EX(lpo, nChar) +#define OLE2CT_EX_DEF(lpo) W2CA_EX_DEF(lpo) +#define OLE2T_EX(lpo, nChar) W2A_EX(lpo, nChar) +#define OLE2T_EX_DEF(lpo) W2A_EX_DEF(lpo) + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY + +#define T2COLE(lpa) A2CW(lpa) +#define T2OLE(lpa) A2W(lpa) +#define OLE2CT(lpo) W2CA(lpo) +#define OLE2T(lpo) W2A(lpo) + +#endif // _ATL_EX_CONVERSION_MACROS_ONLY + +#endif // defined(_UNICODE) + +_Ret_z_ inline LPOLESTR W2OLE_EX( + _In_z_ LPWSTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPOLESTR W2OLE_EX_DEF(_In_z_ LPWSTR lp) +{ + return lp; +} +_Ret_z_ inline LPWSTR OLE2W_EX( + _In_z_ LPOLESTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPWSTR OLE2W_EX_DEF(_In_z_ LPOLESTR lp) +{ + return lp; +} + +#define A2OLE_EX A2W_EX +#define A2OLE_EX_DEF A2W_EX_DEF +#define OLE2A_EX W2A_EX +#define OLE2A_EX_DEF W2A_EX_DEF + +_Ret_z_ inline LPCOLESTR W2COLE_EX( + _In_z_ LPCWSTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPCOLESTR W2COLE_EX_DEF(_In_z_ LPCWSTR lp) +{ + return lp; +} +_Ret_z_ inline LPCWSTR OLE2CW_EX( + _In_z_ LPCOLESTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPCWSTR OLE2CW_EX_DEF(_In_z_ LPCOLESTR lp) +{ + return lp; +} + +#define A2COLE_EX A2CW_EX +#define A2COLE_EX_DEF A2CW_EX_DEF +#define OLE2CA_EX W2CA_EX +#define OLE2CA_EX_DEF W2CA_EX_DEF + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY + +_Ret_z_ inline LPOLESTR W2OLE(_In_z_ LPWSTR lp) +{ + return lp; +} +_Ret_z_ inline LPWSTR OLE2W(_In_z_ LPOLESTR lp) +{ + return lp; +} + +#define A2OLE A2W +#define OLE2A W2A + +_Ret_z_ inline LPCOLESTR W2COLE(_In_z_ LPCWSTR lp) +{ + return lp; +} +_Ret_z_ inline LPCWSTR OLE2CW(_In_z_ LPCOLESTR lp) +{ + return lp; +} + +#define A2COLE A2CW +#define OLE2CA W2CA + +#endif // _ATL_EX_CONVERSION_MACROS_ONLY + +#if defined(_UNICODE) + +#define T2A_EX W2A_EX +#define T2A_EX_DEF W2A_EX_DEF +#define A2T_EX A2W_EX +#define A2T_EX_DEF A2W_EX_DEF + +_Ret_z_ inline LPWSTR T2W_EX( + _In_z_ LPTSTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPWSTR T2W_EX_DEF(_In_z_ LPTSTR lp) +{ + return lp; +} +_Ret_z_ inline LPTSTR W2T_EX( + _In_z_ LPWSTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPTSTR W2T_DEF(_In_z_ LPWSTR lp) +{ + return lp; +} + +#define T2CA_EX W2CA_EX +#define T2CA_EX_DEF W2CA_EX_DEF +#define A2CT_EX A2CW_EX +#define A2CT_EX_DEF A2CW_EX_DEF + +_Ret_z_ inline LPCWSTR T2CW_EX( + _In_z_ LPCTSTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPCWSTR T2CW_EX_DEF(_In_z_ LPCTSTR lp) +{ + return lp; +} +_Ret_z_ inline LPCTSTR W2CT_EX( + _In_z_ LPCWSTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPCTSTR W2CT_EX_DEF(_In_z_ LPCWSTR lp) +{ + return lp; +} + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY + +#define T2A W2A +#define A2T A2W + +_Ret_z_ inline LPWSTR T2W(_In_z_ LPTSTR lp) +{ + return lp; +} +_Ret_z_ inline LPTSTR W2T(_In_z_ LPWSTR lp) +{ + return lp; +} + +#define T2CA W2CA +#define A2CT A2CW + +_Ret_z_ inline LPCWSTR T2CW(_In_z_ LPCTSTR lp) +{ + return lp; +} +_Ret_z_ inline LPCTSTR W2CT(_In_z_ LPCWSTR lp) +{ + return lp; +} + +#endif // _ATL_EX_CONVERSION_MACROS_ONLY + +#else // !defined(_UNICODE) + +#define T2W_EX A2W_EX +#define T2W_EX_DEF A2W_EX_DEF +#define W2T_EX W2A_EX +#define W2T_EX_DEF W2A_EX_DEF + +_Ret_z_ inline LPSTR T2A_EX( + _In_z_ LPTSTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPSTR T2A_EX_DEF(_In_z_ LPTSTR lp) +{ + return lp; +} +_Ret_z_ inline LPTSTR A2T_EX( + _In_z_ LPSTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPTSTR A2T_EX_DEF(_In_z_ LPSTR lp) +{ + return lp; +} + +#define T2CW_EX A2CW_EX +#define T2CW_EX_DEF A2CW_EX_DEF +#define W2CT_EX W2CA_EX +#define W2CT_EX_DEF W2CA_EX_DEF + +_Ret_z_ inline LPCSTR T2CA_EX( + _In_z_ LPCTSTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPCSTR T2CA_EX_DEF(_In_z_ LPCTSTR lp) +{ + return lp; +} +_Ret_z_ inline LPCTSTR A2CT_EX( + _In_z_ LPCSTR lp, + _In_ UINT) +{ + return lp; +} +_Ret_z_ inline LPCTSTR A2CT_EX_DEF(_In_z_ LPCSTR lp) +{ + return lp; +} + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY + +#define T2W A2W +#define W2T W2A +_Ret_z_ inline LPSTR T2A(_In_z_ LPTSTR lp) +{ + return lp; +} +_Ret_z_ inline LPTSTR A2T(_In_z_ LPSTR lp) +{ + return lp; +} +#define T2CW A2CW +#define W2CT W2CA +_Ret_z_ inline LPCSTR T2CA(_In_z_ LPCTSTR lp) +{ + return lp; +} +_Ret_z_ inline LPCTSTR A2CT(_In_z_ LPCSTR lp) +{ + return lp; +} + +#endif // _ATL_EX_CONVERSION_MACROS_ONLY + +#endif // defined(_UNICODE) + +_Check_return_ _Ret_opt_z_ inline BSTR A2WBSTR( + _In_opt_z_ LPCSTR lp, + _In_ int nLen = -1) +{ + if (lp == NULL || nLen == 0) + return NULL; + USES_CONVERSION_EX; + BSTR str = NULL; + +ATLPREFAST_SUPPRESS(6385) + int nConvertedLen = MultiByteToWideChar(_acp_ex, 0, lp, nLen, NULL, 0); +ATLPREFAST_UNSUPPRESS() + int nAllocLen = nConvertedLen; + if (nLen == -1) + nAllocLen -= 1; // Don't allocate terminating '\0' + str = ::SysAllocStringLen(NULL, nAllocLen); + + if (str != NULL) + { + int nResult; + nResult = MultiByteToWideChar(_acp_ex, 0, lp, nLen, str, nConvertedLen); + ATLASSERT(nResult == nConvertedLen); + if(nResult != nConvertedLen) + { + SysFreeString(str); + return NULL; + } + + } + return str; +} + +_Ret_opt_z_ inline BSTR OLE2BSTR(_In_opt_z_ LPCOLESTR lp) +{ + return ::SysAllocString(lp); +} +#if defined(_UNICODE) +// in these cases the default (TCHAR) is the same as OLECHAR +_Ret_opt_z_ inline BSTR T2BSTR_EX(_In_opt_z_ LPCTSTR lp) +{ + return ::SysAllocString(lp); +} +_Ret_opt_z_ inline BSTR A2BSTR_EX(_In_opt_z_ LPCSTR lp) +{ + return A2WBSTR(lp); +} +_Ret_opt_z_ inline BSTR W2BSTR_EX(_In_opt_z_ LPCWSTR lp) +{ + return ::SysAllocString(lp); +} + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY + +_Ret_opt_z_ inline BSTR T2BSTR(_In_opt_z_ LPCTSTR lp) +{ + return ::SysAllocString(lp); +} +_Ret_opt_z_ inline BSTR A2BSTR(_In_opt_z_ LPCSTR lp) +{ + return A2WBSTR(lp); +} +_Ret_opt_z_ inline BSTR W2BSTR(_In_opt_z_ LPCWSTR lp) +{ + return ::SysAllocString(lp); +} + +#endif // _ATL_EX_CONVERSION_MACROS_ONLY + +#else // !defined(_UNICODE) +_Ret_opt_z_ inline BSTR T2BSTR_EX(_In_opt_z_ LPCTSTR lp) +{ + return A2WBSTR(lp); +} +_Ret_opt_z_ inline BSTR A2BSTR_EX(_In_opt_z_ LPCSTR lp) +{ + return A2WBSTR(lp); +} +_Ret_opt_z_ inline BSTR W2BSTR_EX(_In_opt_z_ LPCWSTR lp) +{ + return ::SysAllocString(lp); +} + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY + +_Ret_opt_z_ inline BSTR T2BSTR(_In_opt_z_ LPCTSTR lp) +{ + return A2WBSTR(lp); +} +_Ret_opt_z_ inline BSTR A2BSTR(_In_opt_z_ LPCSTR lp) +{ + return A2WBSTR(lp); +} +_Ret_opt_z_ inline BSTR W2BSTR(_In_opt_z_ LPCWSTR lp) +{ + return ::SysAllocString(lp); +} + +#endif // _ATL_EX_CONVERSION_MACROS_ONLY + +#endif // defined(_UNICODE) + +#ifdef _WINGDI_ +///////////////////////////////////////////////////////////////////////////// +// Global UNICODE<>ANSI translation helpers +inline LPDEVMODEW AtlDevModeA2W( + _Inout_ LPDEVMODEW lpDevModeW, + _In_ const DEVMODEA* lpDevModeA) +{ + USES_CONVERSION_EX; + ATLASSERT(lpDevModeW != NULL); + if (lpDevModeA == NULL || lpDevModeW == NULL) + { + return NULL; + } + + AtlA2WHelper(lpDevModeW->dmDeviceName, (LPCSTR)lpDevModeA->dmDeviceName, 32, _acp_ex); + + if(0 != memcpy_s(&lpDevModeW->dmSpecVersion, offsetof(DEVMODEW, dmFormName) - offsetof(DEVMODEW, dmSpecVersion), + &lpDevModeA->dmSpecVersion, offsetof(DEVMODEW, dmFormName) - offsetof(DEVMODEW, dmSpecVersion))) + { + return NULL; + } + + AtlA2WHelper(lpDevModeW->dmFormName, (LPCSTR)lpDevModeA->dmFormName, 32, _acp_ex); + + if(0 != memcpy_s(&lpDevModeW->dmLogPixels, sizeof(DEVMODEW) - offsetof(DEVMODEW, dmLogPixels), + &lpDevModeA->dmLogPixels, sizeof(DEVMODEW) - offsetof(DEVMODEW, dmLogPixels))) + { + return NULL; + } + + if (lpDevModeA->dmDriverExtra != 0) + { + // lpDevModeW holds more info +#pragma warning(push) +#pragma warning(disable:26000) + if(0 != memcpy_s(lpDevModeW+1, lpDevModeA->dmDriverExtra, lpDevModeA+1, lpDevModeA->dmDriverExtra)) + { + return NULL; + } +#pragma warning(pop) + } + lpDevModeW->dmSize = sizeof(DEVMODEW); + return lpDevModeW; +} + +inline LPTEXTMETRICW AtlTextMetricA2W( + _Out_ LPTEXTMETRICW lptmW, + _In_ LPTEXTMETRICA lptmA) +{ + USES_CONVERSION_EX; + ATLASSERT(lptmW != NULL); + if (lptmA == NULL || lptmW == NULL) + return NULL; + + if(0 != memcpy_s(lptmW, sizeof(LONG) * 11, lptmA, sizeof(LONG) * 11)) + { + return NULL; + } + + if(0 != memcpy_s(&lptmW->tmItalic, sizeof(BYTE) * 5, &lptmA->tmItalic, sizeof(BYTE) * 5)) + { + return NULL; + } + + if(MultiByteToWideChar(_acp_ex, 0, (LPCSTR)&lptmA->tmFirstChar, 1, &lptmW->tmFirstChar, 1) == 0) + { + ATLASSERT(FALSE); + return NULL; + } + + if(MultiByteToWideChar(_acp_ex, 0, (LPCSTR)&lptmA->tmLastChar, 1, &lptmW->tmLastChar, 1) == 0) + { + ATLASSERT(FALSE); + return NULL; + } + + if(MultiByteToWideChar(_acp_ex, 0, (LPCSTR)&lptmA->tmDefaultChar, 1, &lptmW->tmDefaultChar, 1)== 0) + { + ATLASSERT(FALSE); + return NULL; + } + + if(MultiByteToWideChar(_acp_ex, 0, (LPCSTR)&lptmA->tmBreakChar, 1, &lptmW->tmBreakChar, 1) == 0) + { + ATLASSERT(FALSE); + return NULL; + } + + return lptmW; +} + +inline LPTEXTMETRICA AtlTextMetricW2A( + _Out_ LPTEXTMETRICA lptmA, + _In_ LPTEXTMETRICW lptmW) +{ + USES_CONVERSION_EX; + ATLASSERT(lptmA != NULL); + if (lptmW == NULL || lptmA == NULL) + { + return NULL; + } + + if(0 != memcpy_s(lptmA, sizeof(LONG) * 11, lptmW, sizeof(LONG) * 11)) + { + return NULL; + } + + if(0 != memcpy_s(&lptmA->tmItalic, sizeof(BYTE) * 5, &lptmW->tmItalic, sizeof(BYTE) * 5)) + { + return NULL; + } + + if(WideCharToMultiByte(_acp_ex, 0, &lptmW->tmFirstChar, 1, (LPSTR)&lptmA->tmFirstChar, 1, NULL, NULL) == 0) + { + ATLASSERT(FALSE); + return NULL; + } + + if(WideCharToMultiByte(_acp_ex, 0, &lptmW->tmLastChar, 1, (LPSTR)&lptmA->tmLastChar, 1, NULL, NULL) == 0) + { + ATLASSERT(FALSE); + return NULL; + } + + if(WideCharToMultiByte(_acp_ex, 0, &lptmW->tmDefaultChar, 1, (LPSTR)&lptmA->tmDefaultChar, 1, NULL, NULL) == 0) + { + ATLASSERT(FALSE); + return NULL; + } + + if(WideCharToMultiByte(_acp_ex, 0, &lptmW->tmBreakChar, 1, (LPSTR)&lptmA->tmBreakChar, 1, NULL, NULL) == 0) + { + ATLASSERT(FALSE); + return NULL; + } + + return lptmA; +} + +#ifndef ATLDEVMODEA2W +#define ATLDEVMODEA2W AtlDevModeA2W +#define ATLDEVMODEW2A AtlDevModeW2A +#define ATLTEXTMETRICA2W AtlTextMetricA2W +#define ATLTEXTMETRICW2A AtlTextMetricW2A +#endif + +// Requires USES_CONVERSION_EX or USES_ATL_SAFE_ALLOCA macro before using the _EX versions of the macros +#define DEVMODEW2A_EX(lpw)\ + (((lpw) == NULL) ? NULL : ATLDEVMODEW2A((LPDEVMODEA)_ATL_SAFE_ALLOCA(sizeof(DEVMODEA)+(lpw)->dmDriverExtra, _ATL_SAFE_ALLOCA_DEF_THRESHOLD), (lpw))) +#define DEVMODEA2W_EX(lpa)\ + (((lpa) == NULL) ? NULL : ATLDEVMODEA2W((LPDEVMODEW)_ATL_SAFE_ALLOCA(sizeof(DEVMODEW)+(lpa)->dmDriverExtra, _ATL_SAFE_ALLOCA_DEF_THRESHOLD), (lpa))) +#define TEXTMETRICW2A_EX(lptmw)\ + (((lptmw) == NULL) ? NULL : ATLTEXTMETRICW2A((LPTEXTMETRICA)_ATL_SAFE_ALLOCA(sizeof(TEXTMETRICA), _ATL_SAFE_ALLOCA_DEF_THRESHOLD), (lptmw))) +#define TEXTMETRICA2W_EX(lptma)\ + (((lptma) == NULL) ? NULL : ATLTEXTMETRICA2W((LPTEXTMETRICW)_ATL_SAFE_ALLOCA(sizeof(TEXTMETRICW), _ATL_SAFE_ALLOCA_DEF_THRESHOLD), (lptma))) + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY + +#define DEVMODEW2A(lpw)\ + ((lpw == NULL) ? NULL : ATLDEVMODEW2A((LPDEVMODEA)alloca(sizeof(DEVMODEA)+lpw->dmDriverExtra), lpw)) +#define DEVMODEA2W(lpa)\ + ((lpa == NULL) ? NULL : ATLDEVMODEA2W((LPDEVMODEW)alloca(sizeof(DEVMODEW)+lpa->dmDriverExtra), lpa)) +#define TEXTMETRICW2A(lptmw)\ + ((lptmw == NULL) ? NULL : ATLTEXTMETRICW2A((LPTEXTMETRICA)alloca(sizeof(TEXTMETRICA)), lptmw)) +#define TEXTMETRICA2W(lptma)\ + ((lptma == NULL) ? NULL : ATLTEXTMETRICA2W((LPTEXTMETRICW)alloca(sizeof(TEXTMETRICW)), lptma)) + +#endif // _ATL_EX_CONVERSION_MACROS_ONLY + +#define DEVMODEOLE DEVMODEW +#define LPDEVMODEOLE LPDEVMODEW +#define TEXTMETRICOLE TEXTMETRICW +#define LPTEXTMETRICOLE LPTEXTMETRICW + +#if defined(_UNICODE) +// in these cases the default (TCHAR) is the same as OLECHAR +inline LPDEVMODEW DEVMODEOLE2T_EX(_In_opt_ LPDEVMODEOLE lp) +{ + return lp; +} +inline LPDEVMODEOLE DEVMODET2OLE_EX(_In_opt_ LPDEVMODEW lp) +{ + return lp; +} +inline LPTEXTMETRICW TEXTMETRICOLE2T_EX(_In_ LPTEXTMETRICOLE lp) +{ + return lp; +} +inline LPTEXTMETRICOLE TEXTMETRICT2OLE_EX(_In_ LPTEXTMETRICW lp) +{ + return lp; +} + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY +inline LPDEVMODEW DEVMODEOLE2T(_In_ LPDEVMODEOLE lp) +{ + return lp; +} +inline LPDEVMODEOLE DEVMODET2OLE(_In_ LPDEVMODEW lp) +{ + return lp; +} +inline LPTEXTMETRICW TEXTMETRICOLE2T(_In_ LPTEXTMETRICOLE lp) +{ + return lp; +} +inline LPTEXTMETRICOLE TEXTMETRICT2OLE(_In_ LPTEXTMETRICW lp) +{ + return lp; +} +#endif // _ATL_EX_CONVERSION_MACROS_ONLY + +#else // !defined(_UNICODE) + +#define DEVMODEOLE2T_EX(lpo) DEVMODEW2A_EX(lpo) +#define DEVMODET2OLE_EX(lpa) DEVMODEA2W_EX(lpa) +#define TEXTMETRICOLE2T_EX(lptmw) TEXTMETRICW2A_EX(lptmw) +#define TEXTMETRICT2OLE_EX(lptma) TEXTMETRICA2W_EX(lptma) + +#ifndef _ATL_EX_CONVERSION_MACROS_ONLY + +#define DEVMODEOLE2T(lpo) DEVMODEW2A(lpo) +#define DEVMODET2OLE(lpa) DEVMODEA2W(lpa) +#define TEXTMETRICOLE2T(lptmw) TEXTMETRICW2A(lptmw) +#define TEXTMETRICT2OLE(lptma) TEXTMETRICA2W(lptma) + +#endif // _ATL_EX_CONVERSION_MACROS_ONLY + +#endif // defined(_UNICODE) + +#endif //_WINGDI_ + +#pragma pack(pop) + +///////////////////////////////////////////////////////////////////////////// + +#ifndef _ATL_DLL + +#ifdef _WINGDI_ + +ATLINLINE ATLAPI_(LPDEVMODEA) AtlDevModeW2A( + _Inout_opt_ LPDEVMODEA lpDevModeA, + _In_ const DEVMODEW* lpDevModeW) +{ + USES_CONVERSION_EX; + ATLASSERT(lpDevModeA != NULL); + if (lpDevModeW == NULL || lpDevModeA == NULL) + return NULL; + + AtlW2AHelper((LPSTR)lpDevModeA->dmDeviceName, lpDevModeW->dmDeviceName, 32, _acp_ex); + + if(0 != memcpy_s(&lpDevModeA->dmSpecVersion, offsetof(DEVMODEA, dmFormName) - offsetof(DEVMODEA, dmSpecVersion), + &lpDevModeW->dmSpecVersion, offsetof(DEVMODEA, dmFormName) - offsetof(DEVMODEA, dmSpecVersion))) + { + return NULL; + } + + AtlW2AHelper((LPSTR)lpDevModeA->dmFormName, lpDevModeW->dmFormName, 32, _acp_ex); + + if(0 != memcpy_s(&lpDevModeA->dmLogPixels, sizeof(DEVMODEA) - offsetof(DEVMODEA, dmLogPixels), + &lpDevModeW->dmLogPixels, sizeof(DEVMODEA) - offsetof(DEVMODEA, dmLogPixels))) + { + return NULL; + } + + if (lpDevModeW->dmDriverExtra != 0) + { + // lpDevModeW holds more info +#pragma warning(push) +#pragma warning(disable:26000) + if(0 != memcpy_s(lpDevModeA+1, lpDevModeW->dmDriverExtra, lpDevModeW+1, lpDevModeW->dmDriverExtra)) + { + return NULL; + } +#pragma warning(pop) + } + + lpDevModeA->dmSize = sizeof(DEVMODEA); + return lpDevModeA; +} + +#endif //_WINGDI + +#endif // !_ATL_DLL + +#ifndef _ATL_NO_PRAGMA_WARNINGS +#pragma warning (pop) +#endif //!_ATL_NO_PRAGMA_WARNINGS + +#endif // __ATLCONV_H__ diff --git a/src/main/headers/atlcore.h b/src/main/headers/atlcore.h new file mode 100644 index 0000000..6de8d0c --- /dev/null +++ b/src/main/headers/atlcore.h @@ -0,0 +1,601 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#ifndef __ATLCORE_H__ +#define __ATLCORE_H__ + +#pragma once + +#ifdef _ATL_ALL_WARNINGS +#pragma warning( push ) +#endif + +#pragma warning(disable: 4786) // identifier was truncated in the debug information +#pragma warning(disable: 4127) // constant expression + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#if _WIN32_WINNT < 0x0403 +#error This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended. +#endif + +#pragma pack(push,_ATL_PACKING) +namespace ATL +{ +///////////////////////////////////////////////////////////////////////////// +// Verify that a null-terminated string points to valid memory +inline BOOL AtlIsValidString( + _In_z_count_(nMaxLength) LPCWSTR psz, + _In_ size_t nMaxLength = INT_MAX) +{ + (nMaxLength); + return (psz != NULL); +} + +// Verify that a null-terminated string points to valid memory +inline BOOL AtlIsValidString( + _In_z_count_(nMaxLength) LPCSTR psz, + _In_ size_t nMaxLength = UINT_MAX) +{ + (nMaxLength); + return (psz != NULL); +} + +// Verify that a pointer points to valid memory +inline BOOL AtlIsValidAddress( + _In_opt_bytecount_(nBytes) const void* p, + _In_ size_t nBytes, + _In_ BOOL bReadWrite = TRUE) +{ + (bReadWrite); + (nBytes); + return (p != NULL); +} + +template +inline void AtlAssertValidObject( + _In_opt_ _Prepost_opt_bytecount_x_(sizeof(T)) const T *pOb) +{ + ATLASSERT(pOb); + ATLASSERT(AtlIsValidAddress(pOb, sizeof(T))); + if(pOb) + pOb->AssertValid(); +} +#ifdef _DEBUG +#define ATLASSERT_VALID(x) ATL::AtlAssertValidObject(x) +#else +#define ATLASSERT_VALID(x) __noop; +#endif + +// COM Sync Classes +class CComCriticalSection +{ +public: + CComCriticalSection() throw() + { + memset(&m_sec, 0, sizeof(CRITICAL_SECTION)); + } + ~CComCriticalSection() + { + } + HRESULT Lock() throw() + { + EnterCriticalSection(&m_sec); + return S_OK; + } + HRESULT Unlock() throw() + { + LeaveCriticalSection(&m_sec); + return S_OK; + } + HRESULT Init() throw() + { + HRESULT hRes = S_OK; + + if (!InitializeCriticalSectionAndSpinCount(&m_sec, 0)) + { + hRes = HRESULT_FROM_WIN32(GetLastError()); + } + + return hRes; + } + + HRESULT Term() throw() + { + DeleteCriticalSection(&m_sec); + return S_OK; + } + CRITICAL_SECTION m_sec; +}; + +class CComAutoCriticalSection : + public CComCriticalSection +{ +public: + CComAutoCriticalSection() + { + HRESULT hr = CComCriticalSection::Init(); + if (FAILED(hr)) + AtlThrow(hr); + } + ~CComAutoCriticalSection() throw() + { + CComCriticalSection::Term(); + } +private : + HRESULT Init(); // Not implemented. CComAutoCriticalSection::Init should never be called + HRESULT Term(); // Not implemented. CComAutoCriticalSection::Term should never be called +}; + +class CComSafeDeleteCriticalSection : + public CComCriticalSection +{ +public: + CComSafeDeleteCriticalSection(): m_bInitialized(false) + { + } + + ~CComSafeDeleteCriticalSection() throw() + { + if (!m_bInitialized) + { + return; + } + m_bInitialized = false; + CComCriticalSection::Term(); + } + + HRESULT Init() throw() + { + ATLASSERT( !m_bInitialized ); + HRESULT hr = CComCriticalSection::Init(); + if (SUCCEEDED(hr)) + { + m_bInitialized = true; + } + return hr; + } + + HRESULT Term() throw() + { + if (!m_bInitialized) + { + return S_OK; + } + m_bInitialized = false; + return CComCriticalSection::Term(); + } + + HRESULT Lock() + { + // CComSafeDeleteCriticalSection::Init or CComAutoDeleteCriticalSection::Init + // not called or failed. + // m_critsec member of CComObjectRootEx is now of type + // CComAutoDeleteCriticalSection. It has to be initialized + // by calling CComObjectRootEx::_AtlInitialConstruct + ATLASSUME(m_bInitialized); + return CComCriticalSection::Lock(); + } + +private: + bool m_bInitialized; +}; + +class CComAutoDeleteCriticalSection : + public CComSafeDeleteCriticalSection +{ +private: + // CComAutoDeleteCriticalSection::Term should never be called + HRESULT Term() throw(); +}; + +class CComFakeCriticalSection +{ +public: + HRESULT Lock() throw() + { + return S_OK; + } + HRESULT Unlock() throw() + { + return S_OK; + } + HRESULT Init() throw() + { + return S_OK; + } + HRESULT Term() throw() + { + return S_OK; + } +}; + +///////////////////////////////////////////////////////////////////////////// +// Module + +// Used by any project that uses ATL +struct _ATL_BASE_MODULE70 +{ + UINT cbSize; + HINSTANCE m_hInst; + HINSTANCE m_hInstResource; + DWORD dwAtlBuildVer; + const GUID* pguidVer; + CComCriticalSection m_csResource; + CSimpleArray m_rgResourceInstance; +}; +typedef _ATL_BASE_MODULE70 _ATL_BASE_MODULE; + +class CAtlBaseModule : + public _ATL_BASE_MODULE +{ +public : + static bool m_bInitFailed; + CAtlBaseModule() throw(); + ~CAtlBaseModule() throw (); + + HINSTANCE GetModuleInstance() throw() + { + return m_hInst; + } + HINSTANCE GetResourceInstance() throw() + { + return m_hInstResource; + } + HINSTANCE SetResourceInstance(_In_ HINSTANCE hInst) throw() + { + return static_cast< HINSTANCE >(InterlockedExchangePointer((void**)&m_hInstResource, hInst)); + } + + bool AddResourceInstance(_In_ HINSTANCE hInst) throw(); + bool RemoveResourceInstance(_In_ HINSTANCE hInst) throw(); + HINSTANCE GetHInstanceAt(_In_ int i) throw(); +}; + +__declspec(selectany) bool CAtlBaseModule::m_bInitFailed = false; +extern CAtlBaseModule _AtlBaseModule; + +///////////////////////////////////////////////////////////////////////////// +// String resource helpers + +#pragma warning(push) +#pragma warning(disable: 4200) + struct ATLSTRINGRESOURCEIMAGE + { + WORD nLength; + WCHAR achString[]; + }; +#pragma warning(pop) // C4200 + +inline const ATLSTRINGRESOURCEIMAGE* _AtlGetStringResourceImage( + _In_ HINSTANCE hInstance, + _In_ HRSRC hResource, + _In_ UINT id) throw() +{ + const ATLSTRINGRESOURCEIMAGE* pImage; + const ATLSTRINGRESOURCEIMAGE* pImageEnd; + ULONG nResourceSize; + HGLOBAL hGlobal; + UINT iIndex; + + hGlobal = ::LoadResource( hInstance, hResource ); + if( hGlobal == NULL ) + { + return( NULL ); + } + + pImage = (const ATLSTRINGRESOURCEIMAGE*)::LockResource( hGlobal ); + if( pImage == NULL ) + { + return( NULL ); + } + + nResourceSize = ::SizeofResource( hInstance, hResource ); + pImageEnd = (const ATLSTRINGRESOURCEIMAGE*)(LPBYTE( pImage )+nResourceSize); + iIndex = id&0x000f; + + while( (iIndex > 0) && (pImage < pImageEnd) ) + { + pImage = (const ATLSTRINGRESOURCEIMAGE*)(LPBYTE( pImage )+(sizeof( ATLSTRINGRESOURCEIMAGE )+(pImage->nLength*sizeof( WCHAR )))); + iIndex--; + } + if( pImage >= pImageEnd ) + { + return( NULL ); + } + if( pImage->nLength == 0 ) + { + return( NULL ); + } + + return( pImage ); +} + +inline const ATLSTRINGRESOURCEIMAGE* AtlGetStringResourceImage( + _In_ HINSTANCE hInstance, + _In_ UINT id) throw() +{ + HRSRC hResource; + /* + The and operation (& static_cast(~0)) protects the expression from being greater + than WORD - this would cause a runtime error when the application is compiled with /RTCc flag. + */ + hResource = ::FindResourceW(hInstance, MAKEINTRESOURCEW( (((id>>4)+1) & static_cast(~0)) ), (LPWSTR) RT_STRING); + if( hResource == NULL ) + { + return( NULL ); + } + + return _AtlGetStringResourceImage( hInstance, hResource, id ); +} + +inline const ATLSTRINGRESOURCEIMAGE* AtlGetStringResourceImage( + _In_ HINSTANCE hInstance, + _In_ UINT id, + _In_ WORD wLanguage) throw() +{ + HRSRC hResource; + /* + The and operation (& static_cast(~0)) protects the expression from being greater + than WORD - this would cause a runtime error when the application is compiled with /RTCc flag. + */ + hResource = ::FindResourceExW(hInstance, (LPWSTR) RT_STRING, MAKEINTRESOURCEW( (((id>>4)+1) & static_cast(~0)) ), wLanguage); + if( hResource == NULL ) + { + return( NULL ); + } + + return _AtlGetStringResourceImage( hInstance, hResource, id ); +} + +inline const ATLSTRINGRESOURCEIMAGE* AtlGetStringResourceImage(_In_ UINT id) throw() +{ + const ATLSTRINGRESOURCEIMAGE* p = NULL; + HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0); + + for (int i = 1; hInst != NULL && p == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++)) + { + p = AtlGetStringResourceImage(hInst, id); + } + return p; +} + +inline const ATLSTRINGRESOURCEIMAGE* AtlGetStringResourceImage( + _In_ UINT id, + _In_ WORD wLanguage) throw() +{ + const ATLSTRINGRESOURCEIMAGE* p = NULL; + HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0); + + for (int i = 1; hInst != NULL && p == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++)) + { + p = AtlGetStringResourceImage(hInst, id, wLanguage); + } + return p; +} + +inline int AtlLoadString( + _In_ UINT nID, + _Out_z_cap_post_count_(nBufferMax, return + 1) LPTSTR lpBuffer, + _In_ int nBufferMax) throw() +{ + HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0); + int nRet = 0; + + for (int i = 1; hInst != NULL && nRet == 0; hInst = _AtlBaseModule.GetHInstanceAt(i++)) + { + nRet = LoadString(hInst, nID, lpBuffer, nBufferMax); + } + return nRet; +} + +inline HINSTANCE AtlFindResourceInstance( + _In_z_ LPCTSTR lpName, + _In_z_ LPCTSTR lpType, + _In_ WORD wLanguage = 0) throw() +{ + ATLASSERT(lpType != RT_STRING); // Call AtlFindStringResourceInstance to find the string + if (lpType == RT_STRING) + return NULL; + + if (ATL_IS_INTRESOURCE(lpType)) + { + /* Prefast false warnings caused by bad-shaped definition of MAKEINTRESOURCE macro from PSDK */ + if (lpType == ATL_RT_ICON) + { + lpType = ATL_RT_GROUP_ICON; + } + else if (lpType == ATL_RT_CURSOR) + { + lpType = ATL_RT_GROUP_CURSOR; + } + } + + HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0); + HRSRC hResource = NULL; + + for (int i = 1; hInst != NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++)) + { + hResource = ::FindResourceEx(hInst, lpType, lpName, wLanguage); + if (hResource != NULL) + { + return hInst; + } + } + + return NULL; +} + +inline HINSTANCE AtlFindResourceInstance( + _In_ UINT nID, + _In_z_ LPCTSTR lpType, + _In_ WORD wLanguage = 0) throw() +{ + /* + The and operation (& static_cast(~0)) protects the expression from being greater + than WORD - this would cause a runtime error when the application is compiled with /RTCc flag. + */ + return AtlFindResourceInstance(MAKEINTRESOURCE(nID & static_cast(~0)), lpType, wLanguage); +} + +inline HINSTANCE AtlFindStringResourceInstance( + _In_ UINT nID, + _In_ WORD wLanguage = 0) throw() +{ + const ATLSTRINGRESOURCEIMAGE* p = NULL; + HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0); + + for (int i = 1; hInst != NULL && p == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++)) + { + p = AtlGetStringResourceImage(hInst, nID, wLanguage); + if (p != NULL) + return hInst; + } + + return NULL; +} + +/* +Needed by both atlcomcli and atlsafe, so needs to be in here +*/ +inline HRESULT AtlSafeArrayGetActualVartype( + _In_ SAFEARRAY *psaArray, + _Out_ VARTYPE *pvtType) +{ + HRESULT hrSystem=::SafeArrayGetVartype(psaArray, pvtType); + + if(FAILED(hrSystem)) + { + return hrSystem; + } + + /* + When Windows has a SAFEARRAY of type VT_DISPATCH with FADF_HAVEIID, + it returns VT_UNKNOWN instead of VT_DISPATCH. We patch the value to be correct + */ + if(pvtType && *pvtType==VT_UNKNOWN) + { + if(psaArray && ((psaArray->fFeatures & FADF_HAVEIID)!=0)) + { + if(psaArray->fFeatures & FADF_DISPATCH) + { + *pvtType=VT_DISPATCH; + } + } + } + + return hrSystem; +} +template +inline _CharType* AtlCharNext(_In_ const _CharType* p) throw() +{ + ATLASSUME(p != NULL); // Too expensive to check separately here + if (*p == '\0') // ::CharNextA won't increment if we're at a \0 already + return const_cast<_CharType*>(p+1); + else + return ::CharNextA(p); +} + +template <> +inline wchar_t* AtlCharNext(_In_ const wchar_t* p) throw() +{ + return const_cast< wchar_t* >( p+1 ); +} +template +inline const CharType* AtlstrchrT( + _In_z_ const CharType* p, + _In_ CharType ch) throw() +{ + ATLASSERT(p != NULL); + if(p==NULL) + { + return NULL; + } + while( *p != 0 ) + { + if (*p == ch) + { + return p; + } + p = AtlCharNext(p); + } + //strchr for '\0' should succeed - the while loop terminates + //*p == 0, but ch also == 0, so NULL terminator address is returned + return (*p == ch) ? p : NULL; +} +//Ansi and Unicode versions of printf, used with templated CharType trait classes. +#pragma warning(push) +#pragma warning(disable : 4793) +template +inline int AtlprintfT(_In_z_ _Printf_format_string_ const CharType* pszFormat,...) throw() +{ + int retval=0; + va_list argList; + va_start( argList, pszFormat ); + retval=vprintf(pszFormat,argList); + va_end( argList ); + return retval; +} +#pragma warning(pop) + +#pragma warning(push) +#pragma warning(disable : 4793) +template<> +inline int AtlprintfT(_In_z_ _Printf_format_string_ const wchar_t* pszFormat,... ) throw() +{ + int retval=0; + va_list argList; + va_start( argList, pszFormat ); + retval=vwprintf(pszFormat, argList); + va_end( argList ); + return retval; +} +#pragma warning(pop) + +inline BOOL AtlConvertSystemTimeToVariantTime( + _In_ const SYSTEMTIME& systimeSrc, + _Out_ double* pVarDtTm) +{ + ATLENSURE(pVarDtTm!=NULL); + //Convert using ::SystemTimeToVariantTime and store the result in pVarDtTm then + //convert variant time back to system time and compare to original system time. + BOOL ok = ::SystemTimeToVariantTime(const_cast(&systimeSrc), pVarDtTm); + SYSTEMTIME sysTime; + ::ZeroMemory(&sysTime, sizeof(SYSTEMTIME)); + + ok = ok && ::VariantTimeToSystemTime(*pVarDtTm, &sysTime); + ok = ok && (systimeSrc.wYear == sysTime.wYear && + systimeSrc.wMonth == sysTime.wMonth && + systimeSrc.wDay == sysTime.wDay && + systimeSrc.wHour == sysTime.wHour && + systimeSrc.wMinute == sysTime.wMinute && + systimeSrc.wSecond == sysTime.wSecond); + + return ok; +} +///////////////////////////////////////////////////////////////////////////// + +} // namespace ATL +#pragma pack(pop) + +#ifdef _ATL_ALL_WARNINGS +#pragma warning( pop ) +#endif + +#endif // __ATLCORE_H__ diff --git a/src/main/headers/atldef.h b/src/main/headers/atldef.h new file mode 100644 index 0000000..ce05b3c --- /dev/null +++ b/src/main/headers/atldef.h @@ -0,0 +1,712 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#ifndef __ATLDEF_H__ +#define __ATLDEF_H__ + +#pragma once + +#pragma warning(disable : 4619) // there is no warning number + +#include +#include +#include + +// preprocessor string helpers +#ifndef _ATL_STRINGIZE +#define __ATL_STRINGIZE(_Value) #_Value +#define _ATL_STRINGIZE(_Value) __ATL_STRINGIZE(_Value) +#endif + +#ifndef _ATL_APPEND +#define __ATL_APPEND(_Value1, _Value2) _Value1 ## _Value2 +#define _ATL_APPEND(_Value1, _Value2) __ATL_APPEND(_Value1, _Value2) +#endif + +#ifndef RC_INVOKED + +#ifndef __cplusplus + #error ATL requires C++ compilation (use a .cpp suffix) +#endif + +#ifdef UNDER_CE + #error This version of ATL is not currently supported for CE. Look for the CE specific version. +#endif + +// If you are mixing compilation units that are built as +// native code with those that are built /clr, you must define +// the symbol '_ATL_MIXED'. _ATL_MIXED must be defined for all +// compilation units in an executable or it must be defined for none of them. +#if !defined(_ATL_MIXED) +namespace Inconsistent_definition_of_symbol__ATL_MIXED +{ + struct _Please_define_it_the_same_throughout_your_project { }; +} +#else +namespace Inconsistent_definition_of_symbol__ATL_MIXED +{ +#ifdef _M_IX86 +#pragma comment(linker, "/include:??3@YAXPAX@Z") +#else +#pragma comment(linker, "/include:??3@YAXPEAX@Z") +#endif + struct _Please_define_it_the_same_throughout_your_project { virtual void one(){} }; +} +#endif +namespace Inconsistent_definition_of_symbol__ATL_MIXED +{ + __declspec(selectany) _Please_define_it_the_same_throughout_your_project clash = _Please_define_it_the_same_throughout_your_project (); +} + +#if !defined(_ATL_MIXED) +namespace Define_the_symbol__ATL_MIXED +{ +#if defined(_M_CEE) + struct Thank_you { }; +#else +#ifdef _M_IX86 +#pragma comment(linker, "/include:??3@YAXPAX@Z") +#else +#pragma comment(linker, "/include:??3@YAXPEAX@Z") +#endif + struct Thank_you { virtual void one(){} }; +#endif + __declspec(selectany) Thank_you clash = Thank_you(); +} +#endif + +#if defined(_ATL_MIXED) +#define _ATL_NATIVE_INITIALIZATION +#endif + +#if !defined(_M_CEE) +#define _ATL_NATIVE_INITIALIZATION +#endif + +#ifdef _UNICODE +#ifndef UNICODE +#define UNICODE // UNICODE is used by Windows headers +#endif +#endif + +#ifdef UNICODE +#ifndef _UNICODE +#define _UNICODE // _UNICODE is used by C-runtime/MFC headers +#endif +#endif + +#ifdef _DEBUG +#ifndef DEBUG +#define DEBUG +#endif +#endif + + +//PREFAST support static_assert from version 16.00 +#if defined(_PREFAST_) && (_MSC_VER < 1600) +#define ATLSTATIC_ASSERT(expr, comment) +#else +#define ATLSTATIC_ASSERT(expr, comment) static_assert(expr, comment) +#endif + +#ifdef _WIN64 +#define _ATL_SUPPORT_VT_I8 // Always support VT_I8 on Win64. +#endif + +#if !defined(UNALIGNED) +#if defined(_M_IA64) || defined(_M_AMD64) +#define UNALIGNED __unaligned +#else +#define UNALIGNED +#endif +#endif + +#if !defined(_countof) +#if !defined(__cplusplus) +#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0])) +#else +extern "C++" +{ +template +char (*__countof_helper(UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray]; +#define _countof(_Array) sizeof(*__countof_helper(_Array)) +} +#endif +#endif + +#if defined(__MINGW32__) +#ifndef ATLASSERT +#define ATLASSERT(expr) _ASSERTE(expr) +#endif // ATLASSERT + +#include +#endif + +#ifndef AtlThrow +#ifndef _ATL_CUSTOM_THROW +#define AtlThrow ATL::AtlThrowImpl +#endif +#endif // AtlThrow + +#if !defined(__MINGW32__) +#ifndef ATLASSERT +#define ATLASSERT(expr) _ASSERTE(expr) +#endif // ATLASSERT +#endif + +/* +Why does ATLASSUME exist? + +ATL 8 has two existing validation models + +ATLASSERT/ATLVERIFY - These are used to make sure a debug build reports a problem with the expression/invariant +ATLENSURE - Debug is the same as ATLVERIFY, retail throws a C++ exception + +We added ATLENSURE because there were too many unreported error paths in ATL and we wanted to bail out of more +error conditions rather than just trying to continue in retail. + +There might be a case for changing 'lots' of ATLASSERT to ATLENSURE, but we chose an incremental approach and only +changed over where we saw a problem with code reported from a customer or test case. This reduces code churn in our +code for this version. + +In general, our approach is to try to make sure that when something goes wrong +- the client does not continue to run, because we report an error condition +- debug builds see an assertion about the problem + +Sometimes we have code like + +HRESULT ComMethod(void) +{ + ATLASSUME(m_pFoo); + return m_pFoo->Method(); +} + +We could add + if(!m_pFoo) return E_POINTER; + +But this is very unlikely to help, since it removes the ability of the developer to debug this problem if it's seen in a retail +build of the application. + +We could try something more severe + + if(!m_pFoo) terminate(); // or your favourite shutdown function + +This would ensure good reporting (because VC8 terminate generates a Windows Error Report and crash dump), but hardly seems a big win +over the previous crash. + +ATLENSURE might seem slightly better. It is debuggable and consistent with ATL in general. In fact, many parts of ATL do just this. +But in this specific context, it doesn't look like a great choice. COM methods should not in general be emitting native C++ exceptions +as an error reporting strategy. + +So we find ourselves in a quandry. For these kinds of methods, the traditional code (ATLASSERT followed by a crash), seems be the most +debuggable thing to do in this situation. At least for VS8, we have decided to stick with this shape. + +--- + +Now consider the impact of cl /analyze. We want cl /analyze to not warn about our potential dereferences when they refer to member variables +whose state was previously validated by another method. But we do want to see the impact of function contracts on the parameters of the +function. + +So we've done a broad replace of all the member-related ATLASSERT to ATLASSUME. + +*/ + +#ifndef ATLASSUME +#define ATLASSUME(expr) do { ATLASSERT(expr); __analysis_assume(!!(expr)); } while(0) +#endif // ATLASSUME + +#ifndef ATLVERIFY +#ifdef _DEBUG +#define ATLVERIFY(expr) ATLASSERT(expr) +#else +#define ATLVERIFY(expr) (expr) +#endif // DEBUG +#endif // ATLVERIFY + +#ifndef ATLENSURE_THROW +#define ATLENSURE_THROW(expr, hr) \ +do { \ + int __atl_condVal=!!(expr); \ + ATLASSUME(__atl_condVal); \ + if(!(__atl_condVal)) AtlThrow(hr); \ +} while (0) +#endif // ATLENSURE_THROW + +#ifndef ATLENSURE +#define ATLENSURE(expr) ATLENSURE_THROW(expr, E_FAIL) +#endif // ATLENSURE + +#ifndef ATLENSURE_SUCCEEDED +#define ATLENSURE_SUCCEEDED(hr) ATLENSURE_THROW(SUCCEEDED(hr), hr) +#endif // ATLENSURE_SUCCEEDED + +/* Used inside COM methods that do not want to throw */ +#ifndef ATLENSURE_RETURN_VAL +#define ATLENSURE_RETURN_VAL(expr, val) \ +do { \ + int __atl_condVal=!!(expr); \ + ATLASSERT(__atl_condVal); \ + if(!(__atl_condVal)) return val; \ +} while (0) +#endif // ATLENSURE_RETURN_VAL + +/* Used inside COM methods that do not want to throw */ +#ifndef ATLENSURE_RETURN +#define ATLENSURE_RETURN(expr) ATLENSURE_RETURN_HR(expr, E_FAIL) +#endif // ATLENSURE_RETURN + +/* Naming is slightly off in these macros +ATLENSURE_RETURN is an HRESULT return of E_FAIL +ATLENSURE_RETURN_VAL is any return value (function can pick) +ATLENSURE_RETURN_HR is HRESULT-specific, though currently the same as _VAL +*/ +#ifndef ATLENSURE_RETURN_HR +#define ATLENSURE_RETURN_HR(expr, hr) ATLENSURE_RETURN_VAL(expr, hr) +#endif // ATLENSURE_RETURN_HR + +#ifndef ATL_CRT_ERRORCHECK +#define ATL_CRT_ERRORCHECK(expr) AtlCrtErrorCheck(expr) +#endif // ATL_CRT_ERRORCHECK + +#ifndef ATL_CRT_ERRORCHECK_SPRINTF +#define ATL_CRT_ERRORCHECK_SPRINTF(expr) \ +do { \ + errno_t _saveErrno = errno; \ + errno = 0; \ + (expr); \ + if(0 != errno) \ + { \ + AtlCrtErrorCheck(errno); \ + } \ + else \ + { \ + errno = _saveErrno; \ + } \ +} while (0) +#endif // ATL_CRT_ERRORCHECK_SPRINTF + +/////////////////////////////////////////////////////////////////////////////// +// __declspec(novtable) is used on a class declaration to prevent the vtable +// pointer from being initialized in the constructor and destructor for the +// class. This has many benefits because the linker can now eliminate the +// vtable and all the functions pointed to by the vtable. Also, the actual +// constructor and destructor code are now smaller. +/////////////////////////////////////////////////////////////////////////////// +// This should only be used on a class that is not directly createable but is +// rather only used as a base class. Additionally, the constructor and +// destructor (if provided by the user) should not call anything that may cause +// a virtual function call to occur back on the object. +/////////////////////////////////////////////////////////////////////////////// +// By default, the wizards will generate new ATL object classes with this +// attribute (through the ATL_NO_VTABLE macro). This is normally safe as long +// the restriction mentioned above is followed. It is always safe to remove +// this macro from your class, so if in doubt, remove it. +/////////////////////////////////////////////////////////////////////////////// + +#ifdef _ATL_DISABLE_NO_VTABLE +#define ATL_NO_VTABLE +#else +#define ATL_NO_VTABLE __declspec(novtable) +#endif + +#ifdef _ATL_DISABLE_NOTHROW +#define ATL_NOTHROW +#else +#define ATL_NOTHROW __declspec(nothrow) +#endif + +#ifdef _ATL_DISABLE_FORCEINLINE +#define ATL_FORCEINLINE +#else +#define ATL_FORCEINLINE __forceinline +#endif + +#ifdef _ATL_DISABLE_NOINLINE +#define ATL_NOINLINE +#else +#define ATL_NOINLINE __declspec( noinline ) +#endif + +#ifdef _ATL_DISABLE_DEPRECATED +#define ATL_DEPRECATED(_Message) +#else +#define ATL_DEPRECATED(_Message) __declspec( deprecated(_Message) ) +#endif + +// If ATLXX.DLL is being used then _ATL_STATIC_REGISTRY doesn't really make sense +#ifdef _ATL_DLL +#undef _ATL_STATIC_REGISTRY +#else +// If not linking to ATLXX.DLL, use the static registrar and not building atl.dll +#ifndef _ATL_DLL_IMPL +#ifndef _ATL_STATIC_REGISTRY +#define _ATL_STATIC_REGISTRY +#endif +#endif +#endif + +#ifdef _ATL_DEBUG_REFCOUNT +#ifndef _ATL_DEBUG_INTERFACES +#define _ATL_DEBUG_INTERFACES +#endif +#endif + +#ifdef _DEBUG +#ifndef _ATL_DEBUG +#define _ATL_DEBUG +#endif // _ATL_DEBUG +#endif // _DEBUG + +#ifdef _ATL_DEBUG_INTERFACES +#ifndef _ATL_DEBUG +#define _ATL_DEBUG +#endif // _ATL_DEBUG +#endif // _ATL_DEBUG_INTERFACES + +#ifndef _ATL_HEAPFLAGS +#ifdef _MALLOC_ZEROINIT +#define _ATL_HEAPFLAGS HEAP_ZERO_MEMORY +#else +#define _ATL_HEAPFLAGS 0 +#endif +#endif + +#ifndef _ATL_PACKING +#define _ATL_PACKING 8 +#endif + +#if defined(_ATL_DLL) + #define ATLAPI extern "C" HRESULT __declspec(dllimport) __stdcall + #define ATLAPI_(x) extern "C" __declspec(dllimport) x __stdcall + #define ATLINLINE + #define ATLAPIINL extern "C" inline HRESULT __stdcall + #define ATLAPIINL_(x) extern "C" inline x __stdcall +#elif defined(_ATL_DLL_IMPL) + #define ATLAPI extern "C" inline HRESULT __stdcall + #define ATLAPI_(x) extern "C" inline x __stdcall + #define ATLAPIINL ATLAPI + #define ATLAPIINL_(x) ATLAPI_(x) + #define ATLINLINE +#else + #define ATLAPI __declspec(nothrow) HRESULT __stdcall + #define ATLAPI_(x) __declspec(nothrow) x __stdcall + #define ATLAPIINL ATLAPI + #define ATLAPIINL_(x) ATLAPI_(x) + #define ATLINLINE inline +#endif + +#ifdef _ATL_NO_EXCEPTIONS + #ifdef _AFX + // #error MFC projects cannot define _ATL_NO_EXCEPTIONS + #endif +#else + #ifndef _CPPUNWIND + #define _ATL_NO_EXCEPTIONS + #endif +#endif + +#ifdef _CPPUNWIND + +#ifndef ATLTRYALLOC + +#ifdef _AFX +#define ATLTRYALLOC(x) try{x;} catch(CException* e){e->Delete();} +#else +/* prefast noise VSW 489981 */ +#define ATLTRYALLOC(x) __pragma(warning(push)) __pragma(warning(disable: 4571)) try{x;} catch(...) {} __pragma(warning(pop)) +#endif //__AFX + +#endif //ATLTRYALLOC + +// If you define _ATLTRY before including this file, then +// you should define _ATLCATCH and _ATLRETHROW as well. +#ifndef _ATLTRY +#define _ATLTRY try +#ifdef _AFX +#define _ATLCATCH( e ) catch( CException* e ) +#else +#define _ATLCATCH( e ) catch( CAtlException e ) +#endif + +#define _ATLCATCHALL() __pragma(warning(push)) __pragma(warning(disable: 4571)) catch( ... ) __pragma(warning(pop)) + +#ifdef _AFX +#define _ATLDELETEEXCEPTION(e) e->Delete(); +#else +#define _ATLDELETEEXCEPTION(e) e; +#endif + +#define _ATLRETHROW throw +#endif // _ATLTRY + +/* +COM functions should not throw. Which means we should protect their callers from C++ exceptions leaking out. These macros +can help with that, though they have not yet been applied to the whole of ATL, which uses a variety of patterns to achieve +this end +*/ + +#ifndef _ATL_COM_BEGIN +#define _ATL_COM_BEGIN \ + HRESULT __hrAtlComMethod=S_OK; \ + try \ + { +#endif + +#ifdef _AFX +/* Nice to do something more complex here in future to translate an MFC exception to a better HR */ +#define _AFX_COM_END_PART \ + catch(CException *e) \ + { \ + if(e) \ + { \ + e->Delete(); \ + } \ + __hrAtlComMethod=E_FAIL; \ + } +#else +#define _AFX_COM_END_PART \ + catch(CAtlException e) \ + { \ + __hrAtlComMethod=e.m_hr; \ + } +#endif + +#ifndef _ATL_COM_END +#define _ATL_COM_END \ + _AFX_COM_END_PART \ + catch(...) \ + { \ + __hrAtlComMethod=E_FAIL; \ + } \ + return hr; +#endif + + + +#else //_CPPUNWIND + +#ifndef ATLTRYALLOC +#define ATLTRYALLOC(x) x; +#endif //ATLTRYALLOC + +// if _ATLTRY is defined before including this file then +// _ATLCATCH and _ATLRETHROW should be defined as well. +#ifndef _ATLTRY +#define _ATLTRY +#define _ATLCATCH( e ) __pragma(warning(push)) __pragma(warning(disable: 4127)) if( false ) __pragma(warning(pop)) +#define _ATLCATCHALL() __pragma(warning(push)) __pragma(warning(disable: 4127)) if( false ) __pragma(warning(pop)) +#define _ATLDELETEEXCEPTION(e) +#define _ATLRETHROW +#endif // _ATLTRY + +#endif //_CPPUNWIND + +#ifndef ATLTRY +#define ATLTRY(x) ATLTRYALLOC(x) +#endif //ATLTRY + +#define offsetofclass(base, derived) ((DWORD_PTR)(static_cast((derived*)_ATL_PACKING))-_ATL_PACKING) + +///////////////////////////////////////////////////////////////////////////// +// Master version numbers + +#define _ATL 1 // Active Template Library +#define _ATL_VER 0x0A00 // Active Template Library version 10.00 + +#ifndef _ATL_FILENAME_VER +#define _ATL_FILENAME_VER "100" +#endif + +#ifndef _ATL_FILENAME_VER_NUM +#define _ATL_FILENAME_VER_NUM 100 +#endif + +#ifndef _ATL_VER_RBLD +#define _ATL_VER_RBLD "10.00" +#endif + +///////////////////////////////////////////////////////////////////////////// +// Threading + +#ifndef _ATL_SINGLE_THREADED +#ifndef _ATL_APARTMENT_THREADED +#ifndef _ATL_FREE_THREADED +#define _ATL_FREE_THREADED +#endif +#endif +#endif + +// UUIDOF +#ifndef _ATL_NO_UUIDOF +#define _ATL_IIDOF(x) __uuidof(x) +#else +#define _ATL_IIDOF(x) IID_##x +#endif + +// Lean and mean +#ifndef ATL_NO_LEAN_AND_MEAN +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#ifndef NOMCX +#define NOMCX +#endif +#endif // ATL_NO_LEAN_AND_MEAN + +#ifdef NOSERVICE +#ifndef _ATL_NO_SERVICE +#define _ATL_NO_SERVICE +#endif // _ATL_NO_SERVICE +#else +#ifdef _ATL_NO_SERVICE +#ifndef NOSERVICE +#define NOSERVICE +#endif // NOSERVICE +#endif // _ATL_NO_SERVICE +#endif // NOSERVICE + +#include +#ifdef _DEBUG +#include +#endif +#ifndef _ATL_NO_DEBUG_CRT +// Warning: if you define the above symbol, you will have +// to provide your own definition of the ATLASSERT(x) macro +// in order to compile ATL + #include +#endif + +#endif // RC_INVOKED + +// Note : we can not use macros to generate the window class names because it +// will require nested macros. rc.exe does not handle nested macros. +// #define ATLAXWIN_CLASS _ATL_STRINGIZE(_ATL_APPEND(AtlAxWin, _ATL_FILENAME_VER_NUM)) +// #define ATLAXWINLIC_CLASS _ATL_STRINGIZE(_ATL_APPEND(AtlAxWinLic, _ATL_FILENAME_VER_NUM)) + +#define ATLAXWIN_CLASS "AtlAxWin100" +#define ATLAXWINLIC_CLASS "AtlAxWinLic100" + +#if defined(_ATL_SECURE_NO_DEPRECATE) && !defined(_ATL_SECURE_NO_WARNINGS) +#define _ATL_SECURE_NO_WARNINGS +#endif + +// _ATL_INSECURE_DEPRECATE define +#ifndef _ATL_INSECURE_DEPRECATE +#ifdef _ATL_SECURE_NO_WARNINGS +#define _ATL_INSECURE_DEPRECATE(_Message) +#else +#define _ATL_INSECURE_DEPRECATE(_Message) __declspec(deprecated(_Message)) +#endif // _ATL_SECURE_NO_WARNINGS +#endif // _ATL_INSECURE_DEPRECATE + +/* +This is called when something really bad happens -- so bad +that we consider it dangerous to even throw an exception +*/ +#ifndef _ATL_FATAL_SHUTDOWN +#define _ATL_FATAL_SHUTDOWN do { ::TerminateProcess(::GetCurrentProcess(), 0); } while(0) +#endif + +//ATL/MFC code should use standard pointer to member standard syntax &MyClass::MyMethod, instead +//of the legacy non-standard syntax - MyMethod. +#ifdef _ATL_ENABLE_PTM_WARNING +#define PTM_WARNING_DISABLE +#define PTM_WARNING_RESTORE +#else +#if !defined(__MINGW32__) +#define PTM_WARNING_DISABLE \ + __pragma(warning( push )) \ + __pragma(warning( disable : 4867 )) +#define PTM_WARNING_RESTORE \ + __pragma(warning( pop )) +#else +#define PTM_WARNING_DISABLE +#define PTM_WARNING_RESTORE +#endif +#endif //_ATL_ENABLE_PTM_WARNING + +/* we have to define our own versions of MAKEINTRESOURCE and IS_INTRESOURCE to + * fix warning 6268. At least until those macros are not cleanend in PSDK. + Same comes true for those definitions of constants which use the above macros +*/ +#define ATL_MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i)))) +#define ATL_MAKEINTRESOURCEW(i) ((LPWSTR)((ULONG_PTR)((WORD)(i)))) +#ifdef UNICODE +#define ATL_MAKEINTRESOURCE ATL_MAKEINTRESOURCEW +#else +#define ATL_MAKEINTRESOURCE ATL_MAKEINTRESOURCEA +#endif // !UNICODE +#define ATL_IS_INTRESOURCE(_r) ((((ULONG_PTR)(_r)) >> 16) == 0) + +/* + * Predefined Resource Types + */ +#define ATL_RT_CURSOR ATL_MAKEINTRESOURCE(1) +#define ATL_RT_BITMAP ATL_MAKEINTRESOURCE(2) +#define ATL_RT_ICON ATL_MAKEINTRESOURCE(3) +#define ATL_RT_MENU ATL_MAKEINTRESOURCE(4) +#define ATL_RT_DIALOG ATL_MAKEINTRESOURCE(5) +#define ATL_RT_STRING ATL_MAKEINTRESOURCE(6) +#define ATL_RT_FONTDIR ATL_MAKEINTRESOURCE(7) +#define ATL_RT_FONT ATL_MAKEINTRESOURCE(8) +#define ATL_RT_ACCELERATOR ATL_MAKEINTRESOURCE(9) +#define ATL_RT_RCDATA ATL_MAKEINTRESOURCE(10) +#define ATL_RT_MESSAGETABLE ATL_MAKEINTRESOURCE(11) + +#define ATL_DIFFERENCE 11 +#define ATL_RT_GROUP_CURSOR ATL_MAKEINTRESOURCE((ULONG_PTR)ATL_RT_CURSOR + ATL_DIFFERENCE) +#define ATL_RT_GROUP_ICON ATL_MAKEINTRESOURCE((ULONG_PTR)ATL_RT_ICON + ATL_DIFFERENCE) +#define ATL_RT_VERSION ATL_MAKEINTRESOURCE(16) +#define ATL_RT_DLGINCLUDE ATL_MAKEINTRESOURCE(17) +#define ATL_RT_PLUGPLAY ATL_MAKEINTRESOURCE(19) +#define ATL_RT_VXD ATL_MAKEINTRESOURCE(20) +#define ATL_RT_ANICURSOR ATL_MAKEINTRESOURCE(21) +#define ATL_RT_ANIICON ATL_MAKEINTRESOURCE(22) +#define ATL_RT_HTML ATL_MAKEINTRESOURCE(23) + +/* sal.h stuff that is not in the current LKG */ +#ifndef __out_ecount_part_z +#define __out_ecount_part_z(size,length) __out_ecount_part(size,length) __post __nullterminated +#endif + +#ifndef __out_ecount_part_z_opt +#define __out_ecount_part_z_opt(size,length) __out_ecount_part_opt(size,length) __post __nullterminated +#endif + +#ifndef __deref_opt_out_z +#define __deref_opt_out_z __deref_opt_out __post __deref __nullterminated +#endif + +#ifndef __out_bcount_part_z +#define __out_bcount_part_z(size,length) __out_bcount_part(size,length) __post __nullterminated +#endif + +#if !defined(__MINGW32__) +#define ATLPREFAST_SUPPRESS(x) __pragma(warning(push)) __pragma(warning(disable: x)) +#define ATLPREFAST_UNSUPPRESS() __pragma(warning(pop)) +#else +#define ATLPREFAST_SUPPRESS(x) +#define ATLPREFAST_UNSUPPRESS() +#endif + +#ifndef _FormatMessage_format_string_ +#define _FormatMessage_format_string_ +#endif + +/* + Helper functions for SAL annotation +*/ +namespace ATL { + +} // namespace ATL + +#endif // __ATLDEF_H__ + +///////////////////////////////////////////////////////////////////////////// diff --git a/src/main/headers/atlexcept.h b/src/main/headers/atlexcept.h new file mode 100644 index 0000000..a1e88e6 --- /dev/null +++ b/src/main/headers/atlexcept.h @@ -0,0 +1,120 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#ifndef __ATLEXCEPT_H__ +#define __ATLEXCEPT_H__ + +#pragma once + +#if !defined(__MINGW32__) +#include +#include +#endif + + +#pragma pack(push,_ATL_PACKING) +namespace ATL +{ + +///////////////////////////////////////////////////////////////////////////// +// Exception raise (for functions that cannot return an error code) + +inline void __declspec(noreturn) _AtlRaiseException( + _In_ DWORD dwExceptionCode, + _In_ DWORD dwExceptionFlags = EXCEPTION_NONCONTINUABLE) +{ + RaiseException( dwExceptionCode, dwExceptionFlags, 0, NULL ); +} + +class CAtlException +{ +public: + CAtlException() throw() : + m_hr( E_FAIL ) + { + } + + CAtlException(_In_ HRESULT hr) throw() : + m_hr( hr ) + { + } + + operator HRESULT() const throw() + { + return( m_hr ); + } + +public: + HRESULT m_hr; +}; + +#ifndef ATL_NOINLINE +#ifdef _ATL_DISABLE_NOINLINE +#define ATL_NOINLINE +#else +#define ATL_NOINLINE __declspec( noinline ) +#endif +#endif + +#ifndef _ATL_NO_EXCEPTIONS + +// Throw a CAtlException with the given HRESULT +#if defined( _ATL_CUSTOM_THROW ) // You can define your own AtlThrow to throw a custom exception. +#ifdef _AFX +#error MFC projects must use default implementation of AtlThrow() +#endif +#else +ATL_NOINLINE __declspec(noreturn) inline void WINAPI AtlThrowImpl(_In_ HRESULT hr) +{ + throw CAtlException( hr ); +} +#endif + +// Throw a CAtlException corresponding to the result of ::GetLastError +ATL_NOINLINE __declspec(noreturn) inline void WINAPI AtlThrowLastWin32() +{ + DWORD dwError = ::GetLastError(); + AtlThrowImpl( HRESULT_FROM_WIN32( dwError ) ); +} + +#else // no exception handling + +// Throw a CAtlException with th given HRESULT +#if !defined( _ATL_CUSTOM_THROW ) // You can define your own AtlThrow + +ATL_NOINLINE inline void WINAPI AtlThrowImpl(_In_ HRESULT hr) +{ + ATLASSERT( false ); + DWORD dwExceptionCode; + switch(hr) + { + case E_OUTOFMEMORY: + dwExceptionCode = STATUS_NO_MEMORY; + break; + default: + dwExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION; + } + _AtlRaiseException((DWORD)dwExceptionCode); +} +#endif + +// Throw a CAtlException corresponding to the result of ::GetLastError +ATL_NOINLINE inline void WINAPI AtlThrowLastWin32() +{ + DWORD dwError = ::GetLastError(); + AtlThrowImpl( HRESULT_FROM_WIN32( dwError ) ); +} + +#endif // no exception handling + +} // namespace ATL +#pragma pack(pop) + +#endif // __ATLEXCEPT_H__ diff --git a/src/main/headers/atliface.h b/src/main/headers/atliface.h new file mode 100644 index 0000000..75eef99 --- /dev/null +++ b/src/main/headers/atliface.h @@ -0,0 +1,2794 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#pragma warning( disable: 4049 ) /* more than 64k source lines */ + +/* this ALWAYS GENERATED file contains the definitions for the interfaces */ + + + /* File created by MIDL compiler version 6.00.0342 */ +/* at Mon Feb 12 21:31:09 2001 + */ +/* Compiler settings for atliface.idl: + Oicf, W1, Zp8, env=Win32 (32b run) + protocol : dce , ms_ext, c_ext + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +//@@MIDL_FILE_HEADING( ) + + +/* verify that the version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCNDR_H_VERSION__ +#define __REQUIRED_RPCNDR_H_VERSION__ 440 +#endif + +#include "rpc.h" +#include "rpcndr.h" + +#ifndef __RPCNDR_H_VERSION__ +#error this stub requires an updated version of +#endif // __RPCNDR_H_VERSION__ + +#ifndef COM_NO_WINDOWS_H +#include "windows.h" +#include "ole2.h" +#endif /*COM_NO_WINDOWS_H*/ + +#ifndef __atliface_h__ +#define __atliface_h__ + +#pragma once + +/* Forward Declarations */ + +#ifndef __IRegistrarBase_FWD_DEFINED__ +#define __IRegistrarBase_FWD_DEFINED__ +typedef interface IRegistrarBase IRegistrarBase; +#endif /* __IRegistrarBase_FWD_DEFINED__ */ + + +#ifndef __IRegistrar_FWD_DEFINED__ +#define __IRegistrar_FWD_DEFINED__ +typedef interface IRegistrar IRegistrar; +#endif /* __IRegistrar_FWD_DEFINED__ */ + + +#ifndef __IDocHostUIHandlerDispatch_FWD_DEFINED__ +#define __IDocHostUIHandlerDispatch_FWD_DEFINED__ +typedef interface IDocHostUIHandlerDispatch IDocHostUIHandlerDispatch; +#endif /* __IDocHostUIHandlerDispatch_FWD_DEFINED__ */ + + +#ifndef __IAxWinHostWindow_FWD_DEFINED__ +#define __IAxWinHostWindow_FWD_DEFINED__ +typedef interface IAxWinHostWindow IAxWinHostWindow; +#endif /* __IAxWinHostWindow_FWD_DEFINED__ */ + + +#ifndef __IAxWinHostWindowLic_FWD_DEFINED__ +#define __IAxWinHostWindowLic_FWD_DEFINED__ +typedef interface IAxWinHostWindowLic IAxWinHostWindowLic; +#endif /* __IAxWinHostWindowLic_FWD_DEFINED__ */ + + +#ifndef __IAxWinAmbientDispatch_FWD_DEFINED__ +#define __IAxWinAmbientDispatch_FWD_DEFINED__ +typedef interface IAxWinAmbientDispatch IAxWinAmbientDispatch; +#endif /* __IAxWinAmbientDispatch_FWD_DEFINED__ */ + + +#ifndef __IAxWinAmbientDispatchEx_FWD_DEFINED__ +#define __IAxWinAmbientDispatchEx_FWD_DEFINED__ +typedef interface IAxWinAmbientDispatchEx IAxWinAmbientDispatchEx; +#endif /* __IAxWinAmbientDispatchEx_FWD_DEFINED__ */ + + +#ifndef __IInternalConnection_FWD_DEFINED__ +#define __IInternalConnection_FWD_DEFINED__ +typedef interface IInternalConnection IInternalConnection; +#endif /* __IInternalConnection_FWD_DEFINED__ */ + + +#ifndef __IAccessibleServer_FWD_DEFINED__ +#define __IAccessibleServer_FWD_DEFINED__ +typedef interface IAccessibleServer IAccessibleServer; +#endif /* __IAccessibleServer_FWD_DEFINED__ */ + + +/* header files for imported files */ +#include "oaidl.h" +#include "ocidl.h" +// #include "oleacc.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +#ifndef __MIDL_user_allocate_free_DEFINED__ +#define __MIDL_user_allocate_free_DEFINED__ +void * __RPC_USER MIDL_user_allocate(size_t); +void __RPC_USER MIDL_user_free( void * ); +#endif + +/* interface __MIDL_itf_atliface_0000 */ +/* [local] */ + +EXTERN_C const CLSID CLSID_Registrar; + + +extern RPC_IF_HANDLE __MIDL_itf_atliface_0000_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_atliface_0000_v0_0_s_ifspec; + +#ifndef __IRegistrarBase_INTERFACE_DEFINED__ +#define __IRegistrarBase_INTERFACE_DEFINED__ + +/* interface IRegistrarBase */ +/* [unique][helpstring][uuid][object] */ + + +EXTERN_C const IID IID_IRegistrarBase; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("e21f8a85-b05d-4243-8183-c7cb405588f7") + IRegistrarBase : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE AddReplacement( + /* [in] */ LPCOLESTR key, + /* [in] */ LPCOLESTR item) = 0; + + virtual HRESULT STDMETHODCALLTYPE ClearReplacements( void) = 0; + + }; + +#else /* C style interface */ + + typedef struct IRegistrarBaseVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IRegistrarBase * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IRegistrarBase * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IRegistrarBase * This); + + HRESULT ( STDMETHODCALLTYPE *AddReplacement )( + IRegistrarBase * This, + /* [in] */ LPCOLESTR key, + /* [in] */ LPCOLESTR item); + + HRESULT ( STDMETHODCALLTYPE *ClearReplacements )( + IRegistrarBase * This); + + END_INTERFACE + } IRegistrarBaseVtbl; + + interface IRegistrarBase + { + CONST_VTBL struct IRegistrarBaseVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IRegistrarBase_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IRegistrarBase_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IRegistrarBase_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IRegistrarBase_AddReplacement(This,key,item) \ + (This)->lpVtbl -> AddReplacement(This,key,item) + +#define IRegistrarBase_ClearReplacements(This) \ + (This)->lpVtbl -> ClearReplacements(This) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +HRESULT STDMETHODCALLTYPE IRegistrarBase_AddReplacement_Proxy( + IRegistrarBase * This, + /* [in] */ LPCOLESTR key, + /* [in] */ LPCOLESTR item); + + +void __RPC_STUB IRegistrarBase_AddReplacement_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IRegistrarBase_ClearReplacements_Proxy( + IRegistrarBase * This); + + +void __RPC_STUB IRegistrarBase_ClearReplacements_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IRegistrarBase_INTERFACE_DEFINED__ */ + + +#ifndef __IRegistrar_INTERFACE_DEFINED__ +#define __IRegistrar_INTERFACE_DEFINED__ + +/* interface IRegistrar */ +/* [unique][helpstring][uuid][object] */ + + +EXTERN_C const IID IID_IRegistrar; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("44EC053B-400F-11D0-9DCD-00A0C90391D3") + IRegistrar : public IRegistrarBase + { + public: + virtual HRESULT STDMETHODCALLTYPE ResourceRegisterSz( + /* [in] */ LPCOLESTR resFileName, + /* [in] */ LPCOLESTR szID, + /* [in] */ LPCOLESTR szType) = 0; + + virtual HRESULT STDMETHODCALLTYPE ResourceUnregisterSz( + /* [in] */ LPCOLESTR resFileName, + /* [in] */ LPCOLESTR szID, + /* [in] */ LPCOLESTR szType) = 0; + + virtual HRESULT STDMETHODCALLTYPE FileRegister( + /* [in] */ LPCOLESTR fileName) = 0; + + virtual HRESULT STDMETHODCALLTYPE FileUnregister( + /* [in] */ LPCOLESTR fileName) = 0; + + virtual HRESULT STDMETHODCALLTYPE StringRegister( + /* [in] */ LPCOLESTR data) = 0; + + virtual HRESULT STDMETHODCALLTYPE StringUnregister( + /* [in] */ LPCOLESTR data) = 0; + + virtual HRESULT STDMETHODCALLTYPE ResourceRegister( + /* [in] */ LPCOLESTR resFileName, + /* [in] */ UINT nID, + /* [in] */ LPCOLESTR szType) = 0; + + virtual HRESULT STDMETHODCALLTYPE ResourceUnregister( + /* [in] */ LPCOLESTR resFileName, + /* [in] */ UINT nID, + /* [in] */ LPCOLESTR szType) = 0; + + }; + +#else /* C style interface */ + + typedef struct IRegistrarVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IRegistrar * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IRegistrar * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IRegistrar * This); + + HRESULT ( STDMETHODCALLTYPE *AddReplacement )( + IRegistrar * This, + /* [in] */ LPCOLESTR key, + /* [in] */ LPCOLESTR item); + + HRESULT ( STDMETHODCALLTYPE *ClearReplacements )( + IRegistrar * This); + + HRESULT ( STDMETHODCALLTYPE *ResourceRegisterSz )( + IRegistrar * This, + /* [in] */ LPCOLESTR resFileName, + /* [in] */ LPCOLESTR szID, + /* [in] */ LPCOLESTR szType); + + HRESULT ( STDMETHODCALLTYPE *ResourceUnregisterSz )( + IRegistrar * This, + /* [in] */ LPCOLESTR resFileName, + /* [in] */ LPCOLESTR szID, + /* [in] */ LPCOLESTR szType); + + HRESULT ( STDMETHODCALLTYPE *FileRegister )( + IRegistrar * This, + /* [in] */ LPCOLESTR fileName); + + HRESULT ( STDMETHODCALLTYPE *FileUnregister )( + IRegistrar * This, + /* [in] */ LPCOLESTR fileName); + + HRESULT ( STDMETHODCALLTYPE *StringRegister )( + IRegistrar * This, + /* [in] */ LPCOLESTR data); + + HRESULT ( STDMETHODCALLTYPE *StringUnregister )( + IRegistrar * This, + /* [in] */ LPCOLESTR data); + + HRESULT ( STDMETHODCALLTYPE *ResourceRegister )( + IRegistrar * This, + /* [in] */ LPCOLESTR resFileName, + /* [in] */ UINT nID, + /* [in] */ LPCOLESTR szType); + + HRESULT ( STDMETHODCALLTYPE *ResourceUnregister )( + IRegistrar * This, + /* [in] */ LPCOLESTR resFileName, + /* [in] */ UINT nID, + /* [in] */ LPCOLESTR szType); + + END_INTERFACE + } IRegistrarVtbl; + + interface IRegistrar + { + CONST_VTBL struct IRegistrarVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IRegistrar_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IRegistrar_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IRegistrar_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IRegistrar_AddReplacement(This,key,item) \ + (This)->lpVtbl -> AddReplacement(This,key,item) + +#define IRegistrar_ClearReplacements(This) \ + (This)->lpVtbl -> ClearReplacements(This) + + +#define IRegistrar_ResourceRegisterSz(This,resFileName,szID,szType) \ + (This)->lpVtbl -> ResourceRegisterSz(This,resFileName,szID,szType) + +#define IRegistrar_ResourceUnregisterSz(This,resFileName,szID,szType) \ + (This)->lpVtbl -> ResourceUnregisterSz(This,resFileName,szID,szType) + +#define IRegistrar_FileRegister(This,fileName) \ + (This)->lpVtbl -> FileRegister(This,fileName) + +#define IRegistrar_FileUnregister(This,fileName) \ + (This)->lpVtbl -> FileUnregister(This,fileName) + +#define IRegistrar_StringRegister(This,data) \ + (This)->lpVtbl -> StringRegister(This,data) + +#define IRegistrar_StringUnregister(This,data) \ + (This)->lpVtbl -> StringUnregister(This,data) + +#define IRegistrar_ResourceRegister(This,resFileName,nID,szType) \ + (This)->lpVtbl -> ResourceRegister(This,resFileName,nID,szType) + +#define IRegistrar_ResourceUnregister(This,resFileName,nID,szType) \ + (This)->lpVtbl -> ResourceUnregister(This,resFileName,nID,szType) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +HRESULT STDMETHODCALLTYPE IRegistrar_ResourceRegisterSz_Proxy( + IRegistrar * This, + /* [in] */ LPCOLESTR resFileName, + /* [in] */ LPCOLESTR szID, + /* [in] */ LPCOLESTR szType); + + +void __RPC_STUB IRegistrar_ResourceRegisterSz_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IRegistrar_ResourceUnregisterSz_Proxy( + IRegistrar * This, + /* [in] */ LPCOLESTR resFileName, + /* [in] */ LPCOLESTR szID, + /* [in] */ LPCOLESTR szType); + + +void __RPC_STUB IRegistrar_ResourceUnregisterSz_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IRegistrar_FileRegister_Proxy( + IRegistrar * This, + /* [in] */ LPCOLESTR fileName); + + +void __RPC_STUB IRegistrar_FileRegister_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IRegistrar_FileUnregister_Proxy( + IRegistrar * This, + /* [in] */ LPCOLESTR fileName); + + +void __RPC_STUB IRegistrar_FileUnregister_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IRegistrar_StringRegister_Proxy( + IRegistrar * This, + /* [in] */ LPCOLESTR data); + + +void __RPC_STUB IRegistrar_StringRegister_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IRegistrar_StringUnregister_Proxy( + IRegistrar * This, + /* [in] */ LPCOLESTR data); + + +void __RPC_STUB IRegistrar_StringUnregister_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IRegistrar_ResourceRegister_Proxy( + IRegistrar * This, + /* [in] */ LPCOLESTR resFileName, + /* [in] */ UINT nID, + /* [in] */ LPCOLESTR szType); + + +void __RPC_STUB IRegistrar_ResourceRegister_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IRegistrar_ResourceUnregister_Proxy( + IRegistrar * This, + /* [in] */ LPCOLESTR resFileName, + /* [in] */ UINT nID, + /* [in] */ LPCOLESTR szType); + + +void __RPC_STUB IRegistrar_ResourceUnregister_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IRegistrar_INTERFACE_DEFINED__ */ + + +#ifndef __IDocHostUIHandlerDispatch_INTERFACE_DEFINED__ +#define __IDocHostUIHandlerDispatch_INTERFACE_DEFINED__ + +/* interface IDocHostUIHandlerDispatch */ +/* [object][unique][helpstring][uuid][local] */ + +typedef +enum tagDOCHOSTUIDBLCLKDispatch + { docHostUIDblClkDEFAULT = 0, + docHostUIDblClkSHOWPROPERTIES = 1, + docHostUIDblClkSHOWCODE = 2 + } DOCHOSTUIDBLCLKDispatch; + +typedef +enum tagDocHostUIFlagDispatch + { docHostUIFlagDIALOG = 1, + docHostUIFlagDISABLE_HELP_MENU = 2, + docHostUIFlagNO3DBORDER = 4, + docHostUIFlagSCROLL_NO = 8, + docHostUIFlagDISABLE_SCRIPT_INACTIVE = 16, + docHostUIFlagOPENNEWWIN = 32, + docHostUIFlagDISABLE_OFFSCREEN = 64, + docHostUIFlagFLAT_SCROLLBAR = 128, + docHostUIFlagDIV_BLOCKDEFAULT = 256, + docHostUIFlagACTIVATE_CLIENTHIT_ONLY = 512 + } DocHostUIFlagDispatch; + + +EXTERN_C const IID IID_IDocHostUIHandlerDispatch; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("425B5AF0-65F1-11d1-9611-0000F81E0D0D") + IDocHostUIHandlerDispatch : public IDispatch + { + public: + virtual HRESULT STDMETHODCALLTYPE ShowContextMenu( + /* [in] */ DWORD dwID, + /* [in] */ DWORD x, + /* [in] */ DWORD y, + /* [in] */ IUnknown *pcmdtReserved, + /* [in] */ IDispatch *pdispReserved, + /* [retval][out] */ HRESULT *dwRetVal) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetHostInfo( + /* [out][in] */ DWORD *pdwFlags, + /* [out][in] */ DWORD *pdwDoubleClick) = 0; + + virtual HRESULT STDMETHODCALLTYPE ShowUI( + /* [in] */ DWORD dwID, + /* [in] */ IUnknown *pActiveObject, + /* [in] */ IUnknown *pCommandTarget, + /* [in] */ IUnknown *pFrame, + /* [in] */ IUnknown *pDoc, + /* [retval][out] */ HRESULT *dwRetVal) = 0; + + virtual HRESULT STDMETHODCALLTYPE HideUI( void) = 0; + + virtual HRESULT STDMETHODCALLTYPE UpdateUI( void) = 0; + + virtual HRESULT STDMETHODCALLTYPE EnableModeless( + /* [in] */ VARIANT_BOOL fEnable) = 0; + + virtual HRESULT STDMETHODCALLTYPE OnDocWindowActivate( + /* [in] */ VARIANT_BOOL fActivate) = 0; + + virtual HRESULT STDMETHODCALLTYPE OnFrameWindowActivate( + /* [in] */ VARIANT_BOOL fActivate) = 0; + + virtual HRESULT STDMETHODCALLTYPE ResizeBorder( + /* [in] */ long left, + /* [in] */ long top, + /* [in] */ long right, + /* [in] */ long bottom, + /* [in] */ IUnknown *pUIWindow, + /* [in] */ VARIANT_BOOL fFrameWindow) = 0; + + virtual HRESULT STDMETHODCALLTYPE TranslateAccelerator( + /* [in] */ DWORD_PTR hWnd, + /* [in] */ DWORD nMessage, + /* [in] */ DWORD_PTR wParam, + /* [in] */ DWORD_PTR lParam, + /* [in] */ BSTR bstrGuidCmdGroup, + /* [in] */ DWORD nCmdID, + /* [retval][out] */ HRESULT *dwRetVal) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetOptionKeyPath( + /* [out] */ BSTR *pbstrKey, + /* [in] */ DWORD dw) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetDropTarget( + /* [in] */ IUnknown *pDropTarget, + /* [out] */ IUnknown **ppDropTarget) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetExternal( + /* [out] */ IDispatch **ppDispatch) = 0; + + virtual HRESULT STDMETHODCALLTYPE TranslateUrl( + /* [in] */ DWORD dwTranslate, + /* [in] */ BSTR bstrURLIn, + /* [out] */ BSTR *pbstrURLOut) = 0; + + virtual HRESULT STDMETHODCALLTYPE FilterDataObject( + /* [in] */ IUnknown *pDO, + /* [out] */ IUnknown **ppDORet) = 0; + + }; + +#else /* C style interface */ + + typedef struct IDocHostUIHandlerDispatchVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IDocHostUIHandlerDispatch * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IDocHostUIHandlerDispatch * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IDocHostUIHandlerDispatch * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IDocHostUIHandlerDispatch * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IDocHostUIHandlerDispatch * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IDocHostUIHandlerDispatch * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ _In_count_(cNames) LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IDocHostUIHandlerDispatch * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + HRESULT ( STDMETHODCALLTYPE *ShowContextMenu )( + IDocHostUIHandlerDispatch * This, + /* [in] */ DWORD dwID, + /* [in] */ DWORD x, + /* [in] */ DWORD y, + /* [in] */ IUnknown *pcmdtReserved, + /* [in] */ IDispatch *pdispReserved, + /* [retval][out] */ HRESULT *dwRetVal); + + HRESULT ( STDMETHODCALLTYPE *GetHostInfo )( + IDocHostUIHandlerDispatch * This, + /* [out][in] */ DWORD *pdwFlags, + /* [out][in] */ DWORD *pdwDoubleClick); + + HRESULT ( STDMETHODCALLTYPE *ShowUI )( + IDocHostUIHandlerDispatch * This, + /* [in] */ DWORD dwID, + /* [in] */ IUnknown *pActiveObject, + /* [in] */ IUnknown *pCommandTarget, + /* [in] */ IUnknown *pFrame, + /* [in] */ IUnknown *pDoc, + /* [retval][out] */ HRESULT *dwRetVal); + + HRESULT ( STDMETHODCALLTYPE *HideUI )( + IDocHostUIHandlerDispatch * This); + + HRESULT ( STDMETHODCALLTYPE *UpdateUI )( + IDocHostUIHandlerDispatch * This); + + HRESULT ( STDMETHODCALLTYPE *EnableModeless )( + IDocHostUIHandlerDispatch * This, + /* [in] */ VARIANT_BOOL fEnable); + + HRESULT ( STDMETHODCALLTYPE *OnDocWindowActivate )( + IDocHostUIHandlerDispatch * This, + /* [in] */ VARIANT_BOOL fActivate); + + HRESULT ( STDMETHODCALLTYPE *OnFrameWindowActivate )( + IDocHostUIHandlerDispatch * This, + /* [in] */ VARIANT_BOOL fActivate); + + HRESULT ( STDMETHODCALLTYPE *ResizeBorder )( + IDocHostUIHandlerDispatch * This, + /* [in] */ long left, + /* [in] */ long top, + /* [in] */ long right, + /* [in] */ long bottom, + /* [in] */ IUnknown *pUIWindow, + /* [in] */ VARIANT_BOOL fFrameWindow); + + HRESULT ( STDMETHODCALLTYPE *TranslateAccelerator )( + IDocHostUIHandlerDispatch * This, + /* [in] */ DWORD_PTR hWnd, + /* [in] */ DWORD nMessage, + /* [in] */ DWORD_PTR wParam, + /* [in] */ DWORD_PTR lParam, + /* [in] */ BSTR bstrGuidCmdGroup, + /* [in] */ DWORD nCmdID, + /* [retval][out] */ HRESULT *dwRetVal); + + HRESULT ( STDMETHODCALLTYPE *GetOptionKeyPath )( + IDocHostUIHandlerDispatch * This, + /* [out] */ BSTR *pbstrKey, + /* [in] */ DWORD dw); + + HRESULT ( STDMETHODCALLTYPE *GetDropTarget )( + IDocHostUIHandlerDispatch * This, + /* [in] */ IUnknown *pDropTarget, + /* [out] */ IUnknown **ppDropTarget); + + HRESULT ( STDMETHODCALLTYPE *GetExternal )( + IDocHostUIHandlerDispatch * This, + /* [out] */ IDispatch **ppDispatch); + + HRESULT ( STDMETHODCALLTYPE *TranslateUrl )( + IDocHostUIHandlerDispatch * This, + /* [in] */ DWORD dwTranslate, + /* [in] */ BSTR bstrURLIn, + /* [out] */ BSTR *pbstrURLOut); + + HRESULT ( STDMETHODCALLTYPE *FilterDataObject )( + IDocHostUIHandlerDispatch * This, + /* [in] */ IUnknown *pDO, + /* [out] */ IUnknown **ppDORet); + + END_INTERFACE + } IDocHostUIHandlerDispatchVtbl; + + interface IDocHostUIHandlerDispatch + { + CONST_VTBL struct IDocHostUIHandlerDispatchVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IDocHostUIHandlerDispatch_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IDocHostUIHandlerDispatch_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IDocHostUIHandlerDispatch_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IDocHostUIHandlerDispatch_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IDocHostUIHandlerDispatch_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IDocHostUIHandlerDispatch_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IDocHostUIHandlerDispatch_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IDocHostUIHandlerDispatch_ShowContextMenu(This,dwID,x,y,pcmdtReserved,pdispReserved,dwRetVal) \ + (This)->lpVtbl -> ShowContextMenu(This,dwID,x,y,pcmdtReserved,pdispReserved,dwRetVal) + +#define IDocHostUIHandlerDispatch_GetHostInfo(This,pdwFlags,pdwDoubleClick) \ + (This)->lpVtbl -> GetHostInfo(This,pdwFlags,pdwDoubleClick) + +#define IDocHostUIHandlerDispatch_ShowUI(This,dwID,pActiveObject,pCommandTarget,pFrame,pDoc,dwRetVal) \ + (This)->lpVtbl -> ShowUI(This,dwID,pActiveObject,pCommandTarget,pFrame,pDoc,dwRetVal) + +#define IDocHostUIHandlerDispatch_HideUI(This) \ + (This)->lpVtbl -> HideUI(This) + +#define IDocHostUIHandlerDispatch_UpdateUI(This) \ + (This)->lpVtbl -> UpdateUI(This) + +#define IDocHostUIHandlerDispatch_EnableModeless(This,fEnable) \ + (This)->lpVtbl -> EnableModeless(This,fEnable) + +#define IDocHostUIHandlerDispatch_OnDocWindowActivate(This,fActivate) \ + (This)->lpVtbl -> OnDocWindowActivate(This,fActivate) + +#define IDocHostUIHandlerDispatch_OnFrameWindowActivate(This,fActivate) \ + (This)->lpVtbl -> OnFrameWindowActivate(This,fActivate) + +#define IDocHostUIHandlerDispatch_ResizeBorder(This,left,top,right,bottom,pUIWindow,fFrameWindow) \ + (This)->lpVtbl -> ResizeBorder(This,left,top,right,bottom,pUIWindow,fFrameWindow) + +#define IDocHostUIHandlerDispatch_TranslateAccelerator(This,hWnd,nMessage,wParam,lParam,bstrGuidCmdGroup,nCmdID,dwRetVal) \ + (This)->lpVtbl -> TranslateAccelerator(This,hWnd,nMessage,wParam,lParam,bstrGuidCmdGroup,nCmdID,dwRetVal) + +#define IDocHostUIHandlerDispatch_GetOptionKeyPath(This,pbstrKey,dw) \ + (This)->lpVtbl -> GetOptionKeyPath(This,pbstrKey,dw) + +#define IDocHostUIHandlerDispatch_GetDropTarget(This,pDropTarget,ppDropTarget) \ + (This)->lpVtbl -> GetDropTarget(This,pDropTarget,ppDropTarget) + +#define IDocHostUIHandlerDispatch_GetExternal(This,ppDispatch) \ + (This)->lpVtbl -> GetExternal(This,ppDispatch) + +#define IDocHostUIHandlerDispatch_TranslateUrl(This,dwTranslate,bstrURLIn,pbstrURLOut) \ + (This)->lpVtbl -> TranslateUrl(This,dwTranslate,bstrURLIn,pbstrURLOut) + +#define IDocHostUIHandlerDispatch_FilterDataObject(This,pDO,ppDORet) \ + (This)->lpVtbl -> FilterDataObject(This,pDO,ppDORet) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_ShowContextMenu_Proxy( + IDocHostUIHandlerDispatch * This, + /* [in] */ DWORD dwID, + /* [in] */ DWORD x, + /* [in] */ DWORD y, + /* [in] */ IUnknown *pcmdtReserved, + /* [in] */ IDispatch *pdispReserved, + /* [retval][out] */ HRESULT *dwRetVal); + + +void __RPC_STUB IDocHostUIHandlerDispatch_ShowContextMenu_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_GetHostInfo_Proxy( + IDocHostUIHandlerDispatch * This, + /* [out][in] */ DWORD *pdwFlags, + /* [out][in] */ DWORD *pdwDoubleClick); + + +void __RPC_STUB IDocHostUIHandlerDispatch_GetHostInfo_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_ShowUI_Proxy( + IDocHostUIHandlerDispatch * This, + /* [in] */ DWORD dwID, + /* [in] */ IUnknown *pActiveObject, + /* [in] */ IUnknown *pCommandTarget, + /* [in] */ IUnknown *pFrame, + /* [in] */ IUnknown *pDoc, + /* [retval][out] */ HRESULT *dwRetVal); + + +void __RPC_STUB IDocHostUIHandlerDispatch_ShowUI_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_HideUI_Proxy( + IDocHostUIHandlerDispatch * This); + + +void __RPC_STUB IDocHostUIHandlerDispatch_HideUI_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_UpdateUI_Proxy( + IDocHostUIHandlerDispatch * This); + + +void __RPC_STUB IDocHostUIHandlerDispatch_UpdateUI_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_EnableModeless_Proxy( + IDocHostUIHandlerDispatch * This, + /* [in] */ VARIANT_BOOL fEnable); + + +void __RPC_STUB IDocHostUIHandlerDispatch_EnableModeless_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_OnDocWindowActivate_Proxy( + IDocHostUIHandlerDispatch * This, + /* [in] */ VARIANT_BOOL fActivate); + + +void __RPC_STUB IDocHostUIHandlerDispatch_OnDocWindowActivate_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_OnFrameWindowActivate_Proxy( + IDocHostUIHandlerDispatch * This, + /* [in] */ VARIANT_BOOL fActivate); + + +void __RPC_STUB IDocHostUIHandlerDispatch_OnFrameWindowActivate_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_ResizeBorder_Proxy( + IDocHostUIHandlerDispatch * This, + /* [in] */ long left, + /* [in] */ long top, + /* [in] */ long right, + /* [in] */ long bottom, + /* [in] */ IUnknown *pUIWindow, + /* [in] */ VARIANT_BOOL fFrameWindow); + + +void __RPC_STUB IDocHostUIHandlerDispatch_ResizeBorder_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_TranslateAccelerator_Proxy( + IDocHostUIHandlerDispatch * This, + /* [in] */ DWORD_PTR hWnd, + /* [in] */ DWORD nMessage, + /* [in] */ DWORD_PTR wParam, + /* [in] */ DWORD_PTR lParam, + /* [in] */ BSTR bstrGuidCmdGroup, + /* [in] */ DWORD nCmdID, + /* [retval][out] */ HRESULT *dwRetVal); + + +void __RPC_STUB IDocHostUIHandlerDispatch_TranslateAccelerator_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_GetOptionKeyPath_Proxy( + IDocHostUIHandlerDispatch * This, + /* [out] */ BSTR *pbstrKey, + /* [in] */ DWORD dw); + + +void __RPC_STUB IDocHostUIHandlerDispatch_GetOptionKeyPath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_GetDropTarget_Proxy( + IDocHostUIHandlerDispatch * This, + /* [in] */ IUnknown *pDropTarget, + /* [out] */ IUnknown **ppDropTarget); + + +void __RPC_STUB IDocHostUIHandlerDispatch_GetDropTarget_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_GetExternal_Proxy( + IDocHostUIHandlerDispatch * This, + /* [out] */ IDispatch **ppDispatch); + + +void __RPC_STUB IDocHostUIHandlerDispatch_GetExternal_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_TranslateUrl_Proxy( + IDocHostUIHandlerDispatch * This, + /* [in] */ DWORD dwTranslate, + /* [in] */ BSTR bstrURLIn, + /* [out] */ BSTR *pbstrURLOut); + + +void __RPC_STUB IDocHostUIHandlerDispatch_TranslateUrl_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IDocHostUIHandlerDispatch_FilterDataObject_Proxy( + IDocHostUIHandlerDispatch * This, + /* [in] */ IUnknown *pDO, + /* [out] */ IUnknown **ppDORet); + + +void __RPC_STUB IDocHostUIHandlerDispatch_FilterDataObject_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IDocHostUIHandlerDispatch_INTERFACE_DEFINED__ */ + + +#ifndef __IAxWinHostWindow_INTERFACE_DEFINED__ +#define __IAxWinHostWindow_INTERFACE_DEFINED__ + +/* interface IAxWinHostWindow */ +/* [object][unique][helpstring][uuid] */ + + +EXTERN_C const IID IID_IAxWinHostWindow; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("B6EA2050-048A-11d1-82B9-00C04FB9942E") + IAxWinHostWindow : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE CreateControl( + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream) = 0; + + virtual HRESULT STDMETHODCALLTYPE CreateControlEx( + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream, + /* [out] */ IUnknown **ppUnk, + /* [in] */ REFIID riidAdvise, + /* [in] */ IUnknown *punkAdvise) = 0; + + virtual HRESULT STDMETHODCALLTYPE AttachControl( + /* [in] */ IUnknown *pUnkControl, + /* [in] */ HWND hWnd) = 0; + + virtual HRESULT STDMETHODCALLTYPE QueryControl( + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject) = 0; + + virtual HRESULT STDMETHODCALLTYPE SetExternalDispatch( + /* [in] */ IDispatch *pDisp) = 0; + + virtual HRESULT STDMETHODCALLTYPE SetExternalUIHandler( + /* [in] */ IDocHostUIHandlerDispatch *pDisp) = 0; + + }; + +#else /* C style interface */ + + typedef struct IAxWinHostWindowVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IAxWinHostWindow * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IAxWinHostWindow * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IAxWinHostWindow * This); + + HRESULT ( STDMETHODCALLTYPE *CreateControl )( + IAxWinHostWindow * This, + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream); + + HRESULT ( STDMETHODCALLTYPE *CreateControlEx )( + IAxWinHostWindow * This, + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream, + /* [out] */ IUnknown **ppUnk, + /* [in] */ REFIID riidAdvise, + /* [in] */ IUnknown *punkAdvise); + + HRESULT ( STDMETHODCALLTYPE *AttachControl )( + IAxWinHostWindow * This, + /* [in] */ IUnknown *pUnkControl, + /* [in] */ HWND hWnd); + + HRESULT ( STDMETHODCALLTYPE *QueryControl )( + IAxWinHostWindow * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + HRESULT ( STDMETHODCALLTYPE *SetExternalDispatch )( + IAxWinHostWindow * This, + /* [in] */ IDispatch *pDisp); + + HRESULT ( STDMETHODCALLTYPE *SetExternalUIHandler )( + IAxWinHostWindow * This, + /* [in] */ IDocHostUIHandlerDispatch *pDisp); + + END_INTERFACE + } IAxWinHostWindowVtbl; + + interface IAxWinHostWindow + { + CONST_VTBL struct IAxWinHostWindowVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IAxWinHostWindow_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IAxWinHostWindow_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IAxWinHostWindow_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IAxWinHostWindow_CreateControl(This,lpTricsData,hWnd,pStream) \ + (This)->lpVtbl -> CreateControl(This,lpTricsData,hWnd,pStream) + +#define IAxWinHostWindow_CreateControlEx(This,lpTricsData,hWnd,pStream,ppUnk,riidAdvise,punkAdvise) \ + (This)->lpVtbl -> CreateControlEx(This,lpTricsData,hWnd,pStream,ppUnk,riidAdvise,punkAdvise) + +#define IAxWinHostWindow_AttachControl(This,pUnkControl,hWnd) \ + (This)->lpVtbl -> AttachControl(This,pUnkControl,hWnd) + +#define IAxWinHostWindow_QueryControl(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryControl(This,riid,ppvObject) + +#define IAxWinHostWindow_SetExternalDispatch(This,pDisp) \ + (This)->lpVtbl -> SetExternalDispatch(This,pDisp) + +#define IAxWinHostWindow_SetExternalUIHandler(This,pDisp) \ + (This)->lpVtbl -> SetExternalUIHandler(This,pDisp) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +HRESULT STDMETHODCALLTYPE IAxWinHostWindow_CreateControl_Proxy( + IAxWinHostWindow * This, + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream); + + +void __RPC_STUB IAxWinHostWindow_CreateControl_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IAxWinHostWindow_CreateControlEx_Proxy( + IAxWinHostWindow * This, + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream, + /* [out] */ IUnknown **ppUnk, + /* [in] */ REFIID riidAdvise, + /* [in] */ IUnknown *punkAdvise); + + +void __RPC_STUB IAxWinHostWindow_CreateControlEx_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IAxWinHostWindow_AttachControl_Proxy( + IAxWinHostWindow * This, + /* [in] */ IUnknown *pUnkControl, + /* [in] */ HWND hWnd); + + +void __RPC_STUB IAxWinHostWindow_AttachControl_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IAxWinHostWindow_QueryControl_Proxy( + IAxWinHostWindow * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + +void __RPC_STUB IAxWinHostWindow_QueryControl_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IAxWinHostWindow_SetExternalDispatch_Proxy( + IAxWinHostWindow * This, + /* [in] */ IDispatch *pDisp); + + +void __RPC_STUB IAxWinHostWindow_SetExternalDispatch_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IAxWinHostWindow_SetExternalUIHandler_Proxy( + IAxWinHostWindow * This, + /* [in] */ IDocHostUIHandlerDispatch *pDisp); + + +void __RPC_STUB IAxWinHostWindow_SetExternalUIHandler_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IAxWinHostWindow_INTERFACE_DEFINED__ */ + + +#ifndef __IAxWinHostWindowLic_INTERFACE_DEFINED__ +#define __IAxWinHostWindowLic_INTERFACE_DEFINED__ + +/* interface IAxWinHostWindowLic */ +/* [object][unique][helpstring][uuid] */ + + +EXTERN_C const IID IID_IAxWinHostWindowLic; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("3935BDA8-4ED9-495c-8650-E01FC1E38A4B") + IAxWinHostWindowLic : public IAxWinHostWindow + { + public: + virtual HRESULT STDMETHODCALLTYPE CreateControlLic( + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream, + /* [in] */ BSTR bstrLic) = 0; + + virtual HRESULT STDMETHODCALLTYPE CreateControlLicEx( + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream, + /* [out] */ IUnknown **ppUnk, + /* [in] */ REFIID riidAdvise, + /* [in] */ IUnknown *punkAdvise, + /* [in] */ BSTR bstrLic) = 0; + + }; + +#else /* C style interface */ + + typedef struct IAxWinHostWindowLicVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IAxWinHostWindowLic * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IAxWinHostWindowLic * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IAxWinHostWindowLic * This); + + HRESULT ( STDMETHODCALLTYPE *CreateControl )( + IAxWinHostWindowLic * This, + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream); + + HRESULT ( STDMETHODCALLTYPE *CreateControlEx )( + IAxWinHostWindowLic * This, + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream, + /* [out] */ IUnknown **ppUnk, + /* [in] */ REFIID riidAdvise, + /* [in] */ IUnknown *punkAdvise); + + HRESULT ( STDMETHODCALLTYPE *AttachControl )( + IAxWinHostWindowLic * This, + /* [in] */ IUnknown *pUnkControl, + /* [in] */ HWND hWnd); + + HRESULT ( STDMETHODCALLTYPE *QueryControl )( + IAxWinHostWindowLic * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + HRESULT ( STDMETHODCALLTYPE *SetExternalDispatch )( + IAxWinHostWindowLic * This, + /* [in] */ IDispatch *pDisp); + + HRESULT ( STDMETHODCALLTYPE *SetExternalUIHandler )( + IAxWinHostWindowLic * This, + /* [in] */ IDocHostUIHandlerDispatch *pDisp); + + HRESULT ( STDMETHODCALLTYPE *CreateControlLic )( + IAxWinHostWindowLic * This, + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream, + /* [in] */ BSTR bstrLic); + + HRESULT ( STDMETHODCALLTYPE *CreateControlLicEx )( + IAxWinHostWindowLic * This, + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream, + /* [out] */ IUnknown **ppUnk, + /* [in] */ REFIID riidAdvise, + /* [in] */ IUnknown *punkAdvise, + /* [in] */ BSTR bstrLic); + + END_INTERFACE + } IAxWinHostWindowLicVtbl; + + interface IAxWinHostWindowLic + { + CONST_VTBL struct IAxWinHostWindowLicVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IAxWinHostWindowLic_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IAxWinHostWindowLic_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IAxWinHostWindowLic_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IAxWinHostWindowLic_CreateControl(This,lpTricsData,hWnd,pStream) \ + (This)->lpVtbl -> CreateControl(This,lpTricsData,hWnd,pStream) + +#define IAxWinHostWindowLic_CreateControlEx(This,lpTricsData,hWnd,pStream,ppUnk,riidAdvise,punkAdvise) \ + (This)->lpVtbl -> CreateControlEx(This,lpTricsData,hWnd,pStream,ppUnk,riidAdvise,punkAdvise) + +#define IAxWinHostWindowLic_AttachControl(This,pUnkControl,hWnd) \ + (This)->lpVtbl -> AttachControl(This,pUnkControl,hWnd) + +#define IAxWinHostWindowLic_QueryControl(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryControl(This,riid,ppvObject) + +#define IAxWinHostWindowLic_SetExternalDispatch(This,pDisp) \ + (This)->lpVtbl -> SetExternalDispatch(This,pDisp) + +#define IAxWinHostWindowLic_SetExternalUIHandler(This,pDisp) \ + (This)->lpVtbl -> SetExternalUIHandler(This,pDisp) + + +#define IAxWinHostWindowLic_CreateControlLic(This,lpTricsData,hWnd,pStream,bstrLic) \ + (This)->lpVtbl -> CreateControlLic(This,lpTricsData,hWnd,pStream,bstrLic) + +#define IAxWinHostWindowLic_CreateControlLicEx(This,lpTricsData,hWnd,pStream,ppUnk,riidAdvise,punkAdvise,bstrLic) \ + (This)->lpVtbl -> CreateControlLicEx(This,lpTricsData,hWnd,pStream,ppUnk,riidAdvise,punkAdvise,bstrLic) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +HRESULT STDMETHODCALLTYPE IAxWinHostWindowLic_CreateControlLic_Proxy( + IAxWinHostWindowLic * This, + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream, + /* [in] */ BSTR bstrLic); + + +void __RPC_STUB IAxWinHostWindowLic_CreateControlLic_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IAxWinHostWindowLic_CreateControlLicEx_Proxy( + IAxWinHostWindowLic * This, + /* [in] */ LPCOLESTR lpTricsData, + /* [in] */ HWND hWnd, + /* [in] */ IStream *pStream, + /* [out] */ IUnknown **ppUnk, + /* [in] */ REFIID riidAdvise, + /* [in] */ IUnknown *punkAdvise, + /* [in] */ BSTR bstrLic); + + +void __RPC_STUB IAxWinHostWindowLic_CreateControlLicEx_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IAxWinHostWindowLic_INTERFACE_DEFINED__ */ + + +#ifndef __IAxWinAmbientDispatch_INTERFACE_DEFINED__ +#define __IAxWinAmbientDispatch_INTERFACE_DEFINED__ + +/* interface IAxWinAmbientDispatch */ +/* [unique][helpstring][uuid][dual][object] */ + + +EXTERN_C const IID IID_IAxWinAmbientDispatch; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("B6EA2051-048A-11d1-82B9-00C04FB9942E") + IAxWinAmbientDispatch : public IDispatch + { + public: + virtual /* [helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_AllowWindowlessActivation( + /* [in] */ VARIANT_BOOL bCanWindowlessActivate) = 0; + + virtual /* [helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_AllowWindowlessActivation( + /* [retval][out] */ VARIANT_BOOL *pbCanWindowlessActivate) = 0; + + virtual /* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_BackColor( + /* [in] */ OLE_COLOR clrBackground) = 0; + + virtual /* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_BackColor( + /* [retval][out] */ OLE_COLOR *pclrBackground) = 0; + + virtual /* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_ForeColor( + /* [in] */ OLE_COLOR clrForeground) = 0; + + virtual /* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_ForeColor( + /* [retval][out] */ OLE_COLOR *pclrForeground) = 0; + + virtual /* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_LocaleID( + /* [in] */ LCID lcidLocaleID) = 0; + + virtual /* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_LocaleID( + /* [retval][out] */ LCID *plcidLocaleID) = 0; + + virtual /* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_UserMode( + /* [in] */ VARIANT_BOOL bUserMode) = 0; + + virtual /* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_UserMode( + /* [retval][out] */ VARIANT_BOOL *pbUserMode) = 0; + + virtual /* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_DisplayAsDefault( + /* [in] */ VARIANT_BOOL bDisplayAsDefault) = 0; + + virtual /* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_DisplayAsDefault( + /* [retval][out] */ VARIANT_BOOL *pbDisplayAsDefault) = 0; + + virtual /* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_Font( + /* [in] */ IFontDisp *pFont) = 0; + + virtual /* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_Font( + /* [retval][out] */ IFontDisp **pFont) = 0; + + virtual /* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_MessageReflect( + /* [in] */ VARIANT_BOOL bMsgReflect) = 0; + + virtual /* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_MessageReflect( + /* [retval][out] */ VARIANT_BOOL *pbMsgReflect) = 0; + + virtual /* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_ShowGrabHandles( + /* [retval][out] */ VARIANT_BOOL *pbShowGrabHandles) = 0; + + virtual /* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_ShowHatching( + /* [retval][out] */ VARIANT_BOOL *pbShowHatching) = 0; + + virtual /* [helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_DocHostFlags( + /* [in] */ DWORD dwDocHostFlags) = 0; + + virtual /* [helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_DocHostFlags( + /* [retval][out] */ DWORD *pdwDocHostFlags) = 0; + + virtual /* [helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_DocHostDoubleClickFlags( + /* [in] */ DWORD dwDocHostDoubleClickFlags) = 0; + + virtual /* [helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_DocHostDoubleClickFlags( + /* [retval][out] */ DWORD *pdwDocHostDoubleClickFlags) = 0; + + virtual /* [helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_AllowContextMenu( + /* [in] */ VARIANT_BOOL bAllowContextMenu) = 0; + + virtual /* [helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_AllowContextMenu( + /* [retval][out] */ VARIANT_BOOL *pbAllowContextMenu) = 0; + + virtual /* [helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_AllowShowUI( + /* [in] */ VARIANT_BOOL bAllowShowUI) = 0; + + virtual /* [helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_AllowShowUI( + /* [retval][out] */ VARIANT_BOOL *pbAllowShowUI) = 0; + + virtual /* [helpstring][propput] */ HRESULT STDMETHODCALLTYPE put_OptionKeyPath( + /* [in] */ BSTR bstrOptionKeyPath) = 0; + + virtual /* [helpstring][propget] */ HRESULT STDMETHODCALLTYPE get_OptionKeyPath( + /* [retval][out] */ BSTR *pbstrOptionKeyPath) = 0; + + }; + +#else /* C style interface */ + + typedef struct IAxWinAmbientDispatchVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IAxWinAmbientDispatch * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IAxWinAmbientDispatch * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IAxWinAmbientDispatch * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IAxWinAmbientDispatch * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IAxWinAmbientDispatch * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IAxWinAmbientDispatch * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ _In_count_(cNames) LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IAxWinAmbientDispatch * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_AllowWindowlessActivation )( + IAxWinAmbientDispatch * This, + /* [in] */ VARIANT_BOOL bCanWindowlessActivate); + + /* [helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_AllowWindowlessActivation )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbCanWindowlessActivate); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_BackColor )( + IAxWinAmbientDispatch * This, + /* [in] */ OLE_COLOR clrBackground); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_BackColor )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ OLE_COLOR *pclrBackground); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_ForeColor )( + IAxWinAmbientDispatch * This, + /* [in] */ OLE_COLOR clrForeground); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ForeColor )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ OLE_COLOR *pclrForeground); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_LocaleID )( + IAxWinAmbientDispatch * This, + /* [in] */ LCID lcidLocaleID); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_LocaleID )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ LCID *plcidLocaleID); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_UserMode )( + IAxWinAmbientDispatch * This, + /* [in] */ VARIANT_BOOL bUserMode); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_UserMode )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbUserMode); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_DisplayAsDefault )( + IAxWinAmbientDispatch * This, + /* [in] */ VARIANT_BOOL bDisplayAsDefault); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_DisplayAsDefault )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbDisplayAsDefault); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_Font )( + IAxWinAmbientDispatch * This, + /* [in] */ IFontDisp *pFont); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Font )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ IFontDisp **pFont); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_MessageReflect )( + IAxWinAmbientDispatch * This, + /* [in] */ VARIANT_BOOL bMsgReflect); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_MessageReflect )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbMsgReflect); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ShowGrabHandles )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbShowGrabHandles); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ShowHatching )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbShowHatching); + + /* [helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_DocHostFlags )( + IAxWinAmbientDispatch * This, + /* [in] */ DWORD dwDocHostFlags); + + /* [helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_DocHostFlags )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ DWORD *pdwDocHostFlags); + + /* [helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_DocHostDoubleClickFlags )( + IAxWinAmbientDispatch * This, + /* [in] */ DWORD dwDocHostDoubleClickFlags); + + /* [helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_DocHostDoubleClickFlags )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ DWORD *pdwDocHostDoubleClickFlags); + + /* [helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_AllowContextMenu )( + IAxWinAmbientDispatch * This, + /* [in] */ VARIANT_BOOL bAllowContextMenu); + + /* [helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_AllowContextMenu )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbAllowContextMenu); + + /* [helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_AllowShowUI )( + IAxWinAmbientDispatch * This, + /* [in] */ VARIANT_BOOL bAllowShowUI); + + /* [helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_AllowShowUI )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbAllowShowUI); + + /* [helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_OptionKeyPath )( + IAxWinAmbientDispatch * This, + /* [in] */ BSTR bstrOptionKeyPath); + + /* [helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_OptionKeyPath )( + IAxWinAmbientDispatch * This, + /* [retval][out] */ BSTR *pbstrOptionKeyPath); + + END_INTERFACE + } IAxWinAmbientDispatchVtbl; + + interface IAxWinAmbientDispatch + { + CONST_VTBL struct IAxWinAmbientDispatchVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IAxWinAmbientDispatch_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IAxWinAmbientDispatch_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IAxWinAmbientDispatch_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IAxWinAmbientDispatch_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IAxWinAmbientDispatch_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IAxWinAmbientDispatch_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IAxWinAmbientDispatch_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IAxWinAmbientDispatch_put_AllowWindowlessActivation(This,bCanWindowlessActivate) \ + (This)->lpVtbl -> put_AllowWindowlessActivation(This,bCanWindowlessActivate) + +#define IAxWinAmbientDispatch_get_AllowWindowlessActivation(This,pbCanWindowlessActivate) \ + (This)->lpVtbl -> get_AllowWindowlessActivation(This,pbCanWindowlessActivate) + +#define IAxWinAmbientDispatch_put_BackColor(This,clrBackground) \ + (This)->lpVtbl -> put_BackColor(This,clrBackground) + +#define IAxWinAmbientDispatch_get_BackColor(This,pclrBackground) \ + (This)->lpVtbl -> get_BackColor(This,pclrBackground) + +#define IAxWinAmbientDispatch_put_ForeColor(This,clrForeground) \ + (This)->lpVtbl -> put_ForeColor(This,clrForeground) + +#define IAxWinAmbientDispatch_get_ForeColor(This,pclrForeground) \ + (This)->lpVtbl -> get_ForeColor(This,pclrForeground) + +#define IAxWinAmbientDispatch_put_LocaleID(This,lcidLocaleID) \ + (This)->lpVtbl -> put_LocaleID(This,lcidLocaleID) + +#define IAxWinAmbientDispatch_get_LocaleID(This,plcidLocaleID) \ + (This)->lpVtbl -> get_LocaleID(This,plcidLocaleID) + +#define IAxWinAmbientDispatch_put_UserMode(This,bUserMode) \ + (This)->lpVtbl -> put_UserMode(This,bUserMode) + +#define IAxWinAmbientDispatch_get_UserMode(This,pbUserMode) \ + (This)->lpVtbl -> get_UserMode(This,pbUserMode) + +#define IAxWinAmbientDispatch_put_DisplayAsDefault(This,bDisplayAsDefault) \ + (This)->lpVtbl -> put_DisplayAsDefault(This,bDisplayAsDefault) + +#define IAxWinAmbientDispatch_get_DisplayAsDefault(This,pbDisplayAsDefault) \ + (This)->lpVtbl -> get_DisplayAsDefault(This,pbDisplayAsDefault) + +#define IAxWinAmbientDispatch_put_Font(This,pFont) \ + (This)->lpVtbl -> put_Font(This,pFont) + +#define IAxWinAmbientDispatch_get_Font(This,pFont) \ + (This)->lpVtbl -> get_Font(This,pFont) + +#define IAxWinAmbientDispatch_put_MessageReflect(This,bMsgReflect) \ + (This)->lpVtbl -> put_MessageReflect(This,bMsgReflect) + +#define IAxWinAmbientDispatch_get_MessageReflect(This,pbMsgReflect) \ + (This)->lpVtbl -> get_MessageReflect(This,pbMsgReflect) + +#define IAxWinAmbientDispatch_get_ShowGrabHandles(This,pbShowGrabHandles) \ + (This)->lpVtbl -> get_ShowGrabHandles(This,pbShowGrabHandles) + +#define IAxWinAmbientDispatch_get_ShowHatching(This,pbShowHatching) \ + (This)->lpVtbl -> get_ShowHatching(This,pbShowHatching) + +#define IAxWinAmbientDispatch_put_DocHostFlags(This,dwDocHostFlags) \ + (This)->lpVtbl -> put_DocHostFlags(This,dwDocHostFlags) + +#define IAxWinAmbientDispatch_get_DocHostFlags(This,pdwDocHostFlags) \ + (This)->lpVtbl -> get_DocHostFlags(This,pdwDocHostFlags) + +#define IAxWinAmbientDispatch_put_DocHostDoubleClickFlags(This,dwDocHostDoubleClickFlags) \ + (This)->lpVtbl -> put_DocHostDoubleClickFlags(This,dwDocHostDoubleClickFlags) + +#define IAxWinAmbientDispatch_get_DocHostDoubleClickFlags(This,pdwDocHostDoubleClickFlags) \ + (This)->lpVtbl -> get_DocHostDoubleClickFlags(This,pdwDocHostDoubleClickFlags) + +#define IAxWinAmbientDispatch_put_AllowContextMenu(This,bAllowContextMenu) \ + (This)->lpVtbl -> put_AllowContextMenu(This,bAllowContextMenu) + +#define IAxWinAmbientDispatch_get_AllowContextMenu(This,pbAllowContextMenu) \ + (This)->lpVtbl -> get_AllowContextMenu(This,pbAllowContextMenu) + +#define IAxWinAmbientDispatch_put_AllowShowUI(This,bAllowShowUI) \ + (This)->lpVtbl -> put_AllowShowUI(This,bAllowShowUI) + +#define IAxWinAmbientDispatch_get_AllowShowUI(This,pbAllowShowUI) \ + (This)->lpVtbl -> get_AllowShowUI(This,pbAllowShowUI) + +#define IAxWinAmbientDispatch_put_OptionKeyPath(This,bstrOptionKeyPath) \ + (This)->lpVtbl -> put_OptionKeyPath(This,bstrOptionKeyPath) + +#define IAxWinAmbientDispatch_get_OptionKeyPath(This,pbstrOptionKeyPath) \ + (This)->lpVtbl -> get_OptionKeyPath(This,pbstrOptionKeyPath) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_AllowWindowlessActivation_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ VARIANT_BOOL bCanWindowlessActivate); + + +void __RPC_STUB IAxWinAmbientDispatch_put_AllowWindowlessActivation_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_AllowWindowlessActivation_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbCanWindowlessActivate); + + +void __RPC_STUB IAxWinAmbientDispatch_get_AllowWindowlessActivation_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_BackColor_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ OLE_COLOR clrBackground); + + +void __RPC_STUB IAxWinAmbientDispatch_put_BackColor_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_BackColor_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ OLE_COLOR *pclrBackground); + + +void __RPC_STUB IAxWinAmbientDispatch_get_BackColor_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_ForeColor_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ OLE_COLOR clrForeground); + + +void __RPC_STUB IAxWinAmbientDispatch_put_ForeColor_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_ForeColor_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ OLE_COLOR *pclrForeground); + + +void __RPC_STUB IAxWinAmbientDispatch_get_ForeColor_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_LocaleID_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ LCID lcidLocaleID); + + +void __RPC_STUB IAxWinAmbientDispatch_put_LocaleID_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_LocaleID_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ LCID *plcidLocaleID); + + +void __RPC_STUB IAxWinAmbientDispatch_get_LocaleID_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_UserMode_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ VARIANT_BOOL bUserMode); + + +void __RPC_STUB IAxWinAmbientDispatch_put_UserMode_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_UserMode_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbUserMode); + + +void __RPC_STUB IAxWinAmbientDispatch_get_UserMode_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_DisplayAsDefault_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ VARIANT_BOOL bDisplayAsDefault); + + +void __RPC_STUB IAxWinAmbientDispatch_put_DisplayAsDefault_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_DisplayAsDefault_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbDisplayAsDefault); + + +void __RPC_STUB IAxWinAmbientDispatch_get_DisplayAsDefault_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_Font_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ IFontDisp *pFont); + + +void __RPC_STUB IAxWinAmbientDispatch_put_Font_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_Font_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ IFontDisp **pFont); + + +void __RPC_STUB IAxWinAmbientDispatch_get_Font_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_MessageReflect_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ VARIANT_BOOL bMsgReflect); + + +void __RPC_STUB IAxWinAmbientDispatch_put_MessageReflect_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_MessageReflect_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbMsgReflect); + + +void __RPC_STUB IAxWinAmbientDispatch_get_MessageReflect_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_ShowGrabHandles_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbShowGrabHandles); + + +void __RPC_STUB IAxWinAmbientDispatch_get_ShowGrabHandles_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_ShowHatching_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbShowHatching); + + +void __RPC_STUB IAxWinAmbientDispatch_get_ShowHatching_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_DocHostFlags_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ DWORD dwDocHostFlags); + + +void __RPC_STUB IAxWinAmbientDispatch_put_DocHostFlags_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_DocHostFlags_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ DWORD *pdwDocHostFlags); + + +void __RPC_STUB IAxWinAmbientDispatch_get_DocHostFlags_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_DocHostDoubleClickFlags_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ DWORD dwDocHostDoubleClickFlags); + + +void __RPC_STUB IAxWinAmbientDispatch_put_DocHostDoubleClickFlags_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_DocHostDoubleClickFlags_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ DWORD *pdwDocHostDoubleClickFlags); + + +void __RPC_STUB IAxWinAmbientDispatch_get_DocHostDoubleClickFlags_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_AllowContextMenu_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ VARIANT_BOOL bAllowContextMenu); + + +void __RPC_STUB IAxWinAmbientDispatch_put_AllowContextMenu_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_AllowContextMenu_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbAllowContextMenu); + + +void __RPC_STUB IAxWinAmbientDispatch_get_AllowContextMenu_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_AllowShowUI_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ VARIANT_BOOL bAllowShowUI); + + +void __RPC_STUB IAxWinAmbientDispatch_put_AllowShowUI_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_AllowShowUI_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ VARIANT_BOOL *pbAllowShowUI); + + +void __RPC_STUB IAxWinAmbientDispatch_get_AllowShowUI_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][propput] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_put_OptionKeyPath_Proxy( + IAxWinAmbientDispatch * This, + /* [in] */ BSTR bstrOptionKeyPath); + + +void __RPC_STUB IAxWinAmbientDispatch_put_OptionKeyPath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][propget] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatch_get_OptionKeyPath_Proxy( + IAxWinAmbientDispatch * This, + /* [retval][out] */ BSTR *pbstrOptionKeyPath); + + +void __RPC_STUB IAxWinAmbientDispatch_get_OptionKeyPath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IAxWinAmbientDispatch_INTERFACE_DEFINED__ */ + + +#ifndef __IAxWinAmbientDispatchEx_INTERFACE_DEFINED__ +#define __IAxWinAmbientDispatchEx_INTERFACE_DEFINED__ + +/* interface IAxWinAmbientDispatchEx */ +/* [unique][helpstring][uuid][dual][object] */ + + +EXTERN_C const IID IID_IAxWinAmbientDispatchEx; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("B2D0778B-AC99-4c58-A5C8-E7724E5316B5") + IAxWinAmbientDispatchEx : public IAxWinAmbientDispatch + { + public: + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetAmbientDispatch( + /* [in] */ IDispatch *pDispatch) = 0; + + }; + +#else /* C style interface */ + + typedef struct IAxWinAmbientDispatchExVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IAxWinAmbientDispatchEx * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IAxWinAmbientDispatchEx * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IAxWinAmbientDispatchEx * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IAxWinAmbientDispatchEx * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IAxWinAmbientDispatchEx * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IAxWinAmbientDispatchEx * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ _In_count_(cNames) LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IAxWinAmbientDispatchEx * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_AllowWindowlessActivation )( + IAxWinAmbientDispatchEx * This, + /* [in] */ VARIANT_BOOL bCanWindowlessActivate); + + /* [helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_AllowWindowlessActivation )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ VARIANT_BOOL *pbCanWindowlessActivate); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_BackColor )( + IAxWinAmbientDispatchEx * This, + /* [in] */ OLE_COLOR clrBackground); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_BackColor )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ OLE_COLOR *pclrBackground); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_ForeColor )( + IAxWinAmbientDispatchEx * This, + /* [in] */ OLE_COLOR clrForeground); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ForeColor )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ OLE_COLOR *pclrForeground); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_LocaleID )( + IAxWinAmbientDispatchEx * This, + /* [in] */ LCID lcidLocaleID); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_LocaleID )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ LCID *plcidLocaleID); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_UserMode )( + IAxWinAmbientDispatchEx * This, + /* [in] */ VARIANT_BOOL bUserMode); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_UserMode )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ VARIANT_BOOL *pbUserMode); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_DisplayAsDefault )( + IAxWinAmbientDispatchEx * This, + /* [in] */ VARIANT_BOOL bDisplayAsDefault); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_DisplayAsDefault )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ VARIANT_BOOL *pbDisplayAsDefault); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_Font )( + IAxWinAmbientDispatchEx * This, + /* [in] */ IFontDisp *pFont); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Font )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ IFontDisp **pFont); + + /* [id][helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_MessageReflect )( + IAxWinAmbientDispatchEx * This, + /* [in] */ VARIANT_BOOL bMsgReflect); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_MessageReflect )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ VARIANT_BOOL *pbMsgReflect); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ShowGrabHandles )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ VARIANT_BOOL *pbShowGrabHandles); + + /* [id][helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ShowHatching )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ VARIANT_BOOL *pbShowHatching); + + /* [helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_DocHostFlags )( + IAxWinAmbientDispatchEx * This, + /* [in] */ DWORD dwDocHostFlags); + + /* [helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_DocHostFlags )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ DWORD *pdwDocHostFlags); + + /* [helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_DocHostDoubleClickFlags )( + IAxWinAmbientDispatchEx * This, + /* [in] */ DWORD dwDocHostDoubleClickFlags); + + /* [helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_DocHostDoubleClickFlags )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ DWORD *pdwDocHostDoubleClickFlags); + + /* [helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_AllowContextMenu )( + IAxWinAmbientDispatchEx * This, + /* [in] */ VARIANT_BOOL bAllowContextMenu); + + /* [helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_AllowContextMenu )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ VARIANT_BOOL *pbAllowContextMenu); + + /* [helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_AllowShowUI )( + IAxWinAmbientDispatchEx * This, + /* [in] */ VARIANT_BOOL bAllowShowUI); + + /* [helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_AllowShowUI )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ VARIANT_BOOL *pbAllowShowUI); + + /* [helpstring][propput] */ HRESULT ( STDMETHODCALLTYPE *put_OptionKeyPath )( + IAxWinAmbientDispatchEx * This, + /* [in] */ BSTR bstrOptionKeyPath); + + /* [helpstring][propget] */ HRESULT ( STDMETHODCALLTYPE *get_OptionKeyPath )( + IAxWinAmbientDispatchEx * This, + /* [retval][out] */ BSTR *pbstrOptionKeyPath); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetAmbientDispatch )( + IAxWinAmbientDispatchEx * This, + /* [in] */ IDispatch *pDispatch); + + END_INTERFACE + } IAxWinAmbientDispatchExVtbl; + + interface IAxWinAmbientDispatchEx + { + CONST_VTBL struct IAxWinAmbientDispatchExVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IAxWinAmbientDispatchEx_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IAxWinAmbientDispatchEx_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IAxWinAmbientDispatchEx_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IAxWinAmbientDispatchEx_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IAxWinAmbientDispatchEx_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IAxWinAmbientDispatchEx_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IAxWinAmbientDispatchEx_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IAxWinAmbientDispatchEx_put_AllowWindowlessActivation(This,bCanWindowlessActivate) \ + (This)->lpVtbl -> put_AllowWindowlessActivation(This,bCanWindowlessActivate) + +#define IAxWinAmbientDispatchEx_get_AllowWindowlessActivation(This,pbCanWindowlessActivate) \ + (This)->lpVtbl -> get_AllowWindowlessActivation(This,pbCanWindowlessActivate) + +#define IAxWinAmbientDispatchEx_put_BackColor(This,clrBackground) \ + (This)->lpVtbl -> put_BackColor(This,clrBackground) + +#define IAxWinAmbientDispatchEx_get_BackColor(This,pclrBackground) \ + (This)->lpVtbl -> get_BackColor(This,pclrBackground) + +#define IAxWinAmbientDispatchEx_put_ForeColor(This,clrForeground) \ + (This)->lpVtbl -> put_ForeColor(This,clrForeground) + +#define IAxWinAmbientDispatchEx_get_ForeColor(This,pclrForeground) \ + (This)->lpVtbl -> get_ForeColor(This,pclrForeground) + +#define IAxWinAmbientDispatchEx_put_LocaleID(This,lcidLocaleID) \ + (This)->lpVtbl -> put_LocaleID(This,lcidLocaleID) + +#define IAxWinAmbientDispatchEx_get_LocaleID(This,plcidLocaleID) \ + (This)->lpVtbl -> get_LocaleID(This,plcidLocaleID) + +#define IAxWinAmbientDispatchEx_put_UserMode(This,bUserMode) \ + (This)->lpVtbl -> put_UserMode(This,bUserMode) + +#define IAxWinAmbientDispatchEx_get_UserMode(This,pbUserMode) \ + (This)->lpVtbl -> get_UserMode(This,pbUserMode) + +#define IAxWinAmbientDispatchEx_put_DisplayAsDefault(This,bDisplayAsDefault) \ + (This)->lpVtbl -> put_DisplayAsDefault(This,bDisplayAsDefault) + +#define IAxWinAmbientDispatchEx_get_DisplayAsDefault(This,pbDisplayAsDefault) \ + (This)->lpVtbl -> get_DisplayAsDefault(This,pbDisplayAsDefault) + +#define IAxWinAmbientDispatchEx_put_Font(This,pFont) \ + (This)->lpVtbl -> put_Font(This,pFont) + +#define IAxWinAmbientDispatchEx_get_Font(This,pFont) \ + (This)->lpVtbl -> get_Font(This,pFont) + +#define IAxWinAmbientDispatchEx_put_MessageReflect(This,bMsgReflect) \ + (This)->lpVtbl -> put_MessageReflect(This,bMsgReflect) + +#define IAxWinAmbientDispatchEx_get_MessageReflect(This,pbMsgReflect) \ + (This)->lpVtbl -> get_MessageReflect(This,pbMsgReflect) + +#define IAxWinAmbientDispatchEx_get_ShowGrabHandles(This,pbShowGrabHandles) \ + (This)->lpVtbl -> get_ShowGrabHandles(This,pbShowGrabHandles) + +#define IAxWinAmbientDispatchEx_get_ShowHatching(This,pbShowHatching) \ + (This)->lpVtbl -> get_ShowHatching(This,pbShowHatching) + +#define IAxWinAmbientDispatchEx_put_DocHostFlags(This,dwDocHostFlags) \ + (This)->lpVtbl -> put_DocHostFlags(This,dwDocHostFlags) + +#define IAxWinAmbientDispatchEx_get_DocHostFlags(This,pdwDocHostFlags) \ + (This)->lpVtbl -> get_DocHostFlags(This,pdwDocHostFlags) + +#define IAxWinAmbientDispatchEx_put_DocHostDoubleClickFlags(This,dwDocHostDoubleClickFlags) \ + (This)->lpVtbl -> put_DocHostDoubleClickFlags(This,dwDocHostDoubleClickFlags) + +#define IAxWinAmbientDispatchEx_get_DocHostDoubleClickFlags(This,pdwDocHostDoubleClickFlags) \ + (This)->lpVtbl -> get_DocHostDoubleClickFlags(This,pdwDocHostDoubleClickFlags) + +#define IAxWinAmbientDispatchEx_put_AllowContextMenu(This,bAllowContextMenu) \ + (This)->lpVtbl -> put_AllowContextMenu(This,bAllowContextMenu) + +#define IAxWinAmbientDispatchEx_get_AllowContextMenu(This,pbAllowContextMenu) \ + (This)->lpVtbl -> get_AllowContextMenu(This,pbAllowContextMenu) + +#define IAxWinAmbientDispatchEx_put_AllowShowUI(This,bAllowShowUI) \ + (This)->lpVtbl -> put_AllowShowUI(This,bAllowShowUI) + +#define IAxWinAmbientDispatchEx_get_AllowShowUI(This,pbAllowShowUI) \ + (This)->lpVtbl -> get_AllowShowUI(This,pbAllowShowUI) + +#define IAxWinAmbientDispatchEx_put_OptionKeyPath(This,bstrOptionKeyPath) \ + (This)->lpVtbl -> put_OptionKeyPath(This,bstrOptionKeyPath) + +#define IAxWinAmbientDispatchEx_get_OptionKeyPath(This,pbstrOptionKeyPath) \ + (This)->lpVtbl -> get_OptionKeyPath(This,pbstrOptionKeyPath) + + +#define IAxWinAmbientDispatchEx_SetAmbientDispatch(This,pDispatch) \ + (This)->lpVtbl -> SetAmbientDispatch(This,pDispatch) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id] */ HRESULT STDMETHODCALLTYPE IAxWinAmbientDispatchEx_SetAmbientDispatch_Proxy( + IAxWinAmbientDispatchEx * This, + /* [in] */ IDispatch *pDispatch); + + +void __RPC_STUB IAxWinAmbientDispatchEx_SetAmbientDispatch_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IAxWinAmbientDispatchEx_INTERFACE_DEFINED__ */ + + +#ifndef __IInternalConnection_INTERFACE_DEFINED__ +#define __IInternalConnection_INTERFACE_DEFINED__ + +/* interface IInternalConnection */ +/* [object][unique][helpstring][uuid] */ + + +EXTERN_C const IID IID_IInternalConnection; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("72AD0770-6A9F-11d1-BCEC-0060088F444E") + IInternalConnection : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE AddConnection( void) = 0; + + virtual HRESULT STDMETHODCALLTYPE ReleaseConnection( void) = 0; + + }; + +#else /* C style interface */ + + typedef struct IInternalConnectionVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IInternalConnection * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IInternalConnection * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IInternalConnection * This); + + HRESULT ( STDMETHODCALLTYPE *AddConnection )( + IInternalConnection * This); + + HRESULT ( STDMETHODCALLTYPE *ReleaseConnection )( + IInternalConnection * This); + + END_INTERFACE + } IInternalConnectionVtbl; + + interface IInternalConnection + { + CONST_VTBL struct IInternalConnectionVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IInternalConnection_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IInternalConnection_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IInternalConnection_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IInternalConnection_AddConnection(This) \ + (This)->lpVtbl -> AddConnection(This) + +#define IInternalConnection_ReleaseConnection(This) \ + (This)->lpVtbl -> ReleaseConnection(This) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + +HRESULT STDMETHODCALLTYPE IInternalConnection_AddConnection_Proxy( + IInternalConnection * This); + +void __RPC_STUB IInternalConnection_AddConnection_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + +HRESULT STDMETHODCALLTYPE IInternalConnection_ReleaseConnection_Proxy( + IInternalConnection * This); + + +void __RPC_STUB IInternalConnection_ReleaseConnection_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + +#endif /* __IInternalConnection_INTERFACE_DEFINED__ */ + + +/* interface __MIDL_itf_atliface_0257 */ +/* [local] */ + + +#pragma pack(push,_ATL_PACKING) +namespace ATL +{ +#ifdef __cplusplus +#include +#else +#define ATLAPI EXTERN_C HRESULT __declspec(dllimport) __stdcall +#define ATLAPI_(x) EXTERN_C __declspec(dllimport) x __stdcall +#define ATLINLINE +#endif // __cplusplus + +ATLAPI_(INT_PTR) AtlAxDialogBoxW( + _In_ HINSTANCE hInstance, + _In_z_ LPCWSTR lpTemplateName, + _In_ HWND hWndParent, + _In_ DLGPROC lpDialogProc, + _In_ LPARAM dwInitParam); + +ATLAPI_(INT_PTR) AtlAxDialogBoxA( + _In_ HINSTANCE hInstance, + _In_z_ LPCSTR lpTemplateName, + _In_ HWND hWndParent, + _In_ DLGPROC lpDialogProc, + _In_ LPARAM dwInitParam); + +#ifdef UNICODE +#define AtlAxDialogBox AtlAxDialogBoxW +#else +#define AtlAxDialogBox AtlAxDialogBoxA +#endif + +ATLAPI_(HWND) AtlAxCreateDialogW( + _In_ HINSTANCE hInstance, + _In_z_ LPCWSTR lpTemplateName, + _In_ HWND hWndParent, + _In_ DLGPROC lpDialogProc, + _In_ LPARAM dwInitParam); + +ATLAPI_(HWND) AtlAxCreateDialogA( + _In_ HINSTANCE hInstance, + _In_z_ LPCSTR lpTemplateName, + _In_ HWND hWndParent, + _In_ DLGPROC lpDialogProc, + _In_ LPARAM dwInitParam); + +#ifdef UNICODE +#define AtlAxCreateDialog AtlAxCreateDialogW +#else +#define AtlAxCreateDialog AtlAxCreateDialogA +#endif + +ATLAPI AtlAxCreateControl( + _In_z_ LPCOLESTR lpszName, + _In_ HWND hWnd, + _Inout_opt_ IStream* pStream, + _Deref_out_ IUnknown** ppUnkContainer); + +#ifdef __cplusplus + +ATLAPI AtlAxCreateControlEx( + _In_z_ LPCOLESTR lpszName, + _In_ HWND hWnd, + _Inout_opt_ IStream* pStream, + _Deref_opt_out_ IUnknown** ppUnkContainer, + _Deref_opt_out_ IUnknown** ppUnkControl, + _In_ REFIID iidSink=IID_NULL, + _Inout_opt_ IUnknown* punkSink=NULL); + +ATLAPI AtlAxCreateControlLic( + _In_z_ LPCOLESTR lpszName, + _In_ HWND hWnd, + _Inout_opt_ IStream* pStream, + _Deref_opt_out_ IUnknown** ppUnkContainer, + _In_opt_z_ BSTR bstrLic = NULL); + +ATLAPI AtlAxCreateControlLicEx( + _In_z_ LPCOLESTR lpszName, + _In_ HWND hWnd, + _Inout_opt_ IStream* pStream, + _Deref_opt_out_ IUnknown** ppUnkContainer, + _Deref_opt_out_ IUnknown** ppUnkControl, + _In_ REFIID iidSink=IID_NULL, + _Inout_opt_ IUnknown* punkSink=NULL, + _In_opt_z_ BSTR bstrLic = NULL); + +#else + +ATLAPI AtlAxCreateControlEx( + _In_z_ LPCOLESTR lpszName, + _In_ HWND hWnd, + _Inout_opt_ IStream* pStream, + _Deref_opt_out_ IUnknown** ppUnkContainer, + _Deref_opt_out_ IUnknown** ppUnkControl, + _In_ REFIID iidSink, + _Inout_opt_ IUnknown* punkSink); + +ATLAPI AtlAxCreateControlLic( + _In_z_ LPCOLESTR lpszName, + _In_ HWND hWnd, + _Inout_opt_ IStream* pStream, + _Deref_opt_out_ IUnknown** ppUnkContainer, + _In_opt_z_ BSTR bstrLic); + +ATLAPI AtlAxCreateControlLicEx( + _In_z_ LPCOLESTR lpszName, + _Inout_ HWND hWnd, + _In_opt_ IStream* pStream, + _Deref_opt_out_ IUnknown** ppUnkContainer, + _Deref_opt_out_ IUnknown** ppUnkControl, + _In_ REFIID iidSink, + _Inout_opt_ IUnknown* punkSink, + _In_opt_z_ BSTR bstrLic); + +#endif // __cplusplus + +ATLAPI AtlAxAttachControl( + _Inout_ IUnknown* pControl, + _In_ HWND hWnd, + _Deref_opt_out_ IUnknown** ppUnkContainer); + +ATLAPI_(BOOL) AtlAxWinInit(); + +ATLAPI AtlAxGetHost( + _In_ HWND h, + _Deref_out_ IUnknown** pp); + +ATLAPI AtlAxGetControl( + _In_ HWND h, + _Deref_out_ IUnknown** pp); + +}; //namespace ATL +#pragma pack(pop) + + +/* Additional Prototypes for ALL interfaces */ + +unsigned long __RPC_USER BSTR_UserSize( unsigned long *, unsigned long , BSTR * ); +unsigned char * __RPC_USER BSTR_UserMarshal( unsigned long *, unsigned char *, BSTR * ); +unsigned char * __RPC_USER BSTR_UserUnmarshal(unsigned long *, unsigned char *, BSTR * ); +void __RPC_USER BSTR_UserFree( unsigned long *, BSTR * ); + +unsigned long __RPC_USER HWND_UserSize( unsigned long *, unsigned long , HWND * ); +unsigned char * __RPC_USER HWND_UserMarshal( unsigned long *, unsigned char *, HWND * ); +unsigned char * __RPC_USER HWND_UserUnmarshal(unsigned long *, unsigned char *, HWND * ); +void __RPC_USER HWND_UserFree( unsigned long *, HWND * ); + +/* end of Additional Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/src/main/headers/atlrc.h b/src/main/headers/atlrc.h new file mode 100644 index 0000000..ab52f9f --- /dev/null +++ b/src/main/headers/atlrc.h @@ -0,0 +1,27 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#pragma once + +#ifndef __ATLRC_H__ + +#define ATL_RESID_BASE 0xD800 +#define ATL_STRING_BASE ATL_RESID_BASE + +#define ATL_IDS_DATETIME_INVALID (ATL_STRING_BASE + 0) +#define ATL_IDS_DATETIMESPAN_INVALID (ATL_STRING_BASE + 1) + +#define ATL_SERVICE_MANAGER_OPEN_ERROR (ATL_STRING_BASE + 10) +#define ATL_SERVICE_START_ERROR (ATL_STRING_BASE + 11) +#define ATL_SERVICE_OPEN_ERROR (ATL_STRING_BASE + 12) +#define ATL_SERVICE_DELETE_ERROR (ATL_STRING_BASE + 13) +#define ATL_SERVICE_STOP_ERROR (ATL_STRING_BASE + 14) + +#endif // __ATLRC_H__ diff --git a/src/main/headers/atlsimpcoll.h b/src/main/headers/atlsimpcoll.h new file mode 100644 index 0000000..b89dc75 --- /dev/null +++ b/src/main/headers/atlsimpcoll.h @@ -0,0 +1,525 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#ifndef __ATLSIMPCOLL_H__ +#define __ATLSIMPCOLL_H__ + +#pragma once + +#include +#include +#include +#include + +#pragma push_macro("malloc") +#undef malloc +#pragma push_macro("calloc") +#undef calloc +#pragma push_macro("realloc") +#undef realloc +#pragma push_macro("_recalloc") +#undef _recalloc +#pragma push_macro("free") +#undef free + +#pragma warning(push) +#pragma warning(disable: 4800) // forcing 'int' value to bool + + +#pragma pack(push,_ATL_PACKING) +namespace ATL +{ + +#pragma push_macro("new") +#undef new + +///////////////////////////////////////////////////////////////////////////// +// Collection helpers - CSimpleArray & CSimpleMap + +// template class helpers with functions for comparing elements +// override if using complex types without operator== +template +class CSimpleArrayEqualHelper +{ +public: + static bool IsEqual( + _In_ const T& t1, + _In_ const T& t2) + { + return (t1 == t2); + } +}; + +template +class CSimpleArrayEqualHelperFalse +{ +public: + static bool IsEqual( + _In_ const T&, + _In_ const T&) + { + ATLASSERT(false); + return false; + } +}; + +template +class CSimpleMapEqualHelper +{ +public: + static bool IsEqualKey( + _In_ const TKey& k1, + _In_ const TKey& k2) + { + return CSimpleArrayEqualHelper::IsEqual(k1, k2); + } + + static bool IsEqualValue( + _In_ const TVal& v1, + _In_ const TVal& v2) + { + return CSimpleArrayEqualHelper::IsEqual(v1, v2); + } +}; + +template +class CSimpleMapEqualHelperFalse +{ +public: + static bool IsEqualKey( + _In_ const TKey& k1, + _In_ const TKey& k2) + { + return CSimpleArrayEqualHelper::IsEqual(k1, k2); + } + + static bool IsEqualValue( + _In_ const TVal&, + _In_ const TVal&) + { + ATLASSERT(FALSE); + return false; + } +}; + +template > +class CSimpleArray +{ +public: +// Construction/destruction + CSimpleArray() : + m_aT(NULL), m_nSize(0), m_nAllocSize(0) + { + } + + ~CSimpleArray(); + + CSimpleArray(_In_ const CSimpleArray< T, TEqual >& src) : + m_aT(NULL), m_nSize(0), m_nAllocSize(0) + { + if (src.GetSize()) + { + m_aT = (T*)nb_calloc(src.GetSize(), sizeof(T)); + if (m_aT != NULL) + { + m_nAllocSize = src.GetSize(); + for (int i=0; i& operator=(_In_ const CSimpleArray< T, TEqual >& src) + { + if (GetSize() != src.GetSize()) + { + RemoveAll(); + m_aT = (T*)nb_calloc(src.GetSize(), sizeof(T)); + if (m_aT != NULL) + m_nAllocSize = src.GetSize(); + } + else + { + for (int i = GetSize(); i > 0; i--) + RemoveAt(i - 1); + } + for (int i=0; i= (m_aT + m_nAllocSize) ) ); + + T* aT; + int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2); + + if (nNewAllocSize<0||nNewAllocSize>INT_MAX/sizeof(T)) + { + return FALSE; + } + + aT = (T*)_recalloc(m_aT, nNewAllocSize, sizeof(T)); + if(aT == NULL) + return FALSE; + m_nAllocSize = nNewAllocSize; + m_aT = aT; + } + InternalSetAtIndex(m_nSize, t); + m_nSize++; + return TRUE; + } + BOOL Remove(_In_ const T& t) + { + int nIndex = Find(t); + if(nIndex == -1) + return FALSE; + return RemoveAt(nIndex); + } + BOOL RemoveAt(_In_ int nIndex) + { + ATLASSERT(nIndex >= 0 && nIndex < m_nSize); + if (nIndex < 0 || nIndex >= m_nSize) + return FALSE; + m_aT[nIndex].~T(); + if(nIndex != (m_nSize - 1)) + Checked::memmove_s((void*)(m_aT + nIndex), (m_nSize - nIndex) * sizeof(T), (void*)(m_aT + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(T)); + m_nSize--; + return TRUE; + } + void RemoveAll() + { + if(m_aT != NULL) + { + for(int i = 0; i < m_nSize; i++) + m_aT[i].~T(); + nb_free(m_aT); + m_aT = NULL; + } + m_nSize = 0; + m_nAllocSize = 0; + } + const T& operator[] (_In_ int nIndex) const + { + ATLASSERT(nIndex >= 0 && nIndex < m_nSize); + if(nIndex < 0 || nIndex >= m_nSize) + { + _AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED); + } + return m_aT[nIndex]; + } + T& operator[] (_In_ int nIndex) + { + ATLASSERT(nIndex >= 0 && nIndex < m_nSize); + if(nIndex < 0 || nIndex >= m_nSize) + { + _AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED); + } + return m_aT[nIndex]; + } + T* GetData() const + { + return m_aT; + } + + int Find(_In_ const T& t) const + { + for(int i = 0; i < m_nSize; i++) + { + if(TEqual::IsEqual(m_aT[i], t)) + return i; + } + return -1; // not found + } + + BOOL SetAtIndex( + _In_ int nIndex, + _In_ const T& t) + { + if (nIndex < 0 || nIndex >= m_nSize) + return FALSE; + InternalSetAtIndex(nIndex, t); + return TRUE; + } + +// Implementation + class Wrapper + { + public: + Wrapper(_In_ const T& _t) : t(_t) + { + } + template + void * __cdecl operator new( + _In_ size_t, + _In_ _Ty* p) + { + return p; + } + template + void __cdecl operator delete( + _In_ void* /* pv */, + _In_ _Ty* /* p */) + { + } + T t; + }; + +// Implementation + void InternalSetAtIndex( + _In_ int nIndex, + _In_ const T& t) + { + new(m_aT + nIndex) Wrapper(t); + } + + typedef T _ArrayElementType; + T* m_aT; + int m_nSize; + int m_nAllocSize; +}; + +#define CSimpleValArray CSimpleArray + +template inline CSimpleArray::~CSimpleArray() +{ + RemoveAll(); +} + +// intended for small number of simple types or pointers +template > +class CSimpleMap +{ +public: + TKey* m_aKey; + TVal* m_aVal; + int m_nSize; + + typedef TKey _ArrayKeyType; + typedef TVal _ArrayElementType; + +// Construction/destruction + CSimpleMap() : + m_aKey(NULL), m_aVal(NULL), m_nSize(0) + { + } + + ~CSimpleMap() + { + RemoveAll(); + } + +// Operations + int GetSize() const + { + return m_nSize; + } + BOOL Add( + _In_ const TKey& key, + _In_ const TVal& val) + { + TKey* pKey; + pKey = (TKey*)_recalloc(m_aKey, (m_nSize + 1), sizeof(TKey)); + if(pKey == NULL) + return FALSE; + m_aKey = pKey; + TVal* pVal; + pVal = (TVal*)_recalloc(m_aVal, (m_nSize + 1), sizeof(TVal)); + if(pVal == NULL) + return FALSE; + m_aVal = pVal; + InternalSetAtIndex(m_nSize, key, val); + m_nSize++; + return TRUE; + } + BOOL Remove(_In_ const TKey& key) + { + int nIndex = FindKey(key); + if(nIndex == -1) + return FALSE; + return RemoveAt(nIndex); + } + BOOL RemoveAt(_In_ int nIndex) + { + ATLASSERT(nIndex >= 0 && nIndex < m_nSize); + if (nIndex < 0 || nIndex >= m_nSize) + return FALSE; + m_aKey[nIndex].~TKey(); + m_aVal[nIndex].~TVal(); + if(nIndex != (m_nSize - 1)) + { + Checked::memmove_s((void*)(m_aKey + nIndex), (m_nSize - nIndex) * sizeof(TKey), (void*)(m_aKey + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(TKey)); + Checked::memmove_s((void*)(m_aVal + nIndex), (m_nSize - nIndex) * sizeof(TVal), (void*)(m_aVal + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(TVal)); + } + TKey* pKey; + pKey = (TKey*)_recalloc(m_aKey, (m_nSize - 1), sizeof(TKey)); + if(pKey != NULL || m_nSize == 1) + m_aKey = pKey; + TVal* pVal; + pVal = (TVal*)_recalloc(m_aVal, (m_nSize - 1), sizeof(TVal)); + if(pVal != NULL || m_nSize == 1) + m_aVal = pVal; + m_nSize--; + return TRUE; + } + void RemoveAll() + { + if(m_aKey != NULL) + { + for(int i = 0; i < m_nSize; i++) + { + m_aKey[i].~TKey(); + m_aVal[i].~TVal(); + } + nb_free(m_aKey); + m_aKey = NULL; + } + if(m_aVal != NULL) + { + nb_free(m_aVal); + m_aVal = NULL; + } + + m_nSize = 0; + } + BOOL SetAt( + _In_ const TKey& key, + _In_ const TVal& val) + { + int nIndex = FindKey(key); + if(nIndex == -1) + return FALSE; + ATLASSERT(nIndex >= 0 && nIndex < m_nSize); + m_aKey[nIndex].~TKey(); + m_aVal[nIndex].~TVal(); + InternalSetAtIndex(nIndex, key, val); + return TRUE; + } + TVal Lookup(_In_ const TKey& key) const + { + int nIndex = FindKey(key); + if(nIndex == -1) + return NULL; // must be able to convert + return GetValueAt(nIndex); + } + TKey ReverseLookup(_In_ const TVal& val) const + { + int nIndex = FindVal(val); + if(nIndex == -1) + return NULL; // must be able to convert + return GetKeyAt(nIndex); + } + TKey& GetKeyAt(_In_ int nIndex) const + { + ATLASSERT(nIndex >= 0 && nIndex < m_nSize); + if(nIndex < 0 || nIndex >= m_nSize) + _AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED); + + return m_aKey[nIndex]; + } + TVal& GetValueAt(_In_ int nIndex) const + { + ATLASSERT(nIndex >= 0 && nIndex < m_nSize); + if(nIndex < 0 || nIndex >= m_nSize) + _AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED); + + return m_aVal[nIndex]; + } + + int FindKey(_In_ const TKey& key) const + { + for(int i = 0; i < m_nSize; i++) + { + if(TEqual::IsEqualKey(m_aKey[i], key)) + return i; + } + return -1; // not found + } + int FindVal(_In_ const TVal& val) const + { + for(int i = 0; i < m_nSize; i++) + { + if(TEqual::IsEqualValue(m_aVal[i], val)) + return i; + } + return -1; // not found + } + + BOOL SetAtIndex( + _In_ int nIndex, + _In_ const TKey& key, + _In_ const TVal& val) + { + if (nIndex < 0 || nIndex >= m_nSize) + return FALSE; + InternalSetAtIndex(nIndex, key, val); + return TRUE; + } + + +// Implementation + + template + class Wrapper + { + public: + Wrapper(_In_ const T& _t) : t(_t) + { + } + template + void *operator new( + _In_ size_t, + _In_ _Ty* p) + { + return p; + } + template + void operator delete( + _In_ void* /* pv */, + _In_ _Ty* /* p */) + { + } + T t; + }; + void InternalSetAtIndex( + _In_ int nIndex, + _In_ const TKey& key, + _In_ const TVal& val) + { + new(m_aKey + nIndex) Wrapper(key); + new(m_aVal + nIndex) Wrapper(val); + } +}; + +#pragma pop_macro("new") + +}; // namespace ATL +#pragma pack(pop) + +#pragma warning(pop) + +#pragma pop_macro("free") +#pragma pop_macro("realloc") +#pragma pop_macro("_recalloc") +#pragma pop_macro("malloc") +#pragma pop_macro("calloc") + + +#endif // __ATLSIMPCOLL_H__ diff --git a/src/main/headers/atltrace.h b/src/main/headers/atltrace.h new file mode 100644 index 0000000..98a80ee --- /dev/null +++ b/src/main/headers/atltrace.h @@ -0,0 +1,60 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#ifndef __ATLTRACE_H__ +#define __ATLTRACE_H__ + +#pragma once + +#include +#include + + +#ifndef ATLTRACE +#define ATLTRACE +#define ATLTRACE2 ATLTRACE +#endif + +#pragma warning(push) +#pragma warning(disable : 4793) +inline void __cdecl AtlTraceNull(...) +{ +} +inline void __cdecl AtlTrace( + _In_z_ _Printf_format_string_ LPCSTR, ...) +{ +} +inline void __cdecl AtlTrace2( + _In_ DWORD_PTR, + _In_ UINT, + _In_z_ _Printf_format_string_ LPCSTR, ...) +{ +} +inline void __cdecl AtlTrace( + _In_z_ _Printf_format_string_ LPCWSTR, ...) +{ +} +inline void __cdecl AtlTrace2( + _In_ DWORD_PTR, + _In_ UINT, + _In_z_ _Printf_format_string_ LPCWSTR, ...) +{ +} +#pragma warning(pop) + +#ifndef ATLTRACE + +#define ATLTRACE __noop +#define ATLTRACE2 __noop +#endif //ATLTRACE +#define ATLTRACENOTIMPL(funcname) return E_NOTIMPL +#define DECLARE_NOUIASSERT() + +#endif // __ATLTRACE_H__ diff --git a/src/main/headers/nbglobals.h b/src/main/headers/nbglobals.h new file mode 100644 index 0000000..8f33f9e --- /dev/null +++ b/src/main/headers/nbglobals.h @@ -0,0 +1,208 @@ +#pragma once + +#ifdef USE_DLMALLOC +#include "../../libs/dlmalloc/malloc-2.8.6.h" + +#define nb_malloc(size) dlcalloc(1, size) +#define nb_calloc(count, size) dlcalloc(count, size) +#define nb_realloc(ptr, size) dlrealloc(ptr, size) + +#if defined(__cplusplus) +#define nb_free(ptr) dlfree(reinterpret_cast(ptr)) +#else +#define nb_free(ptr) dlfree((void *)(ptr)) +#endif // if defined(__cplusplus) + +#else + +#define nb_malloc(size) malloc(size) +#define nb_calloc(count, size) calloc(count, size) +#define nb_realloc(ptr, size) realloc(ptr, size) + +#if defined(__cplusplus) +#define nb_free(ptr) free(reinterpret_cast(ptr)) +#else +#define nb_free(ptr) free((void *)(ptr)) +#endif // if defined(__cplusplus) + +#endif // ifdef USE_DLMALLOC + +#if defined(_MSC_VER) + +#ifndef noexcept +#define noexcept throw() +#endif + +#endif + +#if defined(__cplusplus) + +inline void * operator_new(size_t size) +{ + void * p = nb_malloc(size); + /*if (!p) + { + static std::bad_alloc badalloc; + throw badalloc; + }*/ + return p; +} + +inline void operator_delete(void * p) +{ + nb_free(p); +} + +#endif // if defined(__cplusplus) + +#ifdef USE_DLMALLOC +/// custom memory allocation +#define DEF_CUSTOM_MEM_ALLOCATION_IMPL \ + public: \ + void * operator new(size_t size) \ + { \ + return operator_new(size); \ + } \ + void operator delete(void * p, size_t) \ + { \ + operator_delete(p); \ + } \ + void * operator new[](size_t size) \ + { \ + return operator_new(size); \ + } \ + void operator delete[](void * p, size_t) \ + { \ + operator_delete(p); \ + } \ + void * operator new(size_t, void * p) \ + { \ + return p; \ + } \ + void operator delete(void *, void *) \ + { \ + } \ + void * operator new[](size_t, void * p) \ + { \ + return p; \ + } \ + void operator delete[](void *, void *) \ + { \ + } + +#ifdef _DEBUG +#define CUSTOM_MEM_ALLOCATION_IMPL DEF_CUSTOM_MEM_ALLOCATION_IMPL \ + void * operator new(size_t size, const char * /*lpszFileName*/, int /*nLine*/) \ + { \ + return operator_new(size); \ + } \ + void * operator new[](size_t size, const char * /*lpszFileName*/, int /*nLine*/) \ + { \ + return operator_new(size); \ + } \ + void operator delete(void * p, const char * /*lpszFileName*/, int /*nLine*/) \ + { \ + operator_delete(p); \ + } \ + void operator delete[](void * p, const char * /*lpszFileName*/, int /*nLine*/) \ + { \ + operator_delete(p); \ + } +#else +#define CUSTOM_MEM_ALLOCATION_IMPL DEF_CUSTOM_MEM_ALLOCATION_IMPL +#endif // ifdef _DEBUG + +#else +#define CUSTOM_MEM_ALLOCATION_IMPL +#endif // ifdef USE_DLMALLOC + +#if defined(__cplusplus) + +namespace nballoc +{ + inline void destruct(char *) {} + inline void destruct(wchar_t *) {} + template + inline void destruct(T * t) { t->~T(); } +} // namespace nballoc + +template struct custom_nballocator_t; + +template <> struct custom_nballocator_t +{ +public: + typedef void * pointer; + typedef const void * const_pointer; + // reference to void members are impossible. + typedef void value_type; + template + struct rebind { typedef custom_nballocator_t other; }; +}; + +template +struct custom_nballocator_t +{ + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T * pointer; + typedef const T * const_pointer; + typedef T & reference; + typedef const T & const_reference; + typedef T value_type; + + template struct rebind { typedef custom_nballocator_t other; }; + inline custom_nballocator_t() noexcept {} + inline custom_nballocator_t(const custom_nballocator_t &) noexcept {} + + template custom_nballocator_t(const custom_nballocator_t &) noexcept {} + + ~custom_nballocator_t() noexcept {} + + pointer address(reference x) const { return &x; } + const_pointer address(const_reference x) const { return &x; } + + pointer allocate(size_type s, void const * = 0) + { + if (0 == s) + return nullptr; + pointer temp = (pointer)nb_malloc(s * sizeof(T)); + if (temp == nullptr) + throw std::bad_alloc(); + return temp; + } + + void deallocate(pointer p, size_type) + { + nb_free(p); + } + + size_type max_size() const noexcept + { + // return std::numeric_limits::max() / sizeof(T); + return size_t(-1) / sizeof(T); + } + + void construct(pointer p, const T & val) + { + new((void *)p) T(val); + } + + void destroy(pointer p) + { + nballoc::destruct(p); + } +}; + +template +inline bool operator==(const custom_nballocator_t &, const custom_nballocator_t &) +{ + return true; +} + +template +inline bool operator!=(const custom_nballocator_t &, const custom_nballocator_t &) +{ + return false; +} + +#endif // if defined(__cplusplus) diff --git a/src/main/headers/statreg.h b/src/main/headers/statreg.h new file mode 100644 index 0000000..3afda41 --- /dev/null +++ b/src/main/headers/statreg.h @@ -0,0 +1,1609 @@ +// This is a part of the Active Template Library. +// Copyright (C) Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Active Template Library Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Active Template Library product. + +#ifndef __STATREG_H__ +#define __STATREG_H__ + +#pragma once + +#ifndef __cplusplus + #error ATL requires C++ compilation (use a .cpp suffix) +#endif + +#ifndef __ATLBASE_H__ + #error statreg.h requires atlbase.h to be included first +#endif + +#pragma warning(push) +#pragma warning(disable:4571) //catch(...) blocks compiled with /EHs do NOT catch or re-throw Structured Exceptions + +#define E_ATL_REGISTRAR_DESC 0x0201 +#define E_ATL_NOT_IN_MAP 0x0202 +#define E_ATL_UNEXPECTED_EOS 0x0203 +#define E_ATL_VALUE_SET_FAILED 0x0204 +#define E_ATL_RECURSE_DELETE_FAILED 0x0205 +#define E_ATL_EXPECTING_EQUAL 0x0206 +#define E_ATL_CREATE_KEY_FAILED 0x0207 +#define E_ATL_DELETE_KEY_FAILED 0x0208 +#define E_ATL_OPEN_KEY_FAILED 0x0209 +#define E_ATL_CLOSE_KEY_FAILED 0x020A +#define E_ATL_UNABLE_TO_COERCE 0x020B +#define E_ATL_BAD_HKEY 0x020C +#define E_ATL_MISSING_OPENKEY_TOKEN 0x020D +#define E_ATL_CONVERT_FAILED 0x020E +#define E_ATL_TYPE_NOT_SUPPORTED 0x020F +#define E_ATL_COULD_NOT_CONCAT 0x0210 +#define E_ATL_COMPOUND_KEY 0x0211 +#define E_ATL_INVALID_MAPKEY 0x0212 +#define E_ATL_UNSUPPORTED_VT 0x0213 +#define E_ATL_VALUE_GET_FAILED 0x0214 +#define E_ATL_VALUE_TOO_LARGE 0x0215 +#define E_ATL_MISSING_VALUE_DELIMETER 0x0216 +#define E_ATL_DATA_NOT_BYTE_ALIGNED 0x0217 + +#pragma pack(push,_ATL_PACKING) +namespace ATL +{ +const TCHAR chDirSep = _T('\\'); +const TCHAR chRightBracket = _T('}'); +const TCHAR chLeftBracket = _T('{'); +const TCHAR chQuote = _T('\''); +const TCHAR chEquals = _T('='); +const LPCTSTR szStringVal = _T("S"); +const LPCTSTR multiszStringVal = _T("M"); +const LPCTSTR szDwordVal = _T("D"); +const LPCTSTR szBinaryVal = _T("B"); +const LPCTSTR szValToken = _T("Val"); +const LPCTSTR szForceRemove = _T("ForceRemove"); +const LPCTSTR szNoRemove = _T("NoRemove"); +const LPCTSTR szDelete = _T("Delete"); + + +// Implementation helper +class CExpansionVectorEqualHelper +{ +public: + static bool IsEqualKey( + _In_z_ const LPTSTR k1, + _In_z_ const LPTSTR k2) + { + if (lstrcmpi(k1, k2) == 0) + return true; + return false; + } + + // Not used + static bool IsEqualValue( + _In_opt_z_ const LPCOLESTR /*v1*/, + _In_opt_z_ const LPCOLESTR /*v2*/) + { + return false; + } +}; + +// Implementation helper +class CExpansionVector : + public CSimpleMap +{ +public: + ~CExpansionVector() + { + ClearReplacements(); + } + + BOOL Add( + _In_z_ LPCTSTR lpszKey, + _In_z_ LPCOLESTR lpszValue) + { + ATLASSERT(lpszKey != NULL && lpszValue != NULL); + if (lpszKey == NULL || lpszValue == NULL) + return FALSE; + + HRESULT hRes = S_OK; + + size_t cbKey = (lstrlen(lpszKey)+1)*sizeof(TCHAR); + TCHAR* szKey = NULL; + + ATLTRY(szKey = new TCHAR[cbKey];) + CAutoVectorPtr spKey; + ATLASSUME(szKey != NULL); + spKey.Attach(szKey); + + size_t cbValue = (ocslen(lpszValue)+1)*sizeof(OLECHAR); + LPOLESTR szValue = NULL; + ATLTRY(szValue = new OLECHAR[cbValue];) + CAutoVectorPtr spValue; + ATLASSUME(szValue != NULL); + spValue.Attach(szValue); + + if (szKey == NULL || szValue == NULL) + hRes = E_OUTOFMEMORY; + else + { + Checked::memcpy_s(szKey, cbKey, lpszKey, cbKey); + Checked::memcpy_s(szValue, cbValue, lpszValue, cbValue); + if (!CSimpleMap::Add(szKey, szValue)) + hRes = E_OUTOFMEMORY; + } + if (SUCCEEDED(hRes)) + { + spKey.Detach(); + spValue.Detach(); + } + return SUCCEEDED(hRes); + } + HRESULT ClearReplacements() + { + for (int i = 0; i < GetSize(); i++) + { + delete []GetKeyAt(i); + delete []GetValueAt(i); + } + RemoveAll(); + return S_OK; + } +}; + +class CRegObject; + +class CRegParser +{ +public: + CRegParser(_In_ CRegObject* pRegObj); + + HRESULT PreProcessBuffer( + _In_z_ LPTSTR lpszReg, + _Deref_out_z_ LPTSTR* ppszReg); + + HRESULT RegisterBuffer( + _In_z_ LPTSTR szReg, + _In_ BOOL bRegister); + +protected: + + static const int MAX_VALUE = 4096; + void SkipWhiteSpace(); + HRESULT NextToken(_Out_z_cap_c_(MAX_VALUE) LPTSTR szToken); + HRESULT AddValue( + _Inout_ CRegKey& rkParent, + _In_opt_z_ LPCTSTR szValueName, + _Out_z_cap_c_(MAX_VALUE) LPTSTR szToken); + BOOL CanForceRemoveKey(_In_z_ LPCTSTR szKey); + BOOL HasSubKeys(_In_ HKEY hkey); + BOOL HasValues(_In_ HKEY hkey); + HRESULT RegisterSubkeys( + _Out_z_cap_c_(MAX_VALUE) LPTSTR szToken, + _In_ HKEY hkParent, + _In_ BOOL bRegister, + _In_ BOOL bInRecovery = FALSE); + BOOL IsSpace(_In_ TCHAR ch); + LPTSTR m_pchCur; + + CRegObject* m_pRegObj; + + HRESULT GenerateError(_In_ UINT) + { + return DISP_E_EXCEPTION; + } + //HRESULT HandleReplacements(LPTSTR& szToken); + HRESULT SkipAssignment(_Inout_z_cap_c_(MAX_VALUE) LPTSTR szToken); + + BOOL EndOfVar() + { + return chQuote == *m_pchCur && chQuote != *CharNext(m_pchCur); + } + static LPTSTR StrChr(_In_z_ LPTSTR lpsz, _In_ TCHAR ch); + static HKEY HKeyFromString(_In_z_ LPTSTR szToken); + static BYTE ChToByte(_In_ const TCHAR ch); + static BOOL VTFromRegType(_In_z_ LPCTSTR szValueType, _Out_ VARTYPE& vt); + + static const TCHAR* const rgszNeverDelete[]; + static const int cbNeverDelete; + static const int MAX_TYPE = 4096; + + // Implementation Helper + class CParseBuffer + { + public: + int nPos; + int nSize; + LPTSTR p; + CParseBuffer(_In_ int nInitial) + { + if (nInitial < 100) + nInitial = 1000; + nPos = 0; + nSize = nInitial; + p = (LPTSTR) ::ATL::AtlCoTaskMemCAlloc(nSize,static_cast(sizeof(TCHAR))); + if (p != NULL) + *p = _T('\0'); + } + ~CParseBuffer() + { + CoTaskMemFree(p); + } + BOOL Append( + _In_count_(nChars) const TCHAR* pch, + _In_ int nChars) + { + ATLASSERT(p != NULL); + int newSize = nPos + nChars + 1; + if ((newSize <= nPos) || (newSize <= nChars)) + return FALSE; + + if (newSize >= nSize) + { + while (newSize >= nSize) { + if (nSize > INT_MAX / 2) + return FALSE; + nSize *= 2; + } + LPTSTR pTemp = (LPTSTR)::ATL::AtlCoTaskMemRecalloc(p, nSize, sizeof(TCHAR)); + if (pTemp == NULL) + return FALSE; + p = pTemp; + } + if ((nPos < 0) || (nPos >= nSize) || nSize - nPos > nSize) + return FALSE; + +#pragma warning(push) +#pragma warning(disable: 22008) + /* Prefast false warning is fired here despite the all above checks */ + Checked::memcpy_s(p + nPos, (nSize-nPos) * sizeof(TCHAR), pch, int(nChars * sizeof(TCHAR))); + nPos += nChars; + *(p + nPos) = _T('\0'); +#pragma warning(pop) + return TRUE; + } + + BOOL AddChar(_In_z_ const TCHAR* pch) + { +#ifndef _UNICODE + int nChars = int(CharNext(pch) - pch); +#else + int nChars = 1; +#endif + return Append(pch, nChars); + + } + BOOL AddString(_In_z_ LPCOLESTR lpsz) + { + if (lpsz == NULL) + { + return FALSE; + } + USES_CONVERSION_EX; + LPCTSTR lpszT = OLE2CT_EX(lpsz, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); + if (lpszT == NULL) + { + return FALSE; + } + return Append(lpszT, (int)lstrlen(lpszT)); + } + LPTSTR Detach() + { + LPTSTR lp = p; + p = NULL; + nSize = nPos = 0; + return lp; + } + + }; +}; + +#if defined(_ATL_DLL) || defined(_ATL_DLL_IMPL) +class ATL_NO_VTABLE CRegObject : + public IRegistrar +#else +class CRegObject : + public IRegistrarBase +#endif +{ +public: + +#if defined(_ATL_DLL) || defined(_ATL_DLL_IMPL) + +#else + STDMETHOD(QueryInterface)( + _In_ const IID &, + _In_opt_ void ** ) + { + ATLASSERT(_T("statically linked in CRegObject is not a com object. Do not callthis function")); + return E_NOTIMPL; + } + + STDMETHOD_(ULONG, AddRef)(void) + { + ATLASSERT(_T("statically linked in CRegObject is not a com object. Do not callthis function")); + return 1; + } + STDMETHOD_(ULONG, Release)(void) + { + ATLASSERT(_T("statically linked in CRegObject is not a com object. Do not callthis function")); + return 0; + } +#endif + virtual ~CRegObject() + { + ClearReplacements(); + } + HRESULT FinalConstruct() + { + return m_csMap.Init(); + } + void FinalRelease() {} + + + // Map based methods + HRESULT STDMETHODCALLTYPE AddReplacement( + _In_z_ LPCOLESTR lpszKey, + _In_z_ LPCOLESTR lpszItem); + HRESULT STDMETHODCALLTYPE ClearReplacements(); + LPCOLESTR StrFromMap(_In_z_ LPTSTR lpszKey); + + // Register via a given mechanism + HRESULT STDMETHODCALLTYPE ResourceRegister( + _In_z_ LPCOLESTR pszFileName, + _In_ UINT nID, + _In_z_ LPCOLESTR pszType); + HRESULT STDMETHODCALLTYPE ResourceRegisterSz( + _In_z_ LPCOLESTR pszFileName, + _In_z_ LPCOLESTR pszID, + _In_z_ LPCOLESTR pszType); + HRESULT STDMETHODCALLTYPE ResourceUnregister( + _In_z_ LPCOLESTR pszFileName, + _In_ UINT nID, + _In_z_ LPCOLESTR pszType); + HRESULT STDMETHODCALLTYPE ResourceUnregisterSz( + _In_z_ LPCOLESTR pszFileName, + _In_z_ LPCOLESTR pszID, + _In_z_ LPCOLESTR pszType); + + HRESULT STDMETHODCALLTYPE FileRegister(_In_z_ LPCOLESTR bstrFileName) + { + return CommonFileRegister(bstrFileName, TRUE); + } + + HRESULT STDMETHODCALLTYPE FileUnregister(_In_z_ LPCOLESTR bstrFileName) + { + return CommonFileRegister(bstrFileName, FALSE); + } + + HRESULT STDMETHODCALLTYPE StringRegister(_In_z_ LPCOLESTR bstrData) + { + return RegisterWithString(bstrData, TRUE); + } + + HRESULT STDMETHODCALLTYPE StringUnregister(_In_z_ LPCOLESTR bstrData) + { + return RegisterWithString(bstrData, FALSE); + } + +protected: + + HRESULT CommonFileRegister( + _In_z_ LPCOLESTR pszFileName, + _In_ BOOL bRegister); + HRESULT RegisterFromResource( + _In_z_ LPCOLESTR pszFileName, + _In_z_ LPCTSTR pszID, + _In_z_ LPCTSTR pszType, + _In_ BOOL bRegister); + HRESULT RegisterWithString( + _In_z_ LPCOLESTR pszData, + _In_ BOOL bRegister); + + static HRESULT GenerateError(_In_ UINT) + { + return DISP_E_EXCEPTION; + } + + CExpansionVector m_RepMap; + CComObjectThreadModel::AutoDeleteCriticalSection m_csMap; +}; + +inline HRESULT STDMETHODCALLTYPE CRegObject::AddReplacement( + _In_z_ LPCOLESTR lpszKey, + _In_z_ LPCOLESTR lpszItem) +{ + if (lpszKey == NULL || lpszItem == NULL) + return E_INVALIDARG; + m_csMap.Lock(); + USES_CONVERSION_EX; + + LPCTSTR lpszT = OLE2CT_EX(lpszKey, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); + +#ifndef _UNICODE + if(lpszT == NULL) + return E_OUTOFMEMORY; +#endif + + BOOL bRet = m_RepMap.Add(lpszT, lpszItem); + m_csMap.Unlock(); + return bRet ? S_OK : E_OUTOFMEMORY; +} + +inline HRESULT CRegObject::RegisterFromResource( + _In_z_ LPCOLESTR bstrFileName, + _In_z_ LPCTSTR szID, + _In_z_ LPCTSTR szType, + _In_ BOOL bRegister) +{ + USES_CONVERSION_EX; + + HRESULT hr; + CRegParser parser(this); + HINSTANCE hInstResDll; + HRSRC hrscReg; + HGLOBAL hReg; + DWORD dwSize; + LPSTR szRegA; + DWORD uniSize = 0; + CTempBuffer szReg; + + LPCTSTR lpszBSTRFileName = OLE2CT_EX(bstrFileName, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if (lpszBSTRFileName == NULL) + { + return E_OUTOFMEMORY; + } +#endif // _UNICODE + + hInstResDll = LoadLibraryEx(lpszBSTRFileName, NULL, LOAD_LIBRARY_AS_DATAFILE); + + if (NULL == hInstResDll) + { + hr = AtlHresultFromLastError(); + goto ReturnHR; + } + + hrscReg =FindResource((HMODULE)hInstResDll, szID, szType); + + if (NULL == hrscReg) + { + hr = AtlHresultFromLastError(); + goto ReturnHR; + } + hReg = LoadResource((HMODULE)hInstResDll, hrscReg); + + if (NULL == hReg) + { + hr = AtlHresultFromLastError(); + goto ReturnHR; + } + + dwSize = SizeofResource((HMODULE)hInstResDll, hrscReg); + szRegA = (LPSTR)hReg; + + // Allocate extra space for NULL. + if (dwSize + 1 < dwSize) + { + hr = E_OUTOFMEMORY; + goto ReturnHR; + } + + ATLTRY(szReg.Allocate(dwSize + 1)); + if (szReg == NULL) + { + hr = E_OUTOFMEMORY; + goto ReturnHR; + } +#ifdef _UNICODE + uniSize = ::MultiByteToWideChar(_AtlGetConversionACP(), 0, szRegA, dwSize, szReg, dwSize); + if (uniSize == 0) + { + hr = AtlHresultFromLastError(); + goto ReturnHR; + } + // Append a NULL at the end. + szReg[uniSize] = _T('\0'); +#else + Checked::memcpy_s(szReg, dwSize, szRegA, dwSize); + // Append a NULL at the end. + szReg[dwSize] = _T('\0'); +#endif + + hr = parser.RegisterBuffer(szReg, bRegister); + +ReturnHR: + + if (NULL != hInstResDll) + FreeLibrary((HMODULE)hInstResDll); + return hr; +} + +inline HRESULT STDMETHODCALLTYPE CRegObject::ResourceRegister( + _In_z_ LPCOLESTR szFileName, + _In_ UINT nID, + _In_z_ LPCOLESTR szType) +{ + USES_CONVERSION_EX; + + LPCTSTR lpszT = OLE2CT_EX(szType, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if (lpszT == NULL) + { + return E_OUTOFMEMORY; + } +#endif // _UNICODE + + return RegisterFromResource(szFileName, MAKEINTRESOURCE(nID), lpszT, TRUE); +} + +inline HRESULT STDMETHODCALLTYPE CRegObject::ResourceRegisterSz( + _In_z_ LPCOLESTR szFileName, + _In_z_ LPCOLESTR szID, + _In_z_ LPCOLESTR szType) +{ + USES_CONVERSION_EX; + if (szID == NULL || szType == NULL) + return E_INVALIDARG; + + LPCTSTR lpszID = OLE2CT_EX(szID, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); + LPCTSTR lpszType = OLE2CT_EX(szType, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if (lpszID == NULL || lpszType==NULL) + { + return E_OUTOFMEMORY; + } +#endif // _UNICODE + return RegisterFromResource(szFileName, lpszID, lpszType, TRUE); +} + +inline HRESULT STDMETHODCALLTYPE CRegObject::ResourceUnregister( + _In_z_ LPCOLESTR szFileName, + _In_ UINT nID, + _In_z_ LPCOLESTR szType) +{ + USES_CONVERSION_EX; + + LPCTSTR lpszT = OLE2CT_EX(szType, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if (lpszT == NULL) + { + return E_OUTOFMEMORY; + } +#endif // _UNICODE + return RegisterFromResource(szFileName, MAKEINTRESOURCE(nID), lpszT, FALSE); +} + +inline HRESULT STDMETHODCALLTYPE CRegObject::ResourceUnregisterSz( + _In_z_ LPCOLESTR szFileName, + _In_z_ LPCOLESTR szID, + _In_z_ LPCOLESTR szType) +{ + USES_CONVERSION_EX; + if (szID == NULL || szType == NULL) + return E_INVALIDARG; + + LPCTSTR lpszID = OLE2CT_EX(szID, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); + LPCTSTR lpszType = OLE2CT_EX(szType, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if (lpszID == NULL || lpszType == NULL) + { + return E_OUTOFMEMORY; + } +#endif // _UNICODE + + return RegisterFromResource(szFileName, lpszID, lpszType, FALSE); +} + +inline HRESULT CRegObject::RegisterWithString( + _In_z_ LPCOLESTR bstrData, + _In_ BOOL bRegister) +{ + USES_CONVERSION_EX; + CRegParser parser(this); + + LPCTSTR szReg = OLE2CT_EX(bstrData, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if (szReg == NULL) + { + return E_OUTOFMEMORY; + } +#endif // _UNICODE + + HRESULT hr = parser.RegisterBuffer((LPTSTR)szReg, bRegister); + + return hr; +} + +inline HRESULT CRegObject::ClearReplacements() +{ + m_csMap.Lock(); + HRESULT hr = m_RepMap.ClearReplacements(); + m_csMap.Unlock(); + return hr; +} + + +inline LPCOLESTR CRegObject::StrFromMap(_In_z_ LPTSTR lpszKey) +{ + m_csMap.Lock(); + LPCOLESTR lpsz = m_RepMap.Lookup(lpszKey); + m_csMap.Unlock(); + return lpsz; +} + +inline HRESULT CRegObject::CommonFileRegister( + _In_z_ LPCOLESTR bstrFileName, + _In_ BOOL bRegister) +{ + USES_CONVERSION_EX; + + CRegParser parser(this); + + LPCTSTR lpszBSTRFileName = OLE2CT_EX(bstrFileName, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); +#ifndef _UNICODE + if (lpszBSTRFileName == NULL) + { + return E_OUTOFMEMORY; + } +#endif // _UNICODE + + HANDLE hFile = CreateFile(lpszBSTRFileName, GENERIC_READ, 0, NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_READONLY, + NULL); + if (INVALID_HANDLE_VALUE == hFile) + { + return AtlHresultFromLastError(); + } + + HRESULT hRes = S_OK; + DWORD cbRead; + DWORD cbFile = GetFileSize(hFile, NULL); // No HiOrder DWORD required + + CTempBuffer szReg; + // Extra space for NULL. + ATLTRY(szReg.Allocate(cbFile + 1)); + if (szReg == NULL) + { + hRes = E_OUTOFMEMORY; + goto ReturnHR; + } + + if (ReadFile(hFile, szReg, cbFile, &cbRead, NULL) == 0) + { + hRes = AtlHresultFromLastError(); + } + if (SUCCEEDED(hRes)) + { + szReg[cbRead] = '\0'; + +#ifdef _UNICODE + CTempBuffer szConverted; + ATLTRY(szConverted.Allocate(cbFile + 1)); + if (szConverted == NULL) + { + hRes = E_OUTOFMEMORY; + goto ReturnHR; + + } + if (::MultiByteToWideChar(_AtlGetConversionACP(), 0, szReg, cbFile + 1, szConverted, cbFile + 1) == 0) + { + hRes = AtlHresultFromLastError(); + goto ReturnHR; + } +#else + LPTSTR szConverted = szReg; +#endif + hRes = parser.RegisterBuffer(szConverted, bRegister); + } +ReturnHR: + CloseHandle(hFile); + return hRes; +} + +__declspec(selectany) const TCHAR* const CRegParser::rgszNeverDelete[] = +{ + _T("AppID"), + _T("CLSID"), + _T("Component Categories"), + _T("FileType"), + _T("Interface"), + _T("Hardware"), + _T("Mime"), + _T("SAM"), + _T("SECURITY"), + _T("SYSTEM"), + _T("Software"), + _T("TypeLib") +}; + +__declspec(selectany) const int CRegParser::cbNeverDelete = sizeof(rgszNeverDelete) / sizeof(LPCTSTR*); + + +inline BOOL CRegParser::VTFromRegType( + _In_z_ LPCTSTR szValueType, + _Out_ VARTYPE& vt) +{ + struct typemap + { + LPCTSTR lpsz; + VARTYPE vt; + }; +#pragma warning (push) +#pragma warning (disable : 4640) // construction of local static object is not thread-safe + + static const typemap map[] = { + {szStringVal, VT_BSTR}, + {multiszStringVal, VT_BSTR | VT_BYREF}, + {szDwordVal, VT_UI4}, + {szBinaryVal, VT_UI1} + }; + +#pragma warning (pop) + + for (int i=0;i= szOrig + MAX_VALUE) + return GenerateError(E_ATL_VALUE_TOO_LARGE); + + for (int i = 0; i < (int)nChars; i++, szToken++, pchPrev++) + *szToken = *pchPrev; + } + + if (_T('\0') == *m_pchCur) + { + return GenerateError(E_ATL_UNEXPECTED_EOS); + } + + *szToken = _T('\0'); + m_pchCur = CharNext(m_pchCur); + } + + else + { + // Handle non-quoted ie parse up till first "White Space" + while (_T('\0') != *m_pchCur && !IsSpace(*m_pchCur)) + { + LPTSTR pchPrev = m_pchCur; + m_pchCur = CharNext(m_pchCur); + + INT_PTR nChars = m_pchCur - pchPrev; + + // Make sure we have room for nChars plus terminating NULL + if ((szToken + nChars + 1) >= szOrig + MAX_VALUE) + return GenerateError(E_ATL_VALUE_TOO_LARGE); + + for (int i = 0; i < (int)nChars; i++, szToken++, pchPrev++) + *szToken = *pchPrev; + } + + *szToken = _T('\0'); + } + return S_OK; +} + +#pragma warning(push) +#pragma warning(disable:6385) // suppressing code analysis warning on the GenerateError code path +inline HRESULT CRegParser::AddValue( + _Inout_ CRegKey& rkParent, + _In_opt_z_ LPCTSTR szValueName, + _Out_z_cap_c_(MAX_VALUE) LPTSTR szToken) +{ + HRESULT hr; + + TCHAR szValue[MAX_VALUE]; + VARTYPE vt = VT_EMPTY; + LONG lRes = ERROR_SUCCESS; + UINT nIDRes = 0; + + if (FAILED(hr = NextToken(szValue))) + return hr; + if (!VTFromRegType(szValue, vt)) + { + return GenerateError(E_ATL_TYPE_NOT_SUPPORTED); + } +#pragma warning(pop) + + SkipWhiteSpace(); + if (FAILED(hr = NextToken(szValue))) + return hr; + + switch (vt) + { + case VT_BSTR: + { + lRes = rkParent.SetStringValue(szValueName, szValue); + break; + } + case VT_BSTR | VT_BYREF: + { + int nLen = lstrlen(szValue) + 2; //Allocate space for double null termination. + CTempBuffer pszDestValue; + //nLen should be >= the max size of the target buffer. + ATLTRY(pszDestValue.Allocate(nLen)); + if (pszDestValue != NULL) + { + TCHAR* p = pszDestValue; + TCHAR* q = szValue; + nLen = 0; + while (*q != _T('\0')) + { + TCHAR* r = CharNext(q); + if (*q == _T('\\') && *r == _T('0')) + { + *p++ = _T('\0'); + q = CharNext(r); + } + else + { + *p = *q; +#ifndef _UNICODE + if (IsDBCSLeadByte(*q)) + { + p++; + q++; + //Protect from Lead byte followed by the zero terminator.May skip beyond the end of the string. + if (*q == _T('\0')) { break; } + *p = *q; + } +#endif + p++; + q++; + } + nLen ++; + } + //Always terminate with 2 null characters. + *p = _T('\0'); + p++; + *p = _T('\0'); + lRes = rkParent.SetMultiStringValue(szValueName, pszDestValue); + } + else + { + lRes = ERROR_OUTOFMEMORY; + } + } + break; + case VT_UI4: + { + ULONG ulVal; + USES_CONVERSION_EX; + + LPOLESTR lpszV = T2OLE_EX(szValue, _ATL_SAFE_ALLOCA_DEF_THRESHOLD); + #ifndef _UNICODE + if(lpszV == NULL) + return E_OUTOFMEMORY; + #endif + VarUI4FromStr(lpszV, 0, 0, &ulVal); + + lRes = rkParent.SetDWORDValue(szValueName, ulVal); + break; + } + case VT_UI1: + { + int cbValue = lstrlen(szValue); + if (cbValue & 0x00000001) + { + return E_FAIL; + } + int cbValDiv2 = cbValue/2; + CTempBuffer rgBinary; + ATLTRY(rgBinary.Allocate(cbValDiv2)); + if (rgBinary == NULL) + return E_FAIL; + memset(rgBinary, 0, cbValDiv2); + for (int irg = 0; irg < cbValue; irg++) + rgBinary[(irg/2)] |= (ChToByte(szValue[irg])) << (4*(1 - (irg & 0x00000001))); + lRes = RegSetValueEx(rkParent, szValueName, 0, REG_BINARY, rgBinary, cbValDiv2); + break; + } + } + + if (ERROR_SUCCESS != lRes) + { + nIDRes = E_ATL_VALUE_SET_FAILED; + return AtlHresultFromWin32(lRes); + } + + if (FAILED(hr = NextToken(szToken))) + return hr; + + return S_OK; +} + +inline BOOL CRegParser::CanForceRemoveKey(_In_z_ LPCTSTR szKey) +{ + for (int iNoDel = 0; iNoDel < cbNeverDelete; iNoDel++) + if (!lstrcmpi(szKey, rgszNeverDelete[iNoDel])) + return FALSE; // We cannot delete it + + return TRUE; +} + +inline BOOL CRegParser::HasSubKeys(_In_ HKEY hkey) +{ + DWORD cSubKeys = 0; + + if (RegQueryInfoKeyW(hkey, NULL, NULL, NULL, + &cSubKeys, NULL, NULL, + NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) + { + ATLASSERT(FALSE); + return FALSE; + } + + return cSubKeys > 0; +} + +inline BOOL CRegParser::HasValues(_In_ HKEY hkey) +{ + DWORD cValues = 0; + DWORD cMaxValueNameLen; + + LONG lResult = RegQueryInfoKeyW(hkey, NULL, NULL, NULL, + NULL, NULL, NULL, + &cValues, &cMaxValueNameLen, NULL, NULL, NULL); + if (ERROR_SUCCESS != lResult) + { + ATLASSERT(FALSE); + return FALSE; + } + + if ((1 == cValues) && (0 == cMaxValueNameLen)) + { + return FALSE; + } + + return cValues > 0; // More than 1 means we have a non-default value +} + +inline HRESULT CRegParser::SkipAssignment(_Inout_z_cap_c_(MAX_VALUE) LPTSTR szToken) +{ + HRESULT hr; + TCHAR szValue[MAX_VALUE]; + + if (*szToken == chEquals) + { + if (FAILED(hr = NextToken(szToken))) + return hr; + // Skip assignment + SkipWhiteSpace(); + if (FAILED(hr = NextToken(szValue))) + return hr; + if (FAILED(hr = NextToken(szToken))) + return hr; + } + + return S_OK; +} + +ATLPREFAST_SUPPRESS(6387) +inline HRESULT CRegParser::PreProcessBuffer( + _In_z_ LPTSTR lpszReg, + _Deref_out_z_ LPTSTR* ppszReg) +{ + ATLASSERT(lpszReg != NULL); + ATLASSERT(ppszReg != NULL); + + if (lpszReg == NULL || ppszReg == NULL) + return E_POINTER; + + *ppszReg = NULL; + int nSize = lstrlen(lpszReg)*2; + CParseBuffer pb(nSize); + if (pb.p == NULL) + return E_OUTOFMEMORY; + m_pchCur = lpszReg; + HRESULT hr = S_OK; + + bool bRedirectionEnabled = false; + hr = AtlGetPerUserRegistration(&bRedirectionEnabled); + if( FAILED(hr) ) + { + return hr; + } + + // nNestingLevel is used to avoid checking for unnecessary root key replacements + // since all of them are expected to be at the top level. + int nNestingLevel = 0; + bool bRedirectionPresent = false; + bool bInsideQuotes = false; + + while (*m_pchCur != _T('\0')) // look for end + { + if ( true == bRedirectionEnabled ) + { + LPCOLESTR szStartHKCU = L"HKCU\r\n{\tSoftware\r\n\t{\r\n\t\tClasses"; + LPCOLESTR szEndHKCU = L"\r\n\t}\r\n}\r\n"; + + if ( 0 == nNestingLevel ) + { + // Then we should be reading a root key. HKCR, HKCU, etc + TCHAR* szRootKey = NULL; + if( NULL != ( szRootKey = _tcsstr(m_pchCur, _T("HKCR")) ) && // if HKCR is found. + (szRootKey == m_pchCur) ) // if HKCR is the first token. + { + // Skip HKCR + m_pchCur = CharNext(m_pchCur); + m_pchCur = CharNext(m_pchCur); + m_pchCur = CharNext(m_pchCur); + m_pchCur = CharNext(m_pchCur); + + // Add HKCU + if (!pb.AddString(szStartHKCU)) + { + hr = E_OUTOFMEMORY; + break; + } + + bRedirectionPresent = true; + } + } + + if ( chQuote == *m_pchCur ) + { + if( false == bInsideQuotes ) + { + bInsideQuotes = true; + } + else + { + // Make sure it is not an escaped sequence. + if( EndOfVar() ) + { + bInsideQuotes = false; + } + else + { + // An escaped single quote... + m_pchCur = CharNext(m_pchCur); + if (!pb.AddChar(m_pchCur)) + { + hr = E_OUTOFMEMORY; + break; + } + } + } + } + + if ( (false == bInsideQuotes) && (*m_pchCur == _T('{')) ) + { + ++nNestingLevel; + } + + if ( (false == bInsideQuotes) && (*m_pchCur == _T('}')) ) + { + --nNestingLevel; + if ( (0 == nNestingLevel) && (true == bRedirectionPresent) ) + { + if (!pb.AddString(szEndHKCU)) + { + hr = E_OUTOFMEMORY; + break; + } + + bRedirectionPresent = false; + } + } + } + + if (*m_pchCur == _T('%')) + { + m_pchCur = CharNext(m_pchCur); + if (*m_pchCur == _T('%')) + { + if (!pb.AddChar(m_pchCur)) + { + hr = E_OUTOFMEMORY; + break; + } + } + else + { + LPTSTR lpszNext = StrChr(m_pchCur, _T('%')); + if (lpszNext == NULL) + { + hr = GenerateError(E_ATL_UNEXPECTED_EOS); + break; + } + if ((lpszNext-m_pchCur) > 31) + { + hr = E_FAIL; + break; + } + int nLength = int(lpszNext - m_pchCur); + TCHAR buf[32]; + Checked::tcsncpy_s(buf, _countof(buf), m_pchCur, nLength); + LPCOLESTR lpszVar = m_pRegObj->StrFromMap(buf); + if (lpszVar == NULL) + { + hr = GenerateError(E_ATL_NOT_IN_MAP); + break; + } + if (!pb.AddString(lpszVar)) + { + hr = E_OUTOFMEMORY; + break; + } + + while (m_pchCur != lpszNext) + m_pchCur = CharNext(m_pchCur); + } + } + else + { + if (!pb.AddChar(m_pchCur)) + { + hr = E_OUTOFMEMORY; + break; + } + } + + m_pchCur = CharNext(m_pchCur); + } + if (SUCCEEDED(hr)) + *ppszReg = pb.Detach(); + return hr; +} +ATLPREFAST_UNSUPPRESS() + +inline HRESULT CRegParser::RegisterBuffer( + _In_z_ LPTSTR szBuffer, + _In_ BOOL bRegister) +{ + TCHAR szToken[MAX_VALUE]; + HRESULT hr = S_OK; + + LPTSTR szReg = NULL; + hr = PreProcessBuffer(szBuffer, &szReg); + if (FAILED(hr)) + return hr; + + m_pchCur = szReg; + + // Preprocess szReg + + while (_T('\0') != *m_pchCur) + { + if (FAILED(hr = NextToken(szToken))) + break; + HKEY hkBase; + if ((hkBase = HKeyFromString(szToken)) == NULL) + { + hr = GenerateError(E_ATL_BAD_HKEY); + break; + } + + if (FAILED(hr = NextToken(szToken))) + break; + + if (chLeftBracket != *szToken) + { + hr = GenerateError(E_ATL_MISSING_OPENKEY_TOKEN); + break; + } + if (bRegister) + { + LPTSTR szRegAtRegister = m_pchCur; + hr = RegisterSubkeys(szToken, hkBase, bRegister); + if (FAILED(hr)) + { + m_pchCur = szRegAtRegister; + RegisterSubkeys(szToken, hkBase, FALSE); + break; + } + } + else + { + if (FAILED(hr = RegisterSubkeys(szToken, hkBase, bRegister))) + break; + } + + SkipWhiteSpace(); + } + CoTaskMemFree(szReg); + return hr; +} + +inline HRESULT CRegParser::RegisterSubkeys( + _Out_z_cap_c_(MAX_VALUE) LPTSTR szToken, + _In_ HKEY hkParent, + _In_ BOOL bRegister, + _In_ BOOL bRecover) +{ + CRegKey keyCur; + LONG lRes; + TCHAR szKey[_MAX_PATH]; + BOOL bDelete = TRUE; + BOOL bInRecovery = bRecover; + HRESULT hr = S_OK; + + if (FAILED(hr = NextToken(szToken))) + return hr; + + while (*szToken != chRightBracket) // Continue till we see a } + { + bDelete = TRUE; + BOOL bTokenDelete = !lstrcmpi(szToken, szDelete); + + if (!lstrcmpi(szToken, szForceRemove) || bTokenDelete) + { + if (FAILED(hr = NextToken(szToken))) + break; + + if (bRegister) + { + CRegKey rkForceRemove; + + if (StrChr(szToken, chDirSep) != NULL) + return GenerateError(E_ATL_COMPOUND_KEY); + + if (CanForceRemoveKey(szToken)) + { + rkForceRemove.Attach(hkParent); + // Error not returned. We will overwrite the values any way. + rkForceRemove.RecurseDeleteKey(szToken); + rkForceRemove.Detach(); + } + if (bTokenDelete) + { + if (FAILED(hr = NextToken(szToken))) + break; + if (FAILED(hr = SkipAssignment(szToken))) + break; + goto EndCheck; + } + } + } + + if (!lstrcmpi(szToken, szNoRemove)) + { + bDelete = FALSE; // set even for register + if (FAILED(hr = NextToken(szToken))) + break; + } + + if (!lstrcmpi(szToken, szValToken)) // need to add a value to hkParent + { + TCHAR szValueName[MAX_VALUE]; + + if (FAILED(hr = NextToken(szValueName))) + break; + if (FAILED(hr = NextToken(szToken))) + break; + + if (*szToken != chEquals) + return GenerateError(E_ATL_EXPECTING_EQUAL); + + if (bRegister) + { + CRegKey rk; + + rk.Attach(hkParent); + hr = AddValue(rk, szValueName, szToken); + rk.Detach(); + + if (FAILED(hr)) + return hr; + + goto EndCheck; + } + else + { + if (!bRecover && bDelete) + { + // We have to open the key for write to be able to delete. + CRegKey rkParent; + lRes = rkParent.Open(hkParent, NULL, KEY_WRITE); + if (lRes == ERROR_SUCCESS) + { + lRes = rkParent.DeleteValue(szValueName); + if (lRes != ERROR_SUCCESS && lRes != ERROR_FILE_NOT_FOUND) + { + // Key not present is not an error + hr = AtlHresultFromWin32(lRes); + break; + } + } + else + { + hr = AtlHresultFromWin32(lRes); + break; + } + } + if (FAILED(hr = SkipAssignment(szToken))) + break; + continue; // can never have a subkey + } + } + + if (StrChr(szToken, chDirSep) != NULL) + return GenerateError(E_ATL_COMPOUND_KEY); + + if (bRegister) + { + lRes = keyCur.Open(hkParent, szToken, KEY_READ | KEY_WRITE); + if (ERROR_SUCCESS != lRes) + { + // Failed all access try read only + lRes = keyCur.Open(hkParent, szToken, KEY_READ); + if (ERROR_SUCCESS != lRes) + { + // Finally try creating it + lRes = keyCur.Create(hkParent, szToken, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE); + if (lRes != ERROR_SUCCESS) + return AtlHresultFromWin32(lRes); + } + } + + if (FAILED(hr = NextToken(szToken))) + break; + + + if (*szToken == chEquals) + { + if (FAILED(hr = AddValue(keyCur, NULL, szToken))) // NULL == default + break; + } + } + else //Unregister + { + if (!bRecover) + { + lRes = keyCur.Open(hkParent, szToken, KEY_READ); + + } + else + lRes = ERROR_FILE_NOT_FOUND; + + + // Open failed set recovery mode + if (lRes != ERROR_SUCCESS) + bRecover = true; + + // TRACE out Key open status and if in recovery mode + + // Remember Subkey + Checked::tcsncpy_s(szKey, _countof(szKey), szToken, _TRUNCATE); + + if (FAILED(hr = NextToken(szToken))) + break; + if (FAILED(hr = SkipAssignment(szToken))) + break; + + if (*szToken == chLeftBracket && lstrlen(szToken) == 1) + { + hr = RegisterSubkeys(szToken, keyCur.m_hKey, bRegister, bRecover); + // In recover mode ignore error + if (FAILED(hr) && !bRecover) + break; + // Skip the } + if (FAILED(hr = NextToken(szToken))) + break; + } + bRecover = bInRecovery; + + if (lRes == ERROR_FILE_NOT_FOUND) + // Key already not present so not an error. + continue; + + if (lRes != ERROR_SUCCESS) + { + // We are recovery mode continue on errors else break + if (bRecover) + continue; + else + { + hr = AtlHresultFromWin32(lRes); + break; + } + } + + // If in recovery mode + if (bRecover && HasSubKeys(keyCur)) + { + // See if the KEY is in the NeverDelete list and if so, don't + if (CanForceRemoveKey(szKey) && bDelete) + { + // Error not returned since we are in recovery mode. The error that caused recovery mode is returned + keyCur.RecurseDeleteKey(szKey); + } + continue; + } + + BOOL bHasSubKeys=HasSubKeys(keyCur); + lRes = keyCur.Close(); + if (lRes != ERROR_SUCCESS) + return AtlHresultFromWin32(lRes); + + if (bDelete&& !bHasSubKeys) + { + CRegKey rkParent; + rkParent.Attach(hkParent); + lRes = rkParent.DeleteSubKey(szKey); + rkParent.Detach(); + if (lRes != ERROR_SUCCESS) + { + + hr = AtlHresultFromWin32(lRes); + break; + } + } + } + +EndCheck: + + if (bRegister) + { + if (*szToken == chLeftBracket && lstrlen(szToken) == 1) + { + if (FAILED(hr = RegisterSubkeys(szToken, keyCur.m_hKey, bRegister, FALSE))) + break; + if (FAILED(hr = NextToken(szToken))) + break; + } + } + } + + return hr; +} + +}; //namespace ATL + +#pragma pack(pop) +#pragma warning(pop) + +#endif //__STATREG_H__