How to get the HRESULT of an ApplicationException thrown from a managed library which is called in native c++ using reflection?

0

Using the code sample here: Calling A .NET Managed Method from Native Code

With only the following change:

Throw ApplicationException derived exception in Test method

public class TestException : ApplicationException
{
    public TestException(string message)
        : base(message)
    {
        this.HResult = unchecked((int)0x80040201);
    }
}

public class Class1
{
    public void Test()
    {
        throw new TestException("test");
    }
}

Rebuilding and running the application shows that the call to InvokeMember_3 throws a _com_error with an HRESULT error code of 0x80131604 COR_E_TARGETINVOCATION (TargetInvocationException).

How can I get the real HRESULT 0x80040201?

Thank you.

Edit
I've updated my question a little and posted the complete sample solution here: kb953836.zip

c#
visual-c++
reflection
interop
asked on Stack Overflow Mar 11, 2012 by Rami A. • edited Sep 30, 2020 by Remko

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0