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.

Comments (5)
  1. Medinoc says:

    Wow, WSA_E_NO_MORE looks like a huge mess:

    http://msdn.microsoft.com/en-us/library/ms740668%28VS.85%29.aspx

    WSAENOMORE: 10102

    WSA_E_NO_MORE: 10110

  2. John says:

    And then you have situations where people hijack the "unused" bits:

    http://blogs.msdn.com/stephen_griffin/archive/2007/02/15/random-hresult-from-outlook-object-model.aspx

    Oops.

  3. Worf says:

    @Medinoc: Ditto on WSA_E_CANCELLED.

    More fun happens when you write a namespace provider, because you have to return a code…

    WSALookupServiceNext… lots of fun.

    Add in all the little differences between BSD sockets and WinSock… (A nonblocking TCP socket returns EINPROGRESS in BSD, while Winsock wants EWOULDBLOCK when you do a connect())

  4. configurator says:

    What do the E and S stand for? That is, what are the valid values for severity?

  5. Medinoc says:

    WinError.h lists two severities: Error and Success.

    But sometimes, I wonder if it means really success, or if some took it for "status"…

    //

    // Severity values

    //

    #define SEVERITY_SUCCESS    0

    #define SEVERITY_ERROR      1

Comments are closed.