如何从IVector接口实现GetMany方法

时间:2015-01-22 11:43:49

标签: windows-store-apps c++-cx

我已尝试创建ICollectionView的自定义实现,但我的应用尚未通过认证。原因是WACK工具声明GetMany方法的签名与windows.winmd中的GetMany签名不匹配

以下是windows.winmd关于GetMany的说法:

unsigned int GetMany(unsigned int startIndex, [Windows::Foundation::Metadata::LengthIsAttribute] Platform::Array<T>^ items)

但是,根据编译器的提示,我已经用这种方式定义了GetMany方法:

virtual unsigned int GetMany(unsigned int index, Platform::WriteOnlyArray<Platform::Object^>^ items);

它编译并且工作正常,但WACK抱怨它。我还发现Array作为out参数可以通过这种方式实现:

virtual unsigned int GetMany(unsigned int index, Platform::Array<Platform::Object^>^* items);

然而,在那种情况下,编译器说我的类是抽象的,它错过了GetMany方法的实现。我甚至试过实现这两种方法,但这会破坏编译器。

我可以采用变通方法并以不同的方式实现功能(没有ICollectionView)但是,从设计的角度来看,这个解决方案最适合我。

1 个答案:

答案 0 :(得分:0)

在您的安装中查看collection.h(定义Platform :: VectorView&#39;的实现)可能是有益的。它将GetMany函数定义为:

virtual unsigned int GetMany(unsigned int startIndex, WriteOnlyArray<T>^ dest)

所以你想要使用WriteOnlyArray是正确的。您的收藏集是否在Object^类型上模板化了?

关于不同WinRT阵列模式及其用途的隐藏但信息丰富的MSDN主题:https://msdn.microsoft.com/en-us/library/windows/apps/hh700131.aspx