我正在使用 C++ 和 COM 访问 WinRT API。
下面的代码给了我results == unspecified
ComPtr<IGeolocatorStatics> statics;
RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Geolocation_Geolocator).Get(), IID_PPV_ARGS(&statics));
ComPtr<IAsyncOperation<GeolocationAccessStatus>> op;
statics->RequestAccessAsync(&op);
GeolocationAccessStatus results;
op->GetResults(&results);
而我results == allowed
是从添加Sleep
电话中获得的。
ComPtr<IGeolocatorStatics> statics;
RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Geolocation_Geolocator).Get(), IID_PPV_ARGS(&statics));
ComPtr<IAsyncOperation<GeolocationAccessStatus>> op;
statics->RequestAccessAsync(&op);
Sleep(100);
GeolocationAccessStatus results;
op->GetResults(&results);
显然,我需要等待 AsyncOperation 以在完成时接收回调。我宁愿做前者。如何使用 COM 等待来自 C++ 的 WinRT IAsyncOperation?