2

In my C++/WinRT project I use below MIDL code to declare an asynchronous method returning a Windows::Foundation::IInspectable object.

namespace myproject
{
    [default_interface]
    runtimeclass FileRetriever 
    {
        FileRetriever();

        Windows.Foundation.IAsyncOperation<Windows.Foundation.IInspectable> RetrieveFileNamesAsync();
    }
}

The code gives the following error when compiling:

Error MIDL2011 [msg]unresolved type declaration [context]: Windows.Foundation.IInspectable [ parameterized interface parameter 'Windows.Foundation.IInspectable' of Procedure 'RetrieveFileNamesAsync' ( RuntimeClass 'myproject.FileRetriever' ) ]

MSDN states the error can be resolved by "add[ing] an import directive for the IDL file(s) that contain the definitions of any type(s) that you reference that you've defined in your project" but IInspectable is obviously not a type I defined myself.


How can I resolve the error?

Thomas Flinkow
  • 4,845
  • 5
  • 29
  • 65
  • 2
    You'll have to use `IInspectable*` or `Object` in place of `Windows.Foundation.IInspectable`. I'm not sure why, and the [documentation](https://learn.microsoft.com/en-us/uwp/midl-3/) wasn't entirely enlightening to me either. – IInspectable Dec 14 '21 at 23:12
  • @IInspectable username checks out :) Thanks, having to use Object certainly makes sense in a way… I understand IInspectable is a base class for almost all WinRT objects, comparable to Object in C#. – Thomas Flinkow Dec 14 '21 at 23:19
  • 2
    There are two flavors of Windows Runtime MIDL. Old style uses `IInspectable*`. The newer style is inspired by C# and uses `Object`. – Raymond Chen Dec 14 '21 at 23:30

0 Answers0