Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could HRESULT appear in an MIDL file?

Tags:

c++

c#

interop

com

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...

like image 467
smwikipedia Avatar asked Feb 26 '23 12:02

smwikipedia


1 Answers

Any practical .idl file should start with

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

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

like image 117
Hans Passant Avatar answered Mar 07 '23 09:03

Hans Passant