I'm trying to implement IVector in a win32 app. Compiler always gives me this MIDL assert error which I can not get rid of. Here is sample class -

#include <iostream>
#include <windows.foundation.h>
#include <wrl/client.h>
#include <wrl/event.h>
#include <wrl/implements.h>

using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
using namespace ABI::Windows::Foundation::Collections;
using namespace std;

template <typename T>
class ImplementIvector
    : public Microsoft::WRL::RuntimeClass<
          Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::WinRtClassicComMix>,
          IInspectable, IVector<T *>, IIterable<T *>> {

public:
  // IVector<T>
  IFACEMETHOD(GetAt)(unsigned int index, _Outptr_ T **item) { return S_OK; }
  IFACEMETHOD(get_Size)(_Out_ unsigned int *size) { return S_OK; }
  IFACEMETHOD(GetView)(IVectorView<T *> **view) { return S_OK; }
  IFACEMETHOD(IndexOf)
  (_In_ T *item, _Out_ unsigned int *index, _Out_ boolean *found) {
    return S_OK;
  }
  IFACEMETHOD(SetAt)(unsigned int index, _In_ T *item) { return S_OK; }
  IFACEMETHOD(InsertAt)(unsigned int index, _In_ T *item) { return S_OK; }
  IFACEMETHOD(RemoveAt)(unsigned int index) { return S_OK; }
  IFACEMETHOD(Append)(_In_ T *item) { return S_OK; }
  IFACEMETHOD(RemoveAtEnd)() { return S_OK; }
  IFACEMETHOD(Clear)() { return S_OK; }

  // IIterable<T>
  IFACEMETHOD(First)(IIterator<T *> **first) { return S_OK; }
};

typedef ImplementIvector<int> CollectionImplementation;

int main() {
  Make<CollectionImplementation>();
  system("pause");
  return 0;
}

Compiling this generates the error-

Error C2338 This interface instance has not been specialized by MIDL. This may be caused by forgetting a '*' pointer on an interface type, by omitting a necessary 'declare' clause in your idl file, by forgetting to include one of the necessary MIDL generated headers. IVector c:\program files (x86)\windows kits\10\include\10.0.17763.0\winrt\windows.foundation.collections.h 201

Seems like collections.h has not_yet_specialized_placeholder which is setting value to 'false' always. If I define below snippet in the file then error goes away but I get different error for no uuid for IVector. Which leads me to believe this in not right solution.

struct {
        not_yet_specialized_placeholder<IIterable<int *>> {
      enum { value = true };
    };

This is driving me crazy as for what am I missing.

1

There are 1 best solutions below

0
On

ImplementIvector<T> Implements IVector<T*>, which means ImplementIvector<int> implements IVector<int*>, which is not a valid WinRT type. You need to change your ImplementIvector to implement IVector<T> instead.