I'm using this function to call a VB 6 ActiveX component from my VC6 ATL component.
When the VB 6 component throws an exception (raises an error), this is caught in CallByNameEx by the catch(...) exception handler. But when I call GetErrorInfo to get the IErrorInfo pointer, it is returning as NULL. Can anyone help?
Code:_variant_t CallByNameEx(_bstr_t bstrProgId, _bstr_t bstrProcName, _variant_t* ptrvarParameters, int nParameters) { _variant_t varResponse; HRESULT hr = S_OK; CLSID clsid; if (SUCCEEDED(hr = CLSIDFromProgID(bstrProgId, &clsid))) { try { IUnknownPtr ptrUnknown(clsid); } catch(_com_error& e) { // Report error } IDispatchPtr ptrDispatch = NULL; if (m_spObjectContext != NULL) { hr = m_spObjectContext->CreateInstance(clsid, __uuidof(IDispatch), reinterpret_cast<void**>(&ptrDispatch)); } else { hr = ::CoCreateInstance(clsid, NULL, CLSCTX_ALL, __uuidof(IDispatch), reinterpret_cast<void**>(&ptrDispatch)); } if (SUCCEEDED(hr) && ptrDispatch != NULL) { DISPID dispid; wchar_t* pszProcName = static_cast<wchar_t*>(bstrProcName); if (SUCCEEDED(hr = ptrDispatch->GetIDsOfNames(IID_NULL, &pszProcName, 1, LOCALE_USER_DEFAULT, &dispid))) { DISPPARAMS dispparams = { ptrvarParameters, NULL, nParameters, 0 }; EXCEPINFO ExcepInfo; unsigned int uArgErr = 0; IErrorInfoPtr ptrErrorInfo = NULL; try { if (SUCCEEDED(hr = ptrDispatch->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparams, &varResponse, &ExcepInfo, &uArgErr))) { // Success } else { // Report error } } catch(...) { // FIXME why is ptrErrorInfo == NULL? if (SUCCEEDED(::GetErrorInfo(0, &ptrErrorInfo)) && ptrErrorInfo != NULL) { // Report error } else { // Report error } } } } } return varResponse; }




Reply With Quote