Solved

_com_error

Posted on 2000-03-27
2
1,482 Views
Last Modified: 2013-11-25
Hi All,
 I try to use try...catch construction in ATL COM object.
I'd like to use rich error, so I call Error("description",GUID_NULL,hr) in try block.
On catch, I get empty description.

try
{
 ...
 hr = pTest.CoCreateInstance(...
 if (FAILED(hr))
  _com_issue_errorex(Error("test.cpp (23)",GUID_NULL,hr));
 ...
 
}
catch(_com_error& e)
{
 CString s = (BSTR)e.Description();
}

1) I test e.Description(), but for this example is empty. Why?
When I call on try block wrapper method(another COM object - which sets description),
then description isn't empty.

Thanks
0
Comment
Question by:mizera
2 Comments
 

Accepted Solution

by:
sgold earned 100 total points
ID: 2660627
there isnt description all the time
tray e.ErrorMessage (); to get
the error
sgold
0
 

Author Comment

by:mizera
ID: 2662955
ErrorMessage() return description error code, but only for system code. I try to use own hresult and add file_line stamp.

I'd like to wrap catch block to macro. I found some way, but I dont't explain it.

Why (_com_error& e) haven't description, but IErrorInfo has?

#define __CATCH_COM_ERROR_EX(iid)
 }
 catch(_com_error& e)
 {
  CString _description = (BSTR)e.Description();
  if (_description.IsEmpty())
  {
   CComPtr<ISupportErrorInfo> pSEI;
   if (SUCCEEDED(QueryInterface(IID_ISupportErrorInfo,(void**)&pSEI)))
   {
    if (pSEI->InterfaceSupportsErrorInfo(IID_##iid) == S_OK)
    {
     CComPtr<IErrorInfo> pEI;
     if (GetErrorInfo(NULL,&pEI) == S_OK)
     {
      CComBSTR _bstr;
      pEI->GetDescription(&_bstr);
      _description = (BSTR)_bstr;
     }
    }
   }
  }

 ....
 e.g. return Error(_description,GUID_NULL,e.Error());
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
haveThree challenge 22 101
dialer.exe 4 52
sumHeights2  challenge 7 78
What .NET website keeps me current? 9 32
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now