@@ -124,30 +124,6 @@ extern "C" void QCALLTYPE ExceptionNative_GetFrozenStackTrace(QCall::ObjectHandl
124124
125125#ifdef FEATURE_COMINTEROP
126126
127- static BSTR BStrFromString (STRINGREF s)
128- {
129- CONTRACTL
130- {
131- THROWS ;
132- }
133- CONTRACTL_END ;
134-
135- WCHAR *wz;
136- int cch;
137- BSTR bstr;
138-
139- if (s == NULL )
140- return NULL ;
141-
142- s->RefInterpretGetStringValuesDangerousForGC (&wz, &cch);
143-
144- bstr = SysAllocString (wz);
145- if (bstr == NULL )
146- COMPlusThrowOM ();
147-
148- return bstr;
149- }
150-
151127static BSTR GetExceptionDescription (OBJECTREF objException)
152128{
153129 CONTRACTL
@@ -161,31 +137,12 @@ static BSTR GetExceptionDescription(OBJECTREF objException)
161137
162138 BSTR bstrDescription;
163139
164- STRINGREF MessageString = NULL ;
165- GCPROTECT_BEGIN (MessageString)
166140 GCPROTECT_BEGIN (objException)
167141 {
168- // read Exception.Message property
169- MethodDescCallSite getMessage (METHOD__EXCEPTION__GET_MESSAGE , &objException);
170-
171- ARG_SLOT GetMessageArgs[] = { ObjToArgSlot (objException)};
172- MessageString = getMessage.Call_RetSTRINGREF (GetMessageArgs);
173-
174- // if the message string is empty then use the exception classname.
175- if (MessageString == NULL || MessageString->GetStringLength () == 0 ) {
176- // call GetClassName
177- MethodDescCallSite getClassName (METHOD__EXCEPTION__GET_CLASS_NAME , &objException);
178- ARG_SLOT GetClassNameArgs[] = { ObjToArgSlot (objException)};
179- MessageString = getClassName.Call_RetSTRINGREF (GetClassNameArgs);
180- _ASSERTE (MessageString != NULL && MessageString->GetStringLength () != 0 );
181- }
182-
183- // Allocate the description BSTR.
184- int DescriptionLen = MessageString->GetStringLength ();
185- bstrDescription = SysAllocStringLen (MessageString->GetBuffer (), DescriptionLen);
142+ UnmanagedCallersOnlyCaller getDescriptionBstr (METHOD__EXCEPTION__GET_DESCRIPTION_BSTR );
143+ bstrDescription = getDescriptionBstr.InvokeThrowing_Ret <BSTR >(&objException);
186144 }
187145 GCPROTECT_END ();
188- GCPROTECT_END ();
189146
190147 return bstrDescription;
191148}
@@ -200,19 +157,17 @@ static BSTR GetExceptionSource(OBJECTREF objException)
200157 PRECONDITION ( IsException (objException->GetMethodTable ()) );
201158 }
202159 CONTRACTL_END ;
160+
161+ BSTR bstrSource;
203162
204- STRINGREF refRetVal;
205163 GCPROTECT_BEGIN (objException)
206-
207- // read Exception.Source property
208- MethodDescCallSite getSource (METHOD__EXCEPTION__GET_SOURCE , &objException);
209-
210- ARG_SLOT GetSourceArgs[] = { ObjToArgSlot (objException)};
211-
212- refRetVal = getSource.Call_RetSTRINGREF (GetSourceArgs);
213-
164+ {
165+ UnmanagedCallersOnlyCaller getSourceBstr (METHOD__EXCEPTION__GET_SOURCE_BSTR );
166+ bstrSource = getSourceBstr.InvokeThrowing_Ret <BSTR >(&objException);
167+ }
214168 GCPROTECT_END ();
215- return BStrFromString (refRetVal);
169+
170+ return bstrSource;
216171}
217172
218173static void GetExceptionHelp (OBJECTREF objException, BSTR *pbstrHelpFile, DWORD *pdwHelpContext)
@@ -229,20 +184,11 @@ static void GetExceptionHelp(OBJECTREF objException, BSTR *pbstrHelpFile, DWORD
229184 }
230185 CONTRACTL_END ;
231186
232- *pdwHelpContext = 0 ;
233-
234- GCPROTECT_BEGIN (objException);
235-
236- // call managed code to parse help context
237- MethodDescCallSite getHelpContext (METHOD__EXCEPTION__GET_HELP_CONTEXT , &objException);
238-
239- ARG_SLOT GetHelpContextArgs[] =
187+ GCPROTECT_BEGIN (objException)
240188 {
241- ObjToArgSlot (objException),
242- PtrToArgSlot (pdwHelpContext)
243- };
244- *pbstrHelpFile = BStrFromString (getHelpContext.Call_RetSTRINGREF (GetHelpContextArgs));
245-
189+ UnmanagedCallersOnlyCaller getHelpContextBstr (METHOD__EXCEPTION__GET_HELP_CONTEXT_BSTR );
190+ getHelpContextBstr.InvokeThrowing (&objException, pbstrHelpFile, pdwHelpContext);
191+ }
246192 GCPROTECT_END ();
247193}
248194
0 commit comments