For .Net to retrieve specific COM exception, COM must implement the ISupportErrorInfo interface

by lichen 9/28/2006 12:01:00 PM

Many COM objects simply use setErrorInfo and expect to call getErrorInfo to retrieve the detail error message. However, .Net would not call getErrorInfo unless the COM object implements the ISupportErrorInfo interface. There are the steps:

1. In the .h file, make the COM object implements the ISupportErrorInfo interface, e.g.:

class ATL_NO_VTABLE CMyObject : ..., public ISupportErrorInfo, ...

2. In COM MAP, add:

BEGIN_COM_MAP(CMyObject)

...

COM_INTERFACE_ENTRY(ISupportErrorInfo)

...

END_COM_MAP()

3. Add the method declaration:

// ISupportsErrorInfo

STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);

4. Implement the method in the .cpp file:

/////////////////////////////////////////////////////////////////////////////

// ISupportsErrorInfo

/////////////////////////////////////////////////////////////////////////////

//

STDMETHODIMP CMyObject::InterfaceSupportsErrorInfo(REFIID riid)

{

static const IID* arr[] =

{

&IID_IMyObject,

&IID_IMyObject2,

&IID_IMyObject3,

};

for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)

{

if (InlineIsEqualGUID(*arr[i],riid))

return S_OK;

}

return S_FALSE;

}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.Net

Related posts

Comments are closed

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Pages

    Recent comments

    Authors

    Tags

      Disclaimer

      The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

      © Copyright 2012

      Sign in