Using COM-Rich Error Information in Managed Code

COM objects use HRESULTs and error objects to return error information to their clients. .NET objects always use exceptions to return error information to their client. The mapping between these two is fairly straightforward. Before I go into that mapping, let's review COM HRESULTs and error objects because it is possible—particularly if you are a VB programmer—to use HRESULTs and error objects without understanding what they are and how they work.

The usual way to return an error in COM is to return a 32-bit error number that is typed as an HRESULT. In fact, all methods defined in a COM interface should return an HRESULT even if they succeed. HRESULTS are partitioned into four bit fields as shown ...

Get .NET and COM Interoperability Handbook, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.