4

I am developing some COM interfaces with IDL files. Some interface methods return HRESULT, but I have checked the MIDL language reference on MSDN, there's not a clue of HRESULT. So where could I find the official definition of this data type?

Update

Thanks to Shog9, I found it in wtypes.idl. I paste it here for other's view:

    ...
    cpp_quote("#ifndef _HRESULT_DEFINED")
    cpp_quote("#define _HRESULT_DEFINED")
    #if defined(_STRICT_HRESULT)
    typedef struct _HRESULT_STRUCT {
            DWORD Data1;
    } HRESULT_STRUCT, *PHRESULT_STRUCT;
    typedef PHRESULT_STRUCT HRESULT;
    #else // defined(_STRICT_HRESULT)
    cpp_quote("#ifdef __midl")
    typedef LONG HRESULT;
    ...

However, when I use the DWORD or LONG explicitly in my IDL files, the MIDL compiler will report an error saying:

"error MIDL2269: procedures in an object interface must return an HRESULT" 

Kind of ridiculous...

smwikipedia
  • 61,609
  • 92
  • 309
  • 482

2 Answers2

4

Any practical .idl file should start with

import "oaidl.idl";
import "ocidl.idl";

Which declares essential types. Like HRESULT and VARIANT. Etcetera.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
4

It's actually just an alias for DWORD (which is an alias for unsigned long). It's #defined for MIDL in wtypes.idl, which as Hans notes is brought in by the standard import mechanism.

The purpose of HRESULT is to represent return codes in a consistently recognizable manner - success and failure can be identified regardless of the source or other information encoded in the value, and certain system-defined values are given special meaning when coupled with standard interfaces. See MSDN for details.

Community
  • 1
  • 1
Shog9
  • 156,901
  • 35
  • 231
  • 235