我正在使用我不熟悉的C++/WRL编写 Windows 10 Store / WinRT 代码。我很想知道如何取消长期挂起的异步操作?
说明它的最好方法是用这个例子:
#include <Windows.Services.Store.h>
#include <wrl.h>
auto onAppLicCompletedCallback = Callback<Implements<RuntimeClassFlags<ClassicCom>, IAsyncOperationCompletedHandler<StoreAppLicense*>, FtmBase>>(
[](IAsyncOperation<StoreAppLicense*>* operation, AsyncStatus status)
{
//Asynchronous operation is done
return S_OK;
});
//'opAppLic' is defined as:
// ComPtr<IAsyncOperation<StoreAppLicense*>> opAppLic;
// ...
//Begin asynchronous operation
HRESULT hr = opAppLic->put_Completed(onAppLicCompletedCallback.Get());
if (SUCCEEDED(hr))
{
//Keep going ...
//Say, at some point here I need to cancel 'onAppLicCompletedCallback'
//but how do I do it?
}
编辑:当我尝试opAppLic->Cancel()
按照以下答案中的建议添加时,它给了我以下编译器错误:
1>file-name.cpp(597): error C2039: 'Cancel' : is not a member of 'Microsoft::WRL::Details::RemoveIUnknownBase<T>'
1> with
1> [
1> T=ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::Services::Store::StoreAppLicense*>
1> ]
我需要QueryInterface
那个IAsyncInfo
,还是什么?
EDIT2:这就是我得到的opAppLic
变量类型:
不,它没有Cancel
方法: