C# and COM interoperability


I'm doing this service for my job and I need to code a module that forwards call from a C++ program to a DLL. Normaly, the C++ program instanciate the DLL with his GUID and then calls some functions. I changed the GUID of the DLL and took the original GUID and applied it to my service so now when the C++ program needs a instance of the DLL, it calls me. I then instanciate the good DLL and forward the calls. This works fine until I need the return value of the forwarded call to the DLL. The .NET documentation states that when a call to a COM object fails (HRESULT != S_OK or S_FAIL) the CLR converts this failure by returning an Exception to the callee (my service). The problem is that i know the return value is different from S_OK and S_FAIL but i don't catch the exception ! (with try/catch block)

This problem comes from the fact that the interface I used to communicate with the DLL returns a HRESULT result but has no [out,retval] param so when i use midl to create the tlb and tlbimp to then create the DLL, the resulting interface i can use in my C# project has a VOID signature. And I must read the HRESULT return value for other processing.

How can I get the HRESULT value from my C# code ?
Who is Participating?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.