Getting error MIDL5004 when creating a simple interface that inherits from another (simple) one RRS feed

  • Question

  • Hi,

    In my experimentation with WinRT component and WRL I came across a strange error. Although I haven't developed COM components for quite sometime I remember that building a hierarchy of interfaces was one of the building blocks of COM.

    As WRL for WinRT whar ATL was COM I would have been expected similar possibilities.

    While trying to make a very simple hierarchy of 2 interfaces, one base and on inheriting from the base one, I came across this  MIDL compilation error that puzzled me.

    error MIDL5004: interfaces must inherit from IInspectable : ICitizen

    Shall I understand that with WRL an interface can only inherit from IInspectable ??? Or did I miss something somewhere? 

    I searched on google for this error MIDL5004 and I didn't even get a result! This doesn't sound good to me...

    Here is the IDL code of those 2 interfaces.

    interface IPerson : IInspectable
        [propget] HRESULT Name([out, retval] HSTRING* value);
        [propput] HRESULT Name([in] HSTRING value);
        [propget] HRESULT Surname([out, retval] HSTRING* value);
        [propput] HRESULT Surname([in] HSTRING value);
    interface ICitizen : IPerson 
        [propget] HRESULT Address([out, retval] IAddress** value);
        [propput] HRESULT Address([in] IAddress* value);

    Can someone out there tell me what's wrong this simple construction? (IAddress is another interface, this one has no issue)

    In order to compile my test I had to create a Citizen runtime class that implements both ICitizen and IPerson. It works of course but in term of component design it is a very poor way of doing!

    What I don't really understand is that if I create some interfaces with C++/CX I can inherit ICitizen from IPerson and create a WinRT component that works.

    I also tried the following approach:

    interface ICitizen : IPerson, IInspectable 
        [propget] HRESULT Address([out, retval] IAddress** value);
        [propput] HRESULT Address([in] IAddress* value);

    but this construction doesn't work neither. Again I thought that with COM MIDL it was possible to create interfaces that inherit from multiple base interface.

    Your inputs are highly appreciated! I really hope that MIDL for WinRT doesn't limit the interface design to a single level, that would be totally unusable for serious application design.

    Thanks for your help
    O. Rouit

    PS: I posted a similar question on stackoverflow but there is no reply yet.


    Software Architect, Advanced IT Tokens Team - Gemalto

    Thursday, December 27, 2012 2:08 PM

All replies

  • Hello,


    Thanks for your feedback, I will involve more experts to investigate it.


    Best regards,


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 2, 2013 5:54 AM
  • Unfortunately, WinRT interfaces must all directly inherit from IInspectable only.  You cannot define an interface to specialize any other interface.  Period.

    You can declare your WinRT runtimeclass to implement any number of IInspectable-derived interfaces.  As long as your object reference is typed to the runtimeclass, you get all of the interfaces (at least in languages like C# and C++/CX that are aware of the ABI contract).

    If you're using pure C++ with WRL, you'll have to QueryInterface on each individual interface.

    Basically, when you're using MIDL in a WinRT project, it's not COM MIDL, it's a special WinRT flavor of MIDL that has many more restrictions.

    Of course, WinRT MIDL (MIDLRT) is not documented anywhere.

    Tuesday, February 12, 2013 1:12 AM