diff --git a/src/coreclr/inc/ex.h b/src/coreclr/inc/ex.h index 50949d62f01384..9a0cad2b210226 100644 --- a/src/coreclr/inc/ex.h +++ b/src/coreclr/inc/ex.h @@ -192,8 +192,10 @@ class Exception virtual BOOL IsDomainBound() {return m_innerException!=NULL && m_innerException->IsDomainBound();} ; virtual HRESULT GetHR() = 0; virtual void GetMessage(SString &s); +#ifdef FEATURE_COMINTEROP virtual IErrorInfo *GetErrorInfo() { LIMITED_METHOD_CONTRACT; return NULL; } virtual HRESULT SetErrorInfo() { LIMITED_METHOD_CONTRACT; return S_OK; } +#endif // FEATURE_COMINTEROP void SetInnerException(Exception * pInnerException) { LIMITED_METHOD_CONTRACT; m_innerException = pInnerException; } // Dynamic type query for catchers @@ -432,8 +434,10 @@ class COMException : public HRException { friend bool DebugIsEECxxExceptionPointer(void* pv); +#ifdef FEATURE_COMINTEROP private: IErrorInfo *m_pErrorInfo; +#endif // FEATURE_COMINTEROP public: COMException(); @@ -488,7 +492,9 @@ class SEHException : public Exception // Virtual overrides HRESULT GetHR(); +#ifdef FEATURE_COMINTEROP IErrorInfo *GetErrorInfo(); +#endif // FEATURE_COMINTEROP void GetMessage(SString &result); protected: @@ -533,7 +539,9 @@ class DelegatingException : public Exception // Virtual overrides virtual BOOL IsDomainBound() {return Exception::IsDomainBound() ||(m_delegatedException!=NULL && m_delegatedException->IsDomainBound());} ; HRESULT GetHR(); +#ifdef FEATURE_COMINTEROP IErrorInfo *GetErrorInfo(); +#endif // FEATURE_COMINTEROP void GetMessage(SString &result); virtual Exception *Clone(); @@ -1290,15 +1298,19 @@ inline HRMsgException::HRMsgException(HRESULT hr, SString const &s) } inline COMException::COMException() - : HRException(), - m_pErrorInfo(NULL) + : HRException() +#ifdef FEATURE_COMINTEROP + , m_pErrorInfo(NULL) +#endif // FEATURE_COMINTEROP { WRAPPER_NO_CONTRACT; } inline COMException::COMException(HRESULT hr) - : HRException(hr), - m_pErrorInfo(NULL) + : HRException(hr) +#ifdef FEATURE_COMINTEROP + , m_pErrorInfo(NULL) +#endif // FEATURE_COMINTEROP { LIMITED_METHOD_CONTRACT; } diff --git a/src/coreclr/pal/inc/rt/oaidl.h b/src/coreclr/pal/inc/rt/oaidl.h deleted file mode 100644 index ed7491c5840e1d..00000000000000 --- a/src/coreclr/pal/inc/rt/oaidl.h +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -// -// =========================================================================== -// File: oaidl.h -// -// =========================================================================== - -#ifndef __OAIDL_H__ -#define __OAIDL_H__ - -// Pointer to IErrorInfo is still used in non-Windows code -// Prevent accidentally using its member -struct IErrorInfo; - -#endif //__OAIDL_H__ diff --git a/src/coreclr/pal/inc/rt/ole2.h b/src/coreclr/pal/inc/rt/ole2.h index f51d41e04b057f..260e051b43fcab 100644 --- a/src/coreclr/pal/inc/rt/ole2.h +++ b/src/coreclr/pal/inc/rt/ole2.h @@ -7,5 +7,4 @@ #include "objidl.h" #include "servprov.h" -#include "oaidl.h" diff --git a/src/coreclr/pal/inc/rt/oleauto.h b/src/coreclr/pal/inc/rt/oleauto.h index 15db2c3912e9a7..663faf6be54d24 100644 --- a/src/coreclr/pal/inc/rt/oleauto.h +++ b/src/coreclr/pal/inc/rt/oleauto.h @@ -11,7 +11,6 @@ #ifndef _OLEAUTO_H_ #define _OLEAUTO_H_ -#include "oaidl.h" #ifndef BEGIN_INTERFACE #define BEGIN_INTERFACE diff --git a/src/coreclr/pal/prebuilt/inc/metahost.h b/src/coreclr/pal/prebuilt/inc/metahost.h index e35cb6e140679f..e0fc0fc0680373 100644 --- a/src/coreclr/pal/prebuilt/inc/metahost.h +++ b/src/coreclr/pal/prebuilt/inc/metahost.h @@ -82,7 +82,6 @@ typedef interface ICLRRuntimeInfo ICLRRuntimeInfo; /* header files for imported files */ #include "unknwn.h" -#include "oaidl.h" #include "ocidl.h" #include "mscoree.h" diff --git a/src/coreclr/utilcode/ex.cpp b/src/coreclr/utilcode/ex.cpp index adee9ba55618ca..8197e4f0ef72cb 100644 --- a/src/coreclr/utilcode/ex.cpp +++ b/src/coreclr/utilcode/ex.cpp @@ -811,11 +811,13 @@ HRESULT SEHException::GetHR() return m_exception.ExceptionCode; } +#ifdef FEATURE_COMINTEROP IErrorInfo *SEHException::GetErrorInfo() { LIMITED_METHOD_CONTRACT; return NULL; } +#endif // FEATURE_COMINTEROP void SEHException::GetMessage(SString &string) { @@ -896,6 +898,7 @@ HRESULT DelegatingException::GetHR() } // HRESULT DelegatingException::GetHR() +#ifdef FEATURE_COMINTEROP //------------------------------------------------------------------------------ IErrorInfo *DelegatingException::GetErrorInfo() { @@ -909,6 +912,7 @@ IErrorInfo *DelegatingException::GetErrorInfo() return pDelegate ? pDelegate->GetErrorInfo() : NULL; } // IErrorInfo *DelegatingException::GetErrorInfo() +#endif // FEATURE_COMINTEROP //------------------------------------------------------------------------------ void DelegatingException::GetMessage(SString &result) diff --git a/src/coreclr/vm/clrex.cpp b/src/coreclr/vm/clrex.cpp index 7b68ac1dcba82e..947f5eeb992f17 100644 --- a/src/coreclr/vm/clrex.cpp +++ b/src/coreclr/vm/clrex.cpp @@ -366,18 +366,6 @@ IErrorInfo *CLRException::GetErrorInfo() // return the IErrorInfo we got... return pErrorInfo; } -#else // FEATURE_COMINTEROP -IErrorInfo *CLRException::GetErrorInfo() -{ - LIMITED_METHOD_CONTRACT; - return NULL; -} -HRESULT CLRException::SetErrorInfo() -{ - LIMITED_METHOD_CONTRACT; - - return S_OK; - } #endif // FEATURE_COMINTEROP void CLRException::GetMessage(SString &result) @@ -698,6 +686,7 @@ OBJECTREF CLRException::GetThrowableFromException(Exception *pException) } else { +#ifdef FEATURE_COMINTEROP SafeComHolder pErrInfo(pException->GetErrorInfo()); if (pErrInfo != NULL) @@ -705,6 +694,7 @@ OBJECTREF CLRException::GetThrowableFromException(Exception *pException) GetExceptionForHR(hr, pErrInfo, &oRetVal); } else +#endif // FEATURE_COMINTEROP { SString message; pException->GetMessage(message); @@ -938,12 +928,14 @@ HRESULT EEException::GetHR() return EEException::GetHRFromKind(m_kind); } +#ifdef FEATURE_COMINTEROP IErrorInfo *EEException::GetErrorInfo() { LIMITED_METHOD_CONTRACT; return NULL; } +#endif // FEATURE_COMINTEROP BOOL EEException::GetThrowableMessage(SString &result) { diff --git a/src/coreclr/vm/clrex.h b/src/coreclr/vm/clrex.h index 586798f397fab3..2426ac7401c80d 100644 --- a/src/coreclr/vm/clrex.h +++ b/src/coreclr/vm/clrex.h @@ -129,8 +129,10 @@ class CLRException : public Exception } HRESULT GetHR(); +#ifdef FEATURE_COMINTEROP IErrorInfo *GetErrorInfo(); HRESULT SetErrorInfo(); +#endif // FEATURE_COMINTEROP void GetMessage(SString &result); @@ -222,7 +224,9 @@ class EEException : public CLRException // Virtual overrides HRESULT GetHR(); +#ifdef FEATURE_COMINTEROP IErrorInfo *GetErrorInfo(); +#endif // FEATURE_COMINTEROP void GetMessage(SString &result); OBJECTREF CreateThrowable(); @@ -842,6 +846,7 @@ LONG CLRNoCatchHandler(EXCEPTION_POINTERS* pExceptionInfo, PVOID pv); // // Thus, the scoped use of FAULT_NOT_FATAL macro. #undef EX_CATCH_HRESULT +#ifdef FEATURE_COMINTEROP #define EX_CATCH_HRESULT(_hr) \ EX_CATCH \ { \ @@ -857,6 +862,15 @@ LONG CLRNoCatchHandler(EXCEPTION_POINTERS* pExceptionInfo, PVOID pv); _ASSERTE(FAILED(_hr)); \ } \ EX_END_CATCH(SwallowAllExceptions) +#else // FEATURE_COMINTEROP +#define EX_CATCH_HRESULT(_hr) \ + EX_CATCH \ + { \ + (_hr) = GET_EXCEPTION()->GetHR(); \ + _ASSERTE(FAILED(_hr)); \ + } \ + EX_END_CATCH(SwallowAllExceptions) +#endif // FEATURE_COMINTEROP #endif // !DACCESS_COMPILE diff --git a/src/coreclr/vm/excep.cpp b/src/coreclr/vm/excep.cpp index c29505dc1a1774..45bc9715d95e54 100644 --- a/src/coreclr/vm/excep.cpp +++ b/src/coreclr/vm/excep.cpp @@ -2989,7 +2989,6 @@ void FreeExceptionData(ExceptionData *pedata) if (pedata->bstrHelpFile) SysFreeString(pedata->bstrHelpFile); } -#endif // FEATURE_COMINTEROP void GetExceptionForHR(HRESULT hr, IErrorInfo* pErrInfo, OBJECTREF* pProtectedThrowable) { @@ -3005,7 +3004,6 @@ void GetExceptionForHR(HRESULT hr, IErrorInfo* pErrInfo, OBJECTREF* pProtectedTh // Initialize *pProtectedThrowable = NULL; -#if defined(FEATURE_COMINTEROP) if (pErrInfo != NULL) { // If this represents a managed object... @@ -3039,7 +3037,6 @@ void GetExceptionForHR(HRESULT hr, IErrorInfo* pErrInfo, OBJECTREF* pProtectedTh (*pProtectedThrowable) = ex.GetThrowable(); } } -#endif // defined(FEATURE_COMINTEROP) // If we made it here and we don't have an exception object, we didn't have a valid IErrorInfo // so we'll create an exception based solely on the hresult. @@ -3056,20 +3053,32 @@ void GetExceptionForHR(HRESULT hr, OBJECTREF* pProtectedThrowable) { THROWS; GC_TRIGGERS; // because of IErrorInfo - MODE_ANY; + MODE_COOPERATIVE; } CONTRACTL_END; // Get an IErrorInfo if one is available. IErrorInfo *pErrInfo = NULL; -#ifdef FEATURE_COMINTEROP if (SafeGetErrorInfo(&pErrInfo) != S_OK) pErrInfo = NULL; -#endif // FEATURE_COMINTEROP GetExceptionForHR(hr, pErrInfo, pProtectedThrowable); } +#else +void GetExceptionForHR(HRESULT hr, OBJECTREF* pProtectedThrowable) +{ + CONTRACTL + { + GC_TRIGGERS; + NOTHROW; + MODE_COOPERATIVE; + } + CONTRACTL_END; + EEMessageException ex(hr); + (*pProtectedThrowable) = ex.GetThrowable(); +} +#endif // FEATURE_COMINTEROP // // Maps a Win32 fault to a COM+ Exception enumeration code @@ -11202,6 +11211,7 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrowNonLocalized(RuntimeExceptionKind reKind, //========================================================================== // Throw a runtime exception based on an HResult //========================================================================== +#ifdef FEATURE_COMINTEROP VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, IErrorInfo* pErrInfo, Exception * pInnerException) { CONTRACTL @@ -11224,7 +11234,6 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, IErrorInfo* pErrInfo, Exce //_ASSERTE((hr != COR_E_EXECUTIONENGINE) || // !"ExecutionEngineException shouldn't be thrown. Use EEPolicy to failfast or a better exception. The caller of this function should modify their code."); -#ifdef FEATURE_COMINTEROP // check for complus created IErrorInfo pointers if (pErrInfo != NULL) { @@ -11238,9 +11247,7 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, IErrorInfo* pErrInfo, Exce GCPROTECT_END (); } } -#endif // FEATURE_COMINTEROP - _ASSERTE((pErrInfo == NULL) || !"pErrInfo should always be null when FEATURE_COMINTEROP is disabled."); if (pInnerException == NULL) { EX_THROW(EEMessageException, (hr)); @@ -11272,8 +11279,6 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr) RealCOMPlusThrowHR(hr, (IErrorInfo*)NULL); } - -#ifdef FEATURE_COMINTEROP VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, tagGetErrorInfo) { CONTRACTL @@ -11293,6 +11298,19 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, tagGetErrorInfo) // Throw the exception. RealCOMPlusThrowHR(hr, pErrInfo); } +#else // FEATURE_COMINTEROP +VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr) +{ + CONTRACTL + { + THROWS; + DISABLED(GC_NOTRIGGER); // Must sanitize first pass handling to enable this + MODE_ANY; + } + CONTRACTL_END; + + EX_THROW(EEMessageException, (hr)); +} #endif // FEATURE_COMINTEROP diff --git a/src/coreclr/vm/excep.h b/src/coreclr/vm/excep.h index 8e8ddacabe6b72..210677250b0700 100644 --- a/src/coreclr/vm/excep.h +++ b/src/coreclr/vm/excep.h @@ -286,7 +286,9 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrow(RuntimeExceptionKind reKind, UINT resID // passed as the first substitution string (%1). //========================================================================== +#ifdef FEATURE_COMINTEROP VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, IErrorInfo* pErrInfo, Exception * pInnerException = NULL); +#endif // FEATURE_COMINTEROP VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr); VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, UINT resID, LPCWSTR wszArg1 = NULL, LPCWSTR wszArg2 = NULL, LPCWSTR wszArg3 = NULL, LPCWSTR wszArg4 = NULL, LPCWSTR wszArg5 = NULL, @@ -359,7 +361,9 @@ void ExceptionPreserveStackTrace(OBJECTREF throwable); // Create an exception object for an HRESULT //========================================================================== +#ifdef FEATURE_COMINTEROP void GetExceptionForHR(HRESULT hr, IErrorInfo* pErrInfo, OBJECTREF* pProtectedThrowable); +#endif // FEATURE_COMINTEROP void GetExceptionForHR(HRESULT hr, OBJECTREF* pProtectedThrowable); HRESULT GetHRFromThrowable(OBJECTREF throwable); diff --git a/src/coreclr/vm/marshalnative.cpp b/src/coreclr/vm/marshalnative.cpp index a71ec7d00c49b0..8b20efe4a3f6e5 100644 --- a/src/coreclr/vm/marshalnative.cpp +++ b/src/coreclr/vm/marshalnative.cpp @@ -438,9 +438,9 @@ extern "C" void QCALLTYPE MarshalNative_GetExceptionForHR(INT32 errorCode, LPVOI BEGIN_QCALL; +#ifdef FEATURE_COMINTEROP // Retrieve the IErrorInfo to use. IErrorInfo* pErrorInfo = (IErrorInfo*)errorInfo; -#ifdef FEATURE_COMINTEROP if (pErrorInfo == (IErrorInfo*)(-1)) { pErrorInfo = NULL; @@ -456,7 +456,11 @@ extern "C" void QCALLTYPE MarshalNative_GetExceptionForHR(INT32 errorCode, LPVOI OBJECTREF exceptObj = NULL; GCPROTECT_BEGIN(exceptObj); +#ifdef FEATURE_COMINTEROP ::GetExceptionForHR(errorCode, pErrorInfo, &exceptObj); +#else + ::GetExceptionForHR(errorCode, &exceptObj); +#endif // FEATURE_COMINTEROP retVal.Set(exceptObj); GCPROTECT_END();