<file_sep>// stdafx.h : include file for standard system include files
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and Microsoft
// QuickHelp and/or WinHelp documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

#define AFX_CRT_ERRORCHECK(expr) \
	AtlCrtErrorCheck(expr)

#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxole.h>
#include <afxcmn.h>
#include <afxpriv.h>
#include <atlbase.h>
#include <atlwin.h>
#include "windowsx.h"
#include "ehvecdtr.h"
#include <xstddef>

#pragma warning( disable: 4706 4100 )


_STD_BEGIN
extern "C" {
	//using ::exception;

	using ::terminate_handler;
	using ::unexpected;
	using ::unexpected_handler;
};
_STD_END

extern "C" inline __declspec(noreturn) void __cdecl __std_terminate(void) { ::terminate(); }
<file_sep>/***
*ehvecdtr.cxx - EH-aware version of destructor iterator helper function
*
*       Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
*       These functions are called when constructing and destructing arrays of
*       objects.  Their purpose is to assure that constructed elements get
*       destructed if the constructor for one of the elements throws.
*
*       Must be compiled using "-d1Binl" to be able to specify __thiscall
*       at the user level
****/
#pragma once

#include "ehdata.h"
#include <eh.h>

#if defined _M_CEE
    #define CALLTYPE  __clrcall
    #define CALLEETYPE __clrcall
    #define __RELIABILITY_CONTRACT                                                   \
        [System::Runtime::ConstrainedExecution::ReliabilityContract(                 \
            System::Runtime::ConstrainedExecution::Consistency::WillNotCorruptState, \
            System::Runtime::ConstrainedExecution::Cer::Success                      \
        )]

    #define ASSERT_UNMANAGED_CODE_ATTRIBUTE [System::Security::Permissions::SecurityPermissionAttribute(System::Security::Permissions::SecurityAction::Assert, UnmanagedCode = true)]
    #define SECURITYCRITICAL_ATTRIBUTE      [System::Security::SecurityCritical]
#else
    #define CALLEETYPE __stdcall
    #define __RELIABILITY_CONTRACT
    #define ASSERT_UNMANAGED_CODE_ATTRIBUTE
    #define SECURITYCRITICAL_ATTRIBUTE

    #if defined _M_IX86
        #define CALLTYPE __thiscall
    #else
        #define CALLTYPE __stdcall
    #endif
#endif

using destructor_type = void (CALLTYPE*)(void*);

__RELIABILITY_CONTRACT
void CALLEETYPE __ArrayUnwind(
    void*           ptr,            // Pointer to array to destruct
    size_t          size,           // Size of each element (including padding)
    size_t          count,          // Number of elements in the array
    destructor_type destructor      // The destructor to call
    );

__RELIABILITY_CONTRACT
SECURITYCRITICAL_ATTRIBUTE
inline void CALLEETYPE __ehvec_dtor(
    void*           ptr,            // Pointer to array to destruct
    size_t          size,           // Size of each element (including padding)
    size_t          count,          // Number of elements in the array
    destructor_type destructor      // The destructor to call
    )
{
    bool success{false};

    // Advance pointer past end of array
    ptr = static_cast<char*>(ptr) + size * count;

    __try
    {
        // Destruct elements
        while (count-- > 0)
        {
            ptr = static_cast<char*>(ptr) - size;
            destructor(ptr);
        }

        success = true;
    }
    __finally
    {
        if (!success)
        {
            __ArrayUnwind(ptr, size, count, destructor);
        }
    }
}

__RELIABILITY_CONTRACT
ASSERT_UNMANAGED_CODE_ATTRIBUTE
SECURITYCRITICAL_ATTRIBUTE
static int ArrayUnwindFilter(EXCEPTION_POINTERS* pExPtrs)
{
    EHExceptionRecord *pExcept = (EHExceptionRecord*)pExPtrs->ExceptionRecord;

    switch(PER_CODE(pExcept))
    {
        case EH_EXCEPTION_NUMBER:
			terminate();
#ifdef ALLOW_UNWIND_ABORT
        case EH_ABORT_FRAME_UNWIND_PART:
            return EXCEPTION_EXECUTE_HANDLER;
#endif
        default:
            return EXCEPTION_CONTINUE_SEARCH;
    }
}

__RELIABILITY_CONTRACT
SECURITYCRITICAL_ATTRIBUTE
inline void CALLEETYPE __ArrayUnwind(
    void*           ptr,          // Pointer to array to destruct
    size_t          size,         // Size of each element (including padding)
    size_t          count,        // Number of elements in the array
    destructor_type destructor    // The destructor to call
    )
{
    // 'unwind' rest of array

    __try
    {
        for (size_t i{0}; i != count; ++i)
        {
            ptr = static_cast<char*>(ptr) - size;
            destructor(ptr);
        }
    }
    __except(ArrayUnwindFilter(exception_info()))
    {
        ; // Deliberately do nothing
    }
}

__RELIABILITY_CONTRACT
SECURITYCRITICAL_ATTRIBUTE
inline void CALLEETYPE __ehvec_dtor(
    void*           ptr,            // Pointer to array to destruct
    size_t          size,           // Size of each element (including padding)
    int             count,          // Number of elements in the array
    destructor_type destructor      // The destructor to call
    )
{
    __ehvec_dtor(ptr, size, static_cast<size_t>(count), destructor);
}