Two thoughts:
- Find and kill (or severely cripple) whoever implements this library
- Implementing a wrapper in managed C ++ since you will need to call the HResult method directly, and I cannot figure out how to do this using interop.
EDIT
Another option is to declare COM interfaces in C #, so the signature of each method returns HRESULT and uses [out retval] for the returned values. This will allow you to retrieve and examine HRESULT of all method calls, not just those that throw a COMException.
By default, COM interop typeimport "captures" the method signatures so that the HRESULT return is deleted on the managed side, and the interop layer throws exceptions for E_FAIL, etc., essentially throwing S_OK, S_FALSE, etc.
There are some explanations in this article , and the PreserveSig attriubte documentation has some additional details.
This will most likely require you to declare all COM interfaces manually instead of using tlbimp , but you can get tlbimp to save the signature of the COM methods.
This will allow you to stay purely in C #, but in your shoes I would go with managed C ++, since it is easier to interact with COM in this non-standard mode.
source share