Question

Currently i am writing a C# COM Server which will be used by a C++ client. I want to return a certain HRESULT to the C++ code when an specific exception is raised in the C# code like the following

// C# COM Server Code
public void MyMethod()
{
    try
    {
        //Some Processing 
    }
    catch(CertainException e)
    {
        //I pass in my Own HResult int to the my Custom Exception 
        MyCustomException ex = new MyCustomException(unchecked((int)0xc00491fe)); 
        throw ex;
    }
}

//C++ Code
HRESULT hr = pMyComInstance->MyMethod();

I expect that the "hr" i got from my C++ code is the int i assigned in my C# code, however instead of getting the HRRESULT, i still got the exception in C++ code.

Have i done anything wrong? please help.. Thanks

Was it helpful?

Solution

In order to return HRESULTS, you need to throw a COMException, not just any exception.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top