August 28th, 2009

The great thing about naming conventions is that not everybody will follow them

The naming convention for HRESULT is «facility»_«severity»_«name», where the facility portion (and the underscore) is omitted if the facility is FACILITY_NULL or FACILITY_WIN32. Good luck finding anybody who follows this naming convention. Okay, fine, if you look closely you might be able to find some people who do.

COM   CO_ E_ NOTINITIALIZED
CO_ S_ MACHINENAMENOTFOUND
Structured storage   STG_ E_ SHAREVIOLATION
STG_ S_ CONVERTED
SETUPAPI   SPAPI_ E_ EXPECTED_SECTION_NAME
Data and view   DV_ E_ TYMED
DV_ E_ FORMATETC
Class factory   CLASS_ E_ NOAGGREGATION
Class registry   REGDB_ E_ CLASSNOTREG
OLEDB   DB_ E_ DELETEDROW

Actually, I guess I was a bit too pessimistic when I said nobody follows it. It seems that the majority of Windows components do follow this convention, although there are some notable exceptions.

DirectDraw   DDERR_UNSUPPORTEDFORMAT
ADSI   E_ADS_INVALID_DOMAIN_OBJECT

There are also some people who decided to confuse matters further by using the HRESULT convention for error codes returned by GetLastError()!

RPC   RPC_S_OBJECT_NOT_FOUND
SmartCard   SEC_E_SMARTCARD_CERT_REVOKED
Task scheduler   SCHED_E_SERVICE_NOT_LOCALSYSTEM
Winsock   WSA_E_NO_MORE

I apologize for the confusion this has caused.

Pre-emptive clarifying remark: The examples given in this article are merely illustrative and are not intended to be comprehensive.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.