Teach Yourself Database Programming
with Visual C++ 6 in 21 days


Appendix D

Interpreting HRESULTS


When you use the #import directive with ADO, as in this book, ADO will usually throw an exception rather than return an HRESULT for runtime errors. Because exceptions provide detailed information on the error and its cause(s), it is generally easy to figure out what went wrong.

HRESULTs, on the other hand, are just numbers. HRESULTs by themselves provide very little information to enable you to figure out what went wrong. For those times when you are forced to decipher an HRESULT, it is sometimes very helpful to know the meaning of HRESULT return codes.

There are several resources to which you can turn to discover the meaning of HRESULT return codes. The Microsoft Knowledge Base has several articles that deal with HRESULTs. The best way to find these articles is to search the Knowledge Base for HRESULT ADO. You can also search for adovc to find ADO C++ articles, some of which deal with decoding HRESULTs.

One Knowledge Base article, "Q168354," contains a list of the frequently encountered HRESULTs and their meanings. Specifically, the article explains the HRESULTs that you could receive from the underlying OLE DB providers when using ADO.

Other Knowledge Base articles show sample code for decoding, or cracking, HRESULTs. The Knowledge Base article "Q169498" illustrates a method you can use to interpret an HRESULT with a function and display the text description.

Two code samples from Microsoft contain code that shows how to crack HRESULTs. These are the ADOVC sample and the DECODE sample. You can obtain these from the Microsoft Software Library or from MSDN.


© Copyright, Sams Publishing. All rights reserved.