Accessing COM error info from c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SimonHeffer
    New Member
    • Sep 2007
    • 12

    Accessing COM error info from c#

    I have a COM server written in MSVC 6 C++. If I use a C++ client and get an error my server will give back error information using IErrorInfo. So if the client calls a method that throws a com_error exception the following will find out what's gone wrong...

    Code:
    ReportErrorInfo(IUnknown * punk){
    	USES_CONVERSION;
    	CComBSTR bstrError;
    	CComPtr<ISupportErrorInfo> pSEI;
    	if (!punk)
    	{
    		strcpy(ErrorMessage,"No interface to COM server");
    	}
    	else try
    	{
    		HRESULT hr = punk->QueryInterface(IID_ISupportErrorInfo,(void **) &pSEI);
    		if(SUCCEEDED(hr))
    		{
    			CComPtr<IErrorInfo> pEO;
    			if(S_OK == ::GetErrorInfo(NULL, &pEO))
    			{
    				CComBSTR bstrDesc;
    				pEO->GetDescription(&bstrDesc);
    				strcpy(ErrorMessage,OLE2T(bstrDesc));
                                   // something useful in ErrorMessage by now
    ...
    But when calling the same method on the server (and expecting the same error) from a C# client using catch (COMException e) then e.Message is
    "Error HRESULT E_FAIL has been returned from a call to a COM component."

    rather than what GetDescription( ) returns.

    Any idea where to start looking?
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Well you could try looking to see if there is an inner exception
    OR tell it to catch (Exception e) instead of a specific type.
    Since I think if <some exceptiontype A> inherits from comException, then catching comException will catch that <some exceptiontype A> and cast it as a comException, losing info?
    The same might also apply if the inner exception is comException and there's an out exception?
    Not sure if that will help at all or not

    Comment

    • SimonHeffer
      New Member
      • Sep 2007
      • 12

      #3
      Thanks for that.

      However I've tried both with no luck.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        You could try writing an unmanged wrapper for it that would take the correct com_error thing and fire off a managed-style error message?

        Not that I know how to do that, just throwing it out there.

        Comment

        Working...