tags:

views:

88

answers:

1

I'm making a COM interface that c# will be using, however i am wondering how i am to check for errors for exception handling on the c# end. As at the moment i am just returning a HRESTULT or bool for most methods and then doing a Marshal.ThrowExceptionForHR but several things can go wrong in some of these methods and returning a E_FAIL just doesn't cut it.

What can i do in order to return more information? Can i make a HRESULT of my own?

A: 

I've never actually done this, but in theory you should be able to do it by supporting IErrorInfo. Marshal.GetExceptionForHR() has an overload that takes an IErrorInfo pointer.

By the way, you should not have to manually call Marshal.ThrowExceptionForHR() - if your method returns HRESULT and and [out] parameter for the return value you can declare it in .NET as returning the return value and set PreserveSig=false and the CLR will automatically throw an exception if the HRESULT indicates a failure.

Evgeny
Cool I shall look into that!
Daniel