-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmfcdual.cpp
executable file
·125 lines (104 loc) · 4.15 KB
/
mfcdual.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
///////////////////////////////////////////////////////////////////////
// XBeamRate - Cross Beam Load Rating
// Copyright © 1999-2025 Washington State Department of Transportation
// Bridge and Structures Office
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the Alternate Route Open Source License as
// published by the Washington State Department of Transportation,
// Bridge and Structures Office.
//
// This program is distributed in the hope that it will be useful, but
// distribution is AS IS, WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
// the Alternate Route Open Source License for more details.
//
// You should have received a copy of the Alternate Route Open Source
// License along with this program; if not, write to the Washington
// State Department of Transportation, Bridge and Structures Office,
// P.O. Box 47340, Olympia, WA 98503, USA or e-mail
///////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <afxpriv.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern "C"
{
/////////////////////////////////////////////////////////////////////////////
// DualHandleException
HRESULT DualHandleException(REFIID riidSource, const CException* pAnyException)
{
USES_CONVERSION;
ASSERT_VALID(pAnyException);
TRACE0("DualHandleException called\n");
// Set ErrInfo object so that VTLB binding container
// applications can get rich error information.
ICreateErrorInfo* pcerrinfo;
HRESULT hr = CreateErrorInfo(&pcerrinfo);
if (SUCCEEDED(hr))
{
TCHAR szDescription[256];
LPCTSTR pszDescription = szDescription;
GUID guid = GUID_NULL;
DWORD dwHelpContext = 0;
BSTR bstrHelpFile = nullptr;
BSTR bstrSource = nullptr;
if (pAnyException->IsKindOf(RUNTIME_CLASS(COleDispatchException)))
{
// specific IDispatch style exception
COleDispatchException* e = (COleDispatchException*)pAnyException;
guid = riidSource;
hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF,
(e->m_wCode + 0x200));
pszDescription = e->m_strDescription;
dwHelpContext = e->m_dwHelpContext;
// propagate source and help file if present
// call ::SysAllocString directly so no further exceptions are thrown
if (!e->m_strHelpFile.IsEmpty())
bstrHelpFile = ::SysAllocString(T2COLE(e->m_strHelpFile));
if (!e->m_strSource.IsEmpty())
bstrSource = ::SysAllocString(T2COLE(e->m_strSource));
}
else if (pAnyException->IsKindOf(RUNTIME_CLASS(CMemoryException)))
{
// failed memory allocation
AfxLoadString(AFX_IDP_FAILED_MEMORY_ALLOC, szDescription);
hr = E_OUTOFMEMORY;
}
else
{
// other unknown/uncommon error
AfxLoadString(AFX_IDP_INTERNAL_FAILURE, szDescription);
hr = E_UNEXPECTED;
}
if (bstrHelpFile == nullptr && dwHelpContext != 0)
bstrHelpFile = ::SysAllocString(T2COLE(AfxGetApp()->m_pszHelpFilePath));
if (bstrSource == nullptr)
bstrSource = ::SysAllocString(T2COLE(AfxGetAppName()));
// Set up ErrInfo object
pcerrinfo->SetGUID(guid);
pcerrinfo->SetDescription(::SysAllocString(T2COLE(pszDescription)));
pcerrinfo->SetHelpContext(dwHelpContext);
pcerrinfo->SetHelpFile(bstrHelpFile);
pcerrinfo->SetSource(bstrSource);
TRACE("\tSource = %ws\n", bstrSource);
TRACE("\tDescription = %s\n", pszDescription);
TRACE("\tHelpContext = %lx\n", dwHelpContext);
TRACE("\tHelpFile = %ws\n", bstrHelpFile);
// Set the ErrInfo object for the current thread
IErrorInfo* perrinfo;
if (SUCCEEDED(pcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID*)&perrinfo)))
{
SetErrorInfo(0, perrinfo);
perrinfo->Release();
}
pcerrinfo->Release();
}
TRACE("DualHandleException returning HRESULT %lx\n", hr);
return hr;
}
} // extern "C"