2

我正在尝试在 win32 应用程序中实现 IVector。编译器总是给我这个我无法摆脱的 MIDL 断言错误。这是示例类 -

#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;
}

编译它会产生错误-

错误 C2338 此接口实例尚未由 MIDL 专门化。这可能是由于忘记了接口类型上的“*”指针、在 idl 文件中省略了必要的“declare”子句、忘记包含必要的 MIDL 生成的标头之一。IVector c:\program files (x86)\windows kits\10\include\10.0.17763.0\winrt\windows.foundation.collections.h 201

似乎 collections.h 有not_yet_specialized_placeholder总是将值设置为“假”。如果我在文件中定义下面的代码片段,那么错误就会消失,但是对于 IVector 没有 uuid,我会得到不同的错误。这使我相信这是不正确的解决方案。

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

至于我错过了什么,这让我发疯。

4

1 回答 1

1

ImplementIvector<T>ImplementsIVector<T*>表示ImplementIvector<int>implements IVector<int*>,它不是有效的 WinRT 类型。你需要改变你ImplementIvector的实现IVector<T>

于 2019-12-16T18:35:26.190 回答