本文整理汇总了C++中ComObjPtr::startTaskAsync方法的典型用法代码示例。如果您正苦于以下问题:C++ ComObjPtr::startTaskAsync方法的具体用法?C++ ComObjPtr::startTaskAsync怎么用?C++ ComObjPtr::startTaskAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ComObjPtr
的用法示例。
在下文中一共展示了ComObjPtr::startTaskAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpdateGuestAdditions
STDMETHODIMP Guest::UpdateGuestAdditions(IN_BSTR aSource, ComSafeArrayIn(AdditionsUpdateFlag_T, aFlags), IProgress **aProgress)
{
#ifndef VBOX_WITH_GUEST_CONTROL
ReturnComNotImplemented();
#else /* VBOX_WITH_GUEST_CONTROL */
CheckComArgStrNotEmptyOrNull(aSource);
CheckComArgOutPointerValid(aProgress);
AutoCaller autoCaller(this);
if (FAILED(autoCaller.rc())) return autoCaller.rc();
/* Validate flags. */
uint32_t fFlags = AdditionsUpdateFlag_None;
if (aFlags)
{
com::SafeArray<CopyFileFlag_T> flags(ComSafeArrayInArg(aFlags));
for (size_t i = 0; i < flags.size(); i++)
fFlags |= flags[i];
}
if (fFlags)
{
if (!(fFlags & AdditionsUpdateFlag_WaitForUpdateStartOnly))
return setError(E_INVALIDARG, tr("Unknown flags (%#x)"), aFlags);
}
HRESULT hr = S_OK;
/* Create an anonymous session. This is required to run the Guest Additions
* update process with administrative rights. */
ComObjPtr<GuestSession> pSession;
int rc = sessionCreate("" /* User */, "" /* Password */, "" /* Domain */,
"Updating Guest Additions" /* Name */, pSession);
if (RT_FAILURE(rc))
{
switch (rc)
{
case VERR_MAX_PROCS_REACHED:
hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of guest sessions (%ld) reached"),
VBOX_GUESTCTRL_MAX_SESSIONS);
break;
/** @todo Add more errors here. */
default:
hr = setError(VBOX_E_IPRT_ERROR, tr("Could not create guest session: %Rrc"), rc);
break;
}
}
else
{
Assert(!pSession.isNull());
rc = pSession->queryInfo();
if (RT_FAILURE(rc))
{
hr = setError(VBOX_E_IPRT_ERROR, tr("Could not query guest session information: %Rrc"), rc);
}
else
{
ComObjPtr<Progress> pProgress;
SessionTaskUpdateAdditions *pTask = new SessionTaskUpdateAdditions(pSession /* GuestSession */,
Utf8Str(aSource), fFlags);
AssertPtrReturn(pTask, VERR_NO_MEMORY);
rc = pSession->startTaskAsync(tr("Updating Guest Additions"), pTask, pProgress);
if (RT_SUCCESS(rc))
{
/* Return progress to the caller. */
hr = pProgress.queryInterfaceTo(aProgress);
}
else
hr = setError(VBOX_E_IPRT_ERROR,
tr("Starting task for updating Guest Additions on the guest failed: %Rrc"), rc);
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}