WinRT WRL WinRtClassicComMix和IAsyncOperation失败

时间:2013-12-19 16:21:25

标签: c++ visual-c++ winrt-async ppl wrl

我有一个C ++ WinRT组件,它是一个WinRtClassicComMix。我想定义一个方法,通过IAsyncOperation将自定义类返回给调用C#或WinJS代码。 当使用没有返回值的IAsyncAction时,一切正常,但是使用带有自动返回值的PPL的create_async会使VS 2012和VS 2013编译器崩溃。

相关细节:

接口和类在IDL中定义:

namespace MyControl
{
    runtimeclass MyComponentColorTable;
    [version(MyS_VERSION)]
    [uuid(7BB5A348-C82C-4EC4-946F-5113843A6A83)]
    [exclusiveto(MyComponentColorTable)]
    interface IMyComponentColorTable: IInspectable
    {
        [propget] HRESULT Count([out, retval] unsigned long  *value);
        HRESULT GetAt([in] unsigned long index, [out, retval] ComponentColor  *componentColor);
    }

    [version(MyS_VERSION)]
    [activatable(MyS_VERSION)]
    [marshaling_behavior(agile)]
    [threading(both)]
    runtimeclass MyComponentColorTable
    {
        [default] interface IMyComponentColorTable;
    }

    runtimeclass MyRendererScene;
    [version(MyS_VERSION)]
    [uuid(8D51F7F2-EDCF-4ED4-B556-03D3CC390A83)]
    [exclusiveto(MyRendererScene)]
    interface IMyRendererScene: IInspectable
    {
        HRESULT GetComponentColorTableAsync([in] GUID assetId, [out, retval] Windows.Foundation.IAsyncOperation<MyControl.MyComponentColorTable*>** operation);
    }
}

相应的头文件:

class CMyRendererScene :
    public Microsoft::WRL::RuntimeClass
    <
       RuntimeClassFlags<Microsoft::WRL::WinRtClassicComMix>,
       IMyRendererScene
    >
{
    InspectableClass(RuntimeClass_MyControl_MyRendererScene, BaseTrust);

public:
    CMyRendererScene(void);
    ~CMyRendererScene(void);

    IFACEMETHOD(GetComponentColorTableAsync)(GUID assetId, ABI::Windows::Foundation::IAsyncOperation<ABI::MyControl::MyComponentColorTable*>** operation);
};

CPP:

IFACEMETHODIMP CMyRendererScene::GetComponentColorTableAsync(GUID assetId, ABI::Windows::Foundation::IAsyncOperation<ABI::MyControl::MyComponentColorTable*>** operation)
{
    Concurrency::task_completion_event<ABI::MyControl::MyComponentColorTable*> tce;
    auto tsk = Concurrency::create_task(tce);
    auto asyncOp = Concurrency::create_async( [tsk]() -> Concurrency::task<ABI::MyControl::MyComponentColorTable*> 
    {
        return tsk;
    });

    // ... Wrapping of the event-based model using task_completion_event happens here ...

    return S_OK;
}

编译失败,导致VS C ++编译器崩溃:

  

错误1错误C1001:发生内部错误   编译器。 c:\ program files(x86)\ microsoft visual studio   11.0 \ vc \ include \ ppltasks.h 5513 1 MyControl

原因是create_async分配给asyncOp自动变量的行。我没有明确定义该变量,因为我无法找出正确的类型。 :(它可能需要是一个帽子类型,但ABI :: MyControl :: MyComponentColorTable *不能声明为^因为它没有定义为WinRT类,所以我假设create_async不能在这里使用,但如何我可以创建并返回我的类型的WinRT IAsyncOperation吗?MyComponentColorTable需要什么才能通过WinRT传回?并且IAvatarComponentColorTable不能用作返回类型,因为它是[exclusiveto(AvatarComponentColorTable)]。:(

0 个答案:

没有答案